Song Liu
7d54c15cb8
ftrace: Clean up hash direct_functions on register failures
We see the following GPF when register_ftrace_direct fails:
[ ] general protection fault, probably for non-canonical address \
0x200000000000010: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC PTI
[...]
[ ] RIP: 0010:ftrace_find_rec_direct+0x53/0x70
[ ] Code: 48 c1 e0 03 48 03 42 08 48 8b 10 31 c0 48 85 d2 74 [...]
[ ] RSP: 0018:ffffc9000138bc10 EFLAGS: 00010206
[ ] RAX: 0000000000000000 RBX: ffffffff813e0df0 RCX: 000000000000003b
[ ] RDX: 0200000000000000 RSI: 000000000000000c RDI: ffffffff813e0df0
[ ] RBP: ffffffffa00a3000 R08: ffffffff81180ce0 R09: 0000000000000001
[ ] R10: ffffc9000138bc18 R11: 0000000000000001 R12: ffffffff813e0df0
[ ] R13: ffffffff813e0df0 R14: ffff888171b56400 R15: 0000000000000000
[ ] FS: 00007fa9420c7780(0000) GS:ffff888ff6a00000(0000) knlGS:000000000
[ ] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ ] CR2: 000000000770d000 CR3: 0000000107d50003 CR4: 0000000000370ee0
[ ] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ ] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ ] Call Trace:
[ ] <TASK>
[ ] register_ftrace_direct+0x54/0x290
[ ] ? render_sigset_t+0xa0/0xa0
[ ] bpf_trampoline_update+0x3f5/0x4a0
[ ] ? 0xffffffffa00a3000
[ ] bpf_trampoline_link_prog+0xa9/0x140
[ ] bpf_tracing_prog_attach+0x1dc/0x450
[ ] bpf_raw_tracepoint_open+0x9a/0x1e0
[ ] ? find_held_lock+0x2d/0x90
[ ] ? lock_release+0x150/0x430
[ ] __sys_bpf+0xbd6/0x2700
[ ] ? lock_is_held_type+0xd8/0x130
[ ] __x64_sys_bpf+0x1c/0x20
[ ] do_syscall_64+0x3a/0x80
[ ] entry_SYSCALL_64_after_hwframe+0x44/0xae
[ ] RIP: 0033:0x7fa9421defa9
[ ] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 9 f8 [...]
[ ] RSP: 002b:00007ffed743bd78 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
[ ] RAX: ffffffffffffffda RBX: 00000000069d2480 RCX: 00007fa9421defa9
[ ] RDX: 0000000000000078 RSI: 00007ffed743bd80 RDI: 0000000000000011
[ ] RBP: 00007ffed743be00 R08: 0000000000bb7270 R09: 0000000000000000
[ ] R10: 00000000069da210 R11: 0000000000000246 R12: 0000000000000001
[ ] R13: 00007ffed743c4b0 R14: 00000000069d2480 R15: 0000000000000001
[ ] </TASK>
[ ] Modules linked in: klp_vm(OK)
[ ] ---[ end trace 0000000000000000 ]---
One way to trigger this is:
1. load a livepatch that patches kernel function xxx;
2. run bpftrace -e 'kfunc:xxx {}', this will fail (expected for now);
3. repeat #2 => gpf.
This is because the entry is added to direct_functions, but not removed.
Fix this by remove the entry from direct_functions when
register_ftrace_direct fails.
Also remove the last trailing space from ftrace.c, so we don't have to
worry about it anymore.
Link: https://lkml.kernel.org/r/20220524170839.900849-1-song@kernel.org
Cc: stable@vger.kernel.org
Fixes: 763e34e74bb7 ("ftrace: Add register_ftrace_direct()")
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
2022-05-26 21:13:01 -04:00
..
2022-03-28 19:08:17 -07:00
2022-03-28 12:41:28 -07:00
2022-03-28 12:27:35 -07:00
2022-03-24 16:39:47 +00:00
2022-04-01 06:46:51 +02:00
2022-04-05 09:59:36 +02:00
2022-04-05 09:59:45 +02:00
2022-03-21 12:59:01 -04:00
2021-12-02 17:25:21 +09:00
2022-03-22 14:39:12 -07:00
2022-01-11 09:51:26 -08:00
2022-03-28 17:29:53 -07:00
2022-03-22 13:44:21 -07:00
2022-03-21 16:48:55 -07:00
2022-03-23 10:54:27 -07:00
2022-03-22 14:39:12 -07:00
2022-04-05 09:59:36 +02:00
2022-04-14 16:19:30 +02:00
2022-05-26 21:13:01 -04:00
2021-10-18 06:17:01 -06:00
2022-02-03 11:20:34 -08:00
2021-10-27 12:32:34 +02:00
2021-12-14 17:39:42 -05:00
2021-11-06 16:43:20 -07:00
2022-01-25 13:22:51 -05:00
2022-02-22 13:51:40 -05:00
2022-01-11 13:08:21 -08:00
2022-03-21 20:53:11 -07:00
2022-03-09 10:32:06 -08:00
2021-08-11 13:11:12 -07:00
2021-09-08 15:32:35 -07:00
2021-08-16 18:55:32 +02:00
2022-03-22 14:39:12 -07:00
2021-12-25 12:20:55 -08:00
2022-03-15 10:32:44 +01:00
2022-01-20 08:52:55 +02:00
2022-03-28 17:29:53 -07:00
2022-02-16 23:25:12 +11:00
2022-03-24 19:06:47 -07:00
2021-06-18 11:43:08 +02:00
2021-05-27 04:01:50 +09:00
2022-01-22 08:33:34 +02:00
2021-10-15 11:25:18 +02:00
2021-07-05 10:46:20 +02:00
2022-03-17 20:17:18 -07:00
2021-08-17 17:50:51 +02:00
2022-03-31 10:36:55 +02:00
2022-03-23 19:00:35 -07:00
2021-12-13 12:04:45 -06:00
2021-11-06 13:30:42 -07:00
2021-09-08 15:32:34 -07:00
2022-05-26 21:12:59 -04:00
2022-03-23 19:00:33 -07:00
2022-03-23 18:03:08 -07:00
2022-04-05 09:59:38 +02:00
2022-02-16 12:51:32 -08:00
2022-01-11 18:45:02 -08:00
2022-02-28 10:26:40 -05:00
2021-12-29 10:37:33 +01:00
2021-09-03 09:58:12 -07:00
2022-01-31 11:21:46 +11:00
2022-03-23 19:00:35 -07:00
2021-12-28 11:26:18 +01:00
2021-09-03 09:58:12 -07:00
2021-10-14 13:29:18 +02:00
2022-01-08 12:43:57 -06:00
2022-03-22 13:06:05 -05:00
2021-11-12 11:53:16 -08:00
2022-03-23 19:00:35 -07:00
2022-02-02 13:11:34 +01:00
2021-12-07 16:36:17 -08:00
2022-03-24 19:06:48 -07:00
2022-03-28 17:29:53 -07:00
2022-03-31 10:36:55 +02:00
2021-10-22 15:32:46 +02:00
2021-08-10 14:57:42 +02:00
2022-02-02 21:34:19 +01:00
2022-02-03 17:02:21 -08:00
2022-02-25 09:36:06 +01:00
2022-04-05 09:59:38 +02:00
2022-04-05 09:59:38 +02:00
2022-01-15 16:30:30 +02:00
2022-03-08 14:33:36 -06:00
2021-06-23 16:41:24 -06:00
2022-03-22 16:11:53 -07:00
2022-03-10 16:51:50 -06:00
2022-03-23 19:00:35 -07:00
2022-02-01 17:24:39 -08:00
2021-08-16 11:39:51 -04:00
2022-01-08 12:43:57 -06:00
2022-02-17 09:11:57 -06:00
2022-02-25 10:40:14 -06:00
2021-09-08 11:50:27 -07:00
2021-07-03 11:41:14 -07:00
2022-04-02 10:37:39 -07:00
2022-02-16 15:57:55 +01:00
2021-08-17 07:49:10 -10:00
2022-03-23 12:40:51 -07:00