entry: Respect changes to system call number at sys_enter tracepoint
PATCH v2 1/1 entry: Respect changes to system call number at sys_enter tracepoint
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 b6ec41346103 ("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.
---
v1 -> v2: Clarify comment; improve commit message
@Thomas Gleixner: Thank you for your very quick reply and helpful comments. I copied and slightly reworded your suggestions for the commit message which were much more concise and clear.
--- kernel/entry/common.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
kernel/entry/common.c +7 -1
@@ -57,8 +57,14 @@ long syscall_trace_enter(struct pt_regs *regs, long syscall,/* Either of the above might have changed the syscall number */ syscall =syscall_get_nr (current, regs); -if (unlikely (work &SYSCALL_WORK_SYSCALL_TRACEPOINT )) +if (unlikely (work &SYSCALL_WORK_SYSCALL_TRACEPOINT )) {trace_sys_enter (regs, syscall); +/* +* Probes or BPF hooks in the tracepoint may have changed the +* system call number as well. +*/ + syscall =syscall_get_nr (current, regs); + }syscall_enter_audit (regs, syscall);
base-commit: 221a164035fd8b554a44bd7c4bf8e7715a497561
Signature · 1 line
2.34.1
[tip: core/entry] entry: Respect changes to system call number by trace_sys_enter()
The following commit has been merged into the core/entry branch of tip:
The following commit has been merged into the core/entry branch of tip:
Commit-ID: fb13b11d53875e28e7fbf0c26b288e4ea676aa9f Gitweb: https://git.kernel.org/tip/fb13b11d53875e28e7fbf0c26b288e4ea676aa9f Author: André Rösti <[email protected]> AuthorDate: Mon, 11 Mar 2024 21:17:04 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 12 Mar 2024 13:23:32 +01:00
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 b6ec41346103 ("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.
--- kernel/entry/common.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
kernel/entry/common.c +7 -1
@@ -57,8 +57,14 @@ long syscall_trace_enter(struct pt_regs *regs, long syscall,/* Either of the above might have changed the syscall number */ syscall =syscall_get_nr (current, regs); -if (unlikely (work &SYSCALL_WORK_SYSCALL_TRACEPOINT )) +if (unlikely (work &SYSCALL_WORK_SYSCALL_TRACEPOINT )) {trace_sys_enter (regs, syscall); +/* +* Probes or BPF hooks in the tracepoint may have changed the +* system call number as well. +*/ + syscall =syscall_get_nr (current, regs); + }syscall_enter_audit (regs, syscall);