Skip to content

Commit 4ade59d

Browse files
martin-kaisergregkh
authored andcommitted
maple_tree: fix tracepoint string pointers
commit 91a5409 upstream. maple_tree tracepoints contain pointers to function names. Such a pointer is saved when a tracepoint logs an event. There's no guarantee that it's still valid when the event is parsed later and the pointer is dereferenced. The kernel warns about these unsafe pointers. event 'ma_read' has unsafe pointer field 'fn' WARNING: kernel/trace/trace.c:3779 at ignore_event+0x1da/0x1e4 Mark the function names as tracepoint_string() to fix the events. One case that doesn't work without my patch would be trace-cmd record to save the binary ringbuffer and trace-cmd report to parse it in userspace. The address of __func__ can't be dereferenced from userspace but tracepoint_string will add an entry to /sys/kernel/tracing/printk_formats Link: https://lkml.kernel.org/r/[email protected] Fixes: 54a611b ("Maple Tree: add new data structure") Signed-off-by: Martin Kaiser <[email protected]> Acked-by: Liam R. Howlett <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c95e5af commit 4ade59d

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/maple_tree.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
#define CREATE_TRACE_POINTS
6565
#include <trace/events/maple_tree.h>
6666

67+
#define TP_FCT tracepoint_string(__func__)
68+
6769
#define MA_ROOT_PARENT 1
6870

6971
/*
@@ -2949,7 +2951,7 @@ static inline void mas_rebalance(struct ma_state *mas,
29492951
MA_STATE(l_mas, mas->tree, mas->index, mas->last);
29502952
MA_STATE(r_mas, mas->tree, mas->index, mas->last);
29512953

2952-
trace_ma_op(__func__, mas);
2954+
trace_ma_op(TP_FCT, mas);
29532955

29542956
/*
29552957
* Rebalancing occurs if a node is insufficient. Data is rebalanced
@@ -3314,7 +3316,7 @@ static void mas_split(struct ma_state *mas, struct maple_big_node *b_node)
33143316
MA_STATE(prev_l_mas, mas->tree, mas->index, mas->last);
33153317
MA_STATE(prev_r_mas, mas->tree, mas->index, mas->last);
33163318

3317-
trace_ma_op(__func__, mas);
3319+
trace_ma_op(TP_FCT, mas);
33183320
mas->depth = mas_mt_height(mas);
33193321

33203322
mast.l = &l_mas;
@@ -3487,7 +3489,7 @@ static bool mas_is_span_wr(struct ma_wr_state *wr_mas)
34873489
return false;
34883490
}
34893491

3490-
trace_ma_write(__func__, wr_mas->mas, wr_mas->r_max, entry);
3492+
trace_ma_write(TP_FCT, wr_mas->mas, wr_mas->r_max, entry);
34913493
return true;
34923494
}
34933495

@@ -3721,7 +3723,7 @@ static noinline void mas_wr_spanning_store(struct ma_wr_state *wr_mas)
37213723
* of data may happen.
37223724
*/
37233725
mas = wr_mas->mas;
3724-
trace_ma_op(__func__, mas);
3726+
trace_ma_op(TP_FCT, mas);
37253727

37263728
if (unlikely(!mas->index && mas->last == ULONG_MAX))
37273729
return mas_new_root(mas, wr_mas->entry);
@@ -3858,7 +3860,7 @@ static inline void mas_wr_node_store(struct ma_wr_state *wr_mas,
38583860
} else {
38593861
memcpy(wr_mas->node, newnode, sizeof(struct maple_node));
38603862
}
3861-
trace_ma_write(__func__, mas, 0, wr_mas->entry);
3863+
trace_ma_write(TP_FCT, mas, 0, wr_mas->entry);
38623864
mas_update_gap(mas);
38633865
mas->end = new_end;
38643866
return;
@@ -3903,7 +3905,7 @@ static inline void mas_wr_slot_store(struct ma_wr_state *wr_mas)
39033905
return;
39043906
}
39053907

3906-
trace_ma_write(__func__, mas, 0, wr_mas->entry);
3908+
trace_ma_write(TP_FCT, mas, 0, wr_mas->entry);
39073909
/*
39083910
* Only update gap when the new entry is empty or there is an empty
39093911
* entry in the original two ranges.
@@ -4024,7 +4026,7 @@ static inline void mas_wr_append(struct ma_wr_state *wr_mas,
40244026
mas_update_gap(mas);
40254027

40264028
mas->end = new_end;
4027-
trace_ma_write(__func__, mas, new_end, wr_mas->entry);
4029+
trace_ma_write(TP_FCT, mas, new_end, wr_mas->entry);
40284030
return;
40294031
}
40304032

@@ -4038,7 +4040,7 @@ static void mas_wr_bnode(struct ma_wr_state *wr_mas)
40384040
{
40394041
struct maple_big_node b_node;
40404042

4041-
trace_ma_write(__func__, wr_mas->mas, 0, wr_mas->entry);
4043+
trace_ma_write(TP_FCT, wr_mas->mas, 0, wr_mas->entry);
40424044
memset(&b_node, 0, sizeof(struct maple_big_node));
40434045
mas_store_b_node(wr_mas, &b_node, wr_mas->offset_end);
40444046
mas_commit_b_node(wr_mas, &b_node);
@@ -5418,7 +5420,7 @@ void *mas_store(struct ma_state *mas, void *entry)
54185420
int request;
54195421
MA_WR_STATE(wr_mas, mas, entry);
54205422

5421-
trace_ma_write(__func__, mas, 0, entry);
5423+
trace_ma_write(TP_FCT, mas, 0, entry);
54225424
#ifdef CONFIG_DEBUG_MAPLE_TREE
54235425
if (MAS_WARN_ON(mas, mas->index > mas->last))
54245426
pr_err("Error %lX > %lX %p\n", mas->index, mas->last, entry);
@@ -5518,7 +5520,7 @@ void mas_store_prealloc(struct ma_state *mas, void *entry)
55185520
}
55195521

55205522
store:
5521-
trace_ma_write(__func__, mas, 0, entry);
5523+
trace_ma_write(TP_FCT, mas, 0, entry);
55225524
mas_wr_store_entry(&wr_mas);
55235525
MAS_WR_BUG_ON(&wr_mas, mas_is_err(mas));
55245526
mas_destroy(mas);
@@ -6320,7 +6322,7 @@ void *mtree_load(struct maple_tree *mt, unsigned long index)
63206322
MA_STATE(mas, mt, index, index);
63216323
void *entry;
63226324

6323-
trace_ma_read(__func__, &mas);
6325+
trace_ma_read(TP_FCT, &mas);
63246326
rcu_read_lock();
63256327
retry:
63266328
entry = mas_start(&mas);
@@ -6363,7 +6365,7 @@ int mtree_store_range(struct maple_tree *mt, unsigned long index,
63636365
MA_STATE(mas, mt, index, last);
63646366
int ret = 0;
63656367

6366-
trace_ma_write(__func__, &mas, 0, entry);
6368+
trace_ma_write(TP_FCT, &mas, 0, entry);
63676369
if (WARN_ON_ONCE(xa_is_advanced(entry)))
63686370
return -EINVAL;
63696371

@@ -6586,7 +6588,7 @@ void *mtree_erase(struct maple_tree *mt, unsigned long index)
65866588
void *entry = NULL;
65876589

65886590
MA_STATE(mas, mt, index, index);
6589-
trace_ma_op(__func__, &mas);
6591+
trace_ma_op(TP_FCT, &mas);
65906592

65916593
mtree_lock(mt);
65926594
entry = mas_erase(&mas);
@@ -6924,7 +6926,7 @@ void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max)
69246926
unsigned long copy = *index;
69256927
#endif
69266928

6927-
trace_ma_read(__func__, &mas);
6929+
trace_ma_read(TP_FCT, &mas);
69286930

69296931
if ((*index) > max)
69306932
return NULL;

0 commit comments

Comments
 (0)