Skip to content

Commit fb13b11

Browse files
andrejKAGA-KOKO
authored andcommitted
entry: Respect changes to system call number by trace_sys_enter()
When a probe is registered at the trace_sys_enter() tracepoint, and that probe changes the system call number, the old system call still gets executed. This worked correctly until commit b6ec413 ("core/entry: Report syscall correctly for trace and audit"), which removed the re-evaluation of the syscall number after the trace point. Restore the original semantics by re-evaluating the system call number after trace_sys_enter(). The performance impact of this re-evaluation is minimal because it only takes place when a trace point is active, and compared to the actual trace point overhead the read from a cache hot variable is negligible. Fixes: b6ec413 ("core/entry: Report syscall correctly for trace and audit") Signed-off-by: André Rösti <an.roesti@gmail.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20240311211704.7262-1-an.roesti@gmail.com
1 parent e8f897f commit fb13b11

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel/entry/common.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ long syscall_trace_enter(struct pt_regs *regs, long syscall,
5757
/* Either of the above might have changed the syscall number */
5858
syscall = syscall_get_nr(current, regs);
5959

60-
if (unlikely(work & SYSCALL_WORK_SYSCALL_TRACEPOINT))
60+
if (unlikely(work & SYSCALL_WORK_SYSCALL_TRACEPOINT)) {
6161
trace_sys_enter(regs, syscall);
62+
/*
63+
* Probes or BPF hooks in the tracepoint may have changed the
64+
* system call number as well.
65+
*/
66+
syscall = syscall_get_nr(current, regs);
67+
}
6268

6369
syscall_enter_audit(regs, syscall);
6470

0 commit comments

Comments
 (0)