Petr Pavlu
604b72b325
function_graph: Fix the ret_stack used by ftrace_graph_ret_addr()
When ftrace_graph_ret_addr() is invoked to convert a found stack return
address to its original value, the function can end up producing the
following crash:
[ 95.442712] BUG: kernel NULL pointer dereference, address: 0000000000000028
[ 95.442720] #PF: supervisor read access in kernel mode
[ 95.442724] #PF: error_code(0x0000) - not-present page
[ 95.442727] PGD 0 P4D 0-
[ 95.442731] Oops: Oops: 0000 [#1] PREEMPT SMP PTI
[ 95.442736] CPU: 1 UID: 0 PID: 2214 Comm: insmod Kdump: loaded Tainted: G OE K 6.11.0-rc1-default #1 67c62a3b3720562f7e7db5f11c1fdb40b7a2857c
[ 95.442747] Tainted: [O]=OOT_MODULE, [E]=UNSIGNED_MODULE, [K]=LIVEPATCH
[ 95.442750] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014
[ 95.442754] RIP: 0010:ftrace_graph_ret_addr+0x42/0xc0
[ 95.442766] Code: [...]
[ 95.442773] RSP: 0018:ffff979b80ff7718 EFLAGS: 00010006
[ 95.442776] RAX: ffffffff8ca99b10 RBX: ffff979b80ff7760 RCX: ffff979b80167dc0
[ 95.442780] RDX: ffffffff8ca99b10 RSI: ffff979b80ff7790 RDI: 0000000000000005
[ 95.442783] RBP: 0000000000000001 R08: 0000000000000005 R09: 0000000000000000
[ 95.442786] R10: 0000000000000005 R11: 0000000000000000 R12: ffffffff8e9491e0
[ 95.442790] R13: ffffffff8d6f70f0 R14: ffff979b80167da8 R15: ffff979b80167dc8
[ 95.442793] FS: 00007fbf83895740(0000) GS:ffff8a0afdd00000(0000) knlGS:0000000000000000
[ 95.442797] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 95.442800] CR2: 0000000000000028 CR3: 0000000005070002 CR4: 0000000000370ef0
[ 95.442806] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 95.442809] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 95.442816] Call Trace:
[ 95.442823] <TASK>
[ 95.442896] unwind_next_frame+0x20d/0x830
[ 95.442905] arch_stack_walk_reliable+0x94/0xe0
[ 95.442917] stack_trace_save_tsk_reliable+0x7d/0xe0
[ 95.442922] klp_check_and_switch_task+0x55/0x1a0
[ 95.442931] task_call_func+0xd3/0xe0
[ 95.442938] klp_try_switch_task.part.5+0x37/0x150
[ 95.442942] klp_try_complete_transition+0x79/0x2d0
[ 95.442947] klp_enable_patch+0x4db/0x890
[ 95.442960] do_one_initcall+0x41/0x2e0
[ 95.442968] do_init_module+0x60/0x220
[ 95.442975] load_module+0x1ebf/0x1fb0
[ 95.443004] init_module_from_file+0x88/0xc0
[ 95.443010] idempotent_init_module+0x190/0x240
[ 95.443015] __x64_sys_finit_module+0x5b/0xc0
[ 95.443019] do_syscall_64+0x74/0x160
[ 95.443232] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 95.443236] RIP: 0033:0x7fbf82f2c709
[ 95.443241] Code: [...]
[ 95.443247] RSP: 002b:00007fffd5ea3b88 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
[ 95.443253] RAX: ffffffffffffffda RBX: 000056359c48e750 RCX: 00007fbf82f2c709
[ 95.443257] RDX: 0000000000000000 RSI: 000056356ed4efc5 RDI: 0000000000000003
[ 95.443260] RBP: 000056356ed4efc5 R08: 0000000000000000 R09: 00007fffd5ea3c10
[ 95.443263] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000
[ 95.443267] R13: 000056359c48e6f0 R14: 0000000000000000 R15: 0000000000000000
[ 95.443272] </TASK>
[ 95.443274] Modules linked in: [...]
[ 95.443385] Unloaded tainted modules: intel_uncore_frequency(E):1 isst_if_common(E):1 skx_edac(E):1
[ 95.443414] CR2: 0000000000000028
The bug can be reproduced with kselftests:
cd linux/tools/testing/selftests
make TARGETS='ftrace livepatch'
(cd ftrace; ./ftracetest test.d/ftrace/fgraph-filter.tc)
(cd livepatch; ./test-livepatch.sh)
The problem is that ftrace_graph_ret_addr() is supposed to operate on the
ret_stack of a selected task but wrongly accesses the ret_stack of the
current task. Specifically, the above NULL dereference occurs when
task->curr_ret_stack is non-zero, but current->ret_stack is NULL.
Correct ftrace_graph_ret_addr() to work with the right ret_stack.
Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Reported-by: Miroslav Benes <mbenes@suse.cz>
Link: https://lore.kernel.org/20240803131211.17255-1-petr.pavlu@suse.com
Fixes: 7aa1eaef9f ("function_graph: Allow multiple users to attach to function graph")
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
2024-08-07 20:20:30 -04:00
..
2024-07-24 20:59:29 +02:00
2024-07-14 18:04:03 -10:00
2024-07-03 12:24:19 +02:00
2024-06-21 15:49:29 +01:00
2024-07-19 07:27:28 +02:00
2024-03-12 13:23:32 +01:00
2024-07-25 13:32:25 -07:00
2024-05-06 17:39:09 +02:00
2024-06-15 10:43:06 -07:00
2024-07-22 14:02:19 -07:00
2024-06-06 11:21:14 -07:00
2024-07-02 16:56:18 +02:00
2024-07-29 12:16:21 +02:00
2024-07-09 17:01:46 +02:00
2024-07-03 19:30:01 -07:00
2024-07-25 13:18:41 -07:00
2024-07-04 13:54:17 -07:00
2024-08-04 13:36:28 -07:00
2024-08-02 18:29:28 +02:00
2024-08-07 20:20:30 -04:00
2024-04-24 09:43:53 +02:00
2024-02-09 11:13:59 -10:00
2024-04-04 16:24:16 +02:00
2024-04-04 16:24:16 +02:00
2024-01-25 10:12:22 -05:00
2024-06-13 14:26:50 -04:00
2023-10-13 18:34:46 +02:00
2024-06-24 22:24:55 -07:00
2024-04-29 08:29:29 -07:00
2024-03-22 11:18:18 +01:00
2024-07-15 19:36:01 -07:00
2024-05-19 14:02:03 -07:00
2024-06-24 22:25:08 -07:00
2024-02-23 17:33:31 -05:00
2024-07-24 20:59:29 +02:00
2024-02-23 17:48:22 -08:00
2024-07-21 17:15:46 -07:00
2023-09-21 12:03:50 -06:00
2024-07-24 20:59:29 +02:00
2023-12-23 15:52:13 +01:00
2024-05-30 01:13:20 +09:00
2023-09-29 11:28:39 -07:00
2024-07-24 20:59:29 +02:00
2024-07-31 12:57:39 +02:00
2024-07-20 16:33:21 +09:00
2024-04-25 20:55:57 -07:00
2024-07-20 16:33:21 +09:00
2023-10-19 11:02:48 +02:00
2024-02-23 17:48:22 -08:00
2024-06-15 10:43:08 -07:00
2024-07-24 20:59:29 +02:00
2024-04-23 14:59:01 +10:00
2024-02-23 17:48:22 -08:00
2024-04-23 14:59:01 +10:00
2024-07-24 20:59:29 +02:00
2024-07-29 10:45:54 -07:00
2024-05-06 14:22:02 -06:00
2024-07-24 20:59:29 +02:00
2024-02-23 17:48:22 -08:00
2024-03-01 12:23:37 +01:00
2023-12-20 19:26:30 -05:00
2024-04-12 15:07:51 +08:00
2024-06-24 22:25:05 -07:00
2023-12-01 09:51:44 -08:00
2024-07-24 20:59:29 +02:00
2024-07-24 20:59:29 +02:00
2024-03-13 12:53:53 -07:00
2024-08-04 13:36:28 -07:00
2024-02-22 15:38:52 -08:00
2024-04-24 09:43:53 +02:00
2024-04-25 21:07:03 -07:00
2023-12-29 12:22:27 -08:00
2024-06-28 19:36:30 -07:00
2024-05-28 11:14:14 -05:00
2024-05-30 15:31:51 -07:00
2024-07-24 20:59:29 +02:00
2024-07-11 01:51:44 -06:00
2024-07-10 22:40:39 +02:00
2023-10-04 10:41:57 -07:00
2024-04-29 05:03:51 +02:00
2024-07-24 20:59:29 +02:00
2023-12-29 12:22:29 -08:00
2024-07-18 12:19:20 -07:00
2024-05-22 09:56:00 -07:00
2024-06-03 15:20:37 +02:00
2024-07-24 20:59:29 +02:00
2024-07-29 12:05:06 -07:00
2023-10-04 10:41:57 -07:00
2024-05-30 15:31:38 -07:00
2024-07-12 16:39:53 -07:00
2024-05-17 17:31:24 -07:00
2024-07-24 20:59:29 +02:00
2023-09-13 14:59:24 +02:00
2024-02-22 15:38:52 -08:00
2024-05-06 17:39:09 +02:00
2024-07-24 20:59:29 +02:00
2024-05-22 08:31:15 -04:00
2024-07-20 16:33:21 +09:00
2023-12-21 13:17:54 +01:00
2024-07-17 21:11:34 -07:00
2024-07-24 20:59:29 +02:00
2024-07-15 14:01:14 -10:00