Skip to content

Commit 47c1856

Browse files
committed
tracing: Fix use-after-free in hist_unreg_all/hist_enable_unreg_all
While running tools/testing/selftests test suite with KASAN, Dmitry Vyukov hit the following use-after-free report: ================================================================== BUG: KASAN: use-after-free in hist_unreg_all+0x1a1/0x1d0 at addr ffff880031632cc0 Read of size 8 by task ftracetest/7413 ================================================================== BUG kmalloc-128 (Not tainted): kasan: bad access detected ------------------------------------------------------------------ This fixes the problem, along with the same problem in hist_enable_unreg_all(). Link: http://lkml.kernel.org/r/c3d05b79e42555b6e36a3a99aae0e37315ee5304.1467247517.git.tom.zanussi@linux.intel.com Cc: Dmitry Vyukov <[email protected]> [Copied Steve's hist_enable_unreg_all() fix to hist_unreg_all()] Signed-off-by: Tom Zanussi <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent 377ccbb commit 47c1856

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,9 +1500,9 @@ static void hist_unregister_trigger(char *glob, struct event_trigger_ops *ops,
15001500

15011501
static void hist_unreg_all(struct trace_event_file *file)
15021502
{
1503-
struct event_trigger_data *test;
1503+
struct event_trigger_data *test, *n;
15041504

1505-
list_for_each_entry_rcu(test, &file->triggers, list) {
1505+
list_for_each_entry_safe(test, n, &file->triggers, list) {
15061506
if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
15071507
list_del_rcu(&test->list);
15081508
trace_event_trigger_enable_disable(file, 0);
@@ -1699,9 +1699,9 @@ hist_enable_get_trigger_ops(char *cmd, char *param)
16991699

17001700
static void hist_enable_unreg_all(struct trace_event_file *file)
17011701
{
1702-
struct event_trigger_data *test;
1702+
struct event_trigger_data *test, *n;
17031703

1704-
list_for_each_entry_rcu(test, &file->triggers, list) {
1704+
list_for_each_entry_safe(test, n, &file->triggers, list) {
17051705
if (test->cmd_ops->trigger_type == ETT_HIST_ENABLE) {
17061706
list_del_rcu(&test->list);
17071707
update_cond_flag(file);

0 commit comments

Comments
 (0)