Skip to content

Commit ea7f880

Browse files
Kalesh Singhgregkh
authored andcommitted
tracing/cfi: Fix cmp_entries_* functions signature mismatch
[ Upstream commit 7ce1bb8 ] If CONFIG_CFI_CLANG=y, attempting to read an event histogram will cause the kernel to panic due to failed CFI check. 1. echo 'hist:keys=common_pid' >> events/sched/sched_switch/trigger 2. cat events/sched/sched_switch/hist 3. kernel panics on attempting to read hist This happens because the sort() function expects a generic int (*)(const void *, const void *) pointer for the compare function. To prevent this CFI failure, change tracing map cmp_entries_* function signatures to match this. Also, fix the build error reported by the kernel test robot [1]. [1] https://lore.kernel.org/r/202110141140.zzi4dRh4-lkp@intel.com/ Link: https://lkml.kernel.org/r/20211014045217.3265162-1-kaleshsingh@google.com Signed-off-by: Kalesh Singh <kaleshsingh@google.com> Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5736f1d commit ea7f880

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

kernel/trace/tracing_map.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -834,29 +834,35 @@ int tracing_map_init(struct tracing_map *map)
834834
return err;
835835
}
836836

837-
static int cmp_entries_dup(const struct tracing_map_sort_entry **a,
838-
const struct tracing_map_sort_entry **b)
837+
static int cmp_entries_dup(const void *A, const void *B)
839838
{
839+
const struct tracing_map_sort_entry *a, *b;
840840
int ret = 0;
841841

842-
if (memcmp((*a)->key, (*b)->key, (*a)->elt->map->key_size))
842+
a = *(const struct tracing_map_sort_entry **)A;
843+
b = *(const struct tracing_map_sort_entry **)B;
844+
845+
if (memcmp(a->key, b->key, a->elt->map->key_size))
843846
ret = 1;
844847

845848
return ret;
846849
}
847850

848-
static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
849-
const struct tracing_map_sort_entry **b)
851+
static int cmp_entries_sum(const void *A, const void *B)
850852
{
851853
const struct tracing_map_elt *elt_a, *elt_b;
854+
const struct tracing_map_sort_entry *a, *b;
852855
struct tracing_map_sort_key *sort_key;
853856
struct tracing_map_field *field;
854857
tracing_map_cmp_fn_t cmp_fn;
855858
void *val_a, *val_b;
856859
int ret = 0;
857860

858-
elt_a = (*a)->elt;
859-
elt_b = (*b)->elt;
861+
a = *(const struct tracing_map_sort_entry **)A;
862+
b = *(const struct tracing_map_sort_entry **)B;
863+
864+
elt_a = a->elt;
865+
elt_b = b->elt;
860866

861867
sort_key = &elt_a->map->sort_key;
862868

@@ -873,18 +879,21 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a,
873879
return ret;
874880
}
875881

876-
static int cmp_entries_key(const struct tracing_map_sort_entry **a,
877-
const struct tracing_map_sort_entry **b)
882+
static int cmp_entries_key(const void *A, const void *B)
878883
{
879884
const struct tracing_map_elt *elt_a, *elt_b;
885+
const struct tracing_map_sort_entry *a, *b;
880886
struct tracing_map_sort_key *sort_key;
881887
struct tracing_map_field *field;
882888
tracing_map_cmp_fn_t cmp_fn;
883889
void *val_a, *val_b;
884890
int ret = 0;
885891

886-
elt_a = (*a)->elt;
887-
elt_b = (*b)->elt;
892+
a = *(const struct tracing_map_sort_entry **)A;
893+
b = *(const struct tracing_map_sort_entry **)B;
894+
895+
elt_a = a->elt;
896+
elt_b = b->elt;
888897

889898
sort_key = &elt_a->map->sort_key;
890899

@@ -989,10 +998,8 @@ static void sort_secondary(struct tracing_map *map,
989998
struct tracing_map_sort_key *primary_key,
990999
struct tracing_map_sort_key *secondary_key)
9911000
{
992-
int (*primary_fn)(const struct tracing_map_sort_entry **,
993-
const struct tracing_map_sort_entry **);
994-
int (*secondary_fn)(const struct tracing_map_sort_entry **,
995-
const struct tracing_map_sort_entry **);
1001+
int (*primary_fn)(const void *, const void *);
1002+
int (*secondary_fn)(const void *, const void *);
9961003
unsigned i, start = 0, n_sub = 1;
9971004

9981005
if (is_key(map, primary_key->field_idx))
@@ -1061,8 +1068,7 @@ int tracing_map_sort_entries(struct tracing_map *map,
10611068
unsigned int n_sort_keys,
10621069
struct tracing_map_sort_entry ***sort_entries)
10631070
{
1064-
int (*cmp_entries_fn)(const struct tracing_map_sort_entry **,
1065-
const struct tracing_map_sort_entry **);
1071+
int (*cmp_entries_fn)(const void *, const void *);
10661072
struct tracing_map_sort_entry *sort_entry, **entries;
10671073
int i, n_entries, ret;
10681074

0 commit comments

Comments
 (0)