From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Shang XiaoJing <shangxiaojing@huawei.com>,
stable@vger.kernel.org, <zanussi@kernel.org>,
<fengguang.wu@intel.com>
Subject: [for-linus][PATCH 10/13] tracing: Fix wild-memory-access in register_synth_event()
Date: Sun, 20 Nov 2022 15:07:10 -0500 [thread overview]
Message-ID: <20221120200735.196313388@goodmis.org> (raw)
In-Reply-To: 20221120200700.725968899@goodmis.org
From: Shang XiaoJing <shangxiaojing@huawei.com>
In register_synth_event(), if set_synth_event_print_fmt() failed, then
both trace_remove_event_call() and unregister_trace_event() will be
called, which means the trace_event_call will call
__unregister_trace_event() twice. As the result, the second unregister
will causes the wild-memory-access.
register_synth_event
set_synth_event_print_fmt failed
trace_remove_event_call
event_remove
if call->event.funcs then
__unregister_trace_event (first call)
unregister_trace_event
__unregister_trace_event (second call)
Fix the bug by avoiding to call the second __unregister_trace_event() by
checking if the first one is called.
general protection fault, probably for non-canonical address
0xfbd59c0000000024: 0000 [#1] SMP KASAN PTI
KASAN: maybe wild-memory-access in range
[0xdead000000000120-0xdead000000000127]
CPU: 0 PID: 3807 Comm: modprobe Not tainted
6.1.0-rc1-00186-g76f33a7eedb4 #299
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014
RIP: 0010:unregister_trace_event+0x6e/0x280
Code: 00 fc ff df 4c 89 ea 48 c1 ea 03 80 3c 02 00 0f 85 0e 02 00 00 48
b8 00 00 00 00 00 fc ff df 4c 8b 63 08 4c 89 e2 48 c1 ea 03 <80> 3c 02
00 0f 85 e2 01 00 00 49 89 2c 24 48 85 ed 74 28 e8 7a 9b
RSP: 0018:ffff88810413f370 EFLAGS: 00010a06
RAX: dffffc0000000000 RBX: ffff888105d050b0 RCX: 0000000000000000
RDX: 1bd5a00000000024 RSI: ffff888119e276e0 RDI: ffffffff835a8b20
RBP: dead000000000100 R08: 0000000000000000 R09: fffffbfff0913481
R10: ffffffff8489a407 R11: fffffbfff0913480 R12: dead000000000122
R13: ffff888105d050b8 R14: 0000000000000000 R15: ffff888105d05028
FS: 00007f7823e8d540(0000) GS:ffff888119e00000(0000)
knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f7823e7ebec CR3: 000000010a058002 CR4: 0000000000330ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
__create_synth_event+0x1e37/0x1eb0
create_or_delete_synth_event+0x110/0x250
synth_event_run_command+0x2f/0x110
test_gen_synth_cmd+0x170/0x2eb [synth_event_gen_test]
synth_event_gen_test_init+0x76/0x9bc [synth_event_gen_test]
do_one_initcall+0xdb/0x480
do_init_module+0x1cf/0x680
load_module+0x6a50/0x70a0
__do_sys_finit_module+0x12f/0x1c0
do_syscall_64+0x3f/0x90
entry_SYSCALL_64_after_hwframe+0x63/0xcd
Link: https://lkml.kernel.org/r/20221117012346.22647-3-shangxiaojing@huawei.com
Fixes: 4b147936fa50 ("tracing: Add support for 'synthetic' events")
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
Cc: stable@vger.kernel.org
Cc: <mhiramat@kernel.org>
Cc: <zanussi@kernel.org>
Cc: <fengguang.wu@intel.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace_events_synth.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index e310052dc83c..29fbfb27c2b2 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -828,10 +828,9 @@ static int register_synth_event(struct synth_event *event)
}
ret = set_synth_event_print_fmt(call);
- if (ret < 0) {
+ /* unregister_trace_event() will be called inside */
+ if (ret < 0)
trace_remove_event_call(call);
- goto err;
- }
out:
return ret;
err:
--
2.35.1
next prev parent reply other threads:[~2022-11-20 20:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-20 20:07 [for-linus][PATCH 00/13] tracing: Fixes for 6.1 Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 01/13] tracing/ring-buffer: Have polling block on watermark Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 02/13] ring-buffer: Include dropped pages in counting dirty patches Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 03/13] tracing: Fix memory leak in tracing_read_pipe() Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 04/13] tracing: Fix warning on variable struct trace_array Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 05/13] ftrace: Fix the possible incorrect kernel message Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 06/13] ftrace: Optimize the allocation for mcount entries Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 07/13] ring_buffer: Do not deactivate non-existant pages Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 08/13] ftrace: Fix null pointer dereference in ftrace_add_mod() Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 09/13] tracing: Fix memory leak in test_gen_synth_cmd() and test_empty_synth_event() Steven Rostedt
2022-11-20 20:07 ` Steven Rostedt [this message]
2022-11-20 20:07 ` [for-linus][PATCH 11/13] tracing: Remove unused __bad_type_size() method Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 12/13] tracing: Fix potential null-pointer-access of entry in list tr->err_log Steven Rostedt
2022-11-20 20:07 ` [for-linus][PATCH 13/13] tracing: Fix race where eprobes can be called before the event Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221120200735.196313388@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=fengguang.wu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=shangxiaojing@huawei.com \
--cc=stable@vger.kernel.org \
--cc=zanussi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox