seccomp: drop syscall exit events for rejected syscalls
Subsystems (3)
cover seccomp: drop syscall exit events for rejected syscalls
On top of [tip: core/urgent] entry: Kill ARCH_SYSCALL_WORK_{ENTER,EXIT}
https://git.kernel.org/tip/7b41ff29c8d386257bae62ad557fd6bad8cc6787
Still RFC, please comment...
Of course this is a user-visible behavior change. ptrace and audit will no longer see the paired exit events for syscalls rejected with force_sig_seccomp(). I _hope_ this is fine and better than what we have now. If this is not acceptable, we can return to "seccomp: defer syscall_rollback() to get_signal()" we discussed before.
2/2 currently ignores !CONFIG_GENERIC_ENTRY architectures. If this approach is accepted, it will be simple to update them one-by-one to sync with the CONFIG_GENERIC_ENTRY case.
Oleg.
---
include/linux/entry-common.h | 9 ++++++++- include/linux/thread_info.h | 2 ++ kernel/seccomp.c | 22 ++++++++++++++-------- 3 files changed, 24 insertions(+), 9 deletions(-)
RFC PATCH 1/2 seccomp: introduce seccomp_nack_syscall() helper
To factor out the code and simplify the next change
--- kernel/seccomp.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
kernel/seccomp.c +10 -8
@@ -1256,6 +1256,14 @@ static int seccomp_do_user_notification(int this_syscall,return -1 ; } +static void seccomp_nack_syscall (int this_syscall,int data,bool force_coredump) +{ +/* Show the handler or coredump the original registers. */ +syscall_rollback (current,current_pt_regs ()); +/* Let the filter pass back 16 bits of data. */ +force_sig_seccomp (this_syscall, data, force_coredump); +} +static int __seccomp_filter (int this_syscall,const bool recheck_after_trace) {u32 filter_ret, action;
@@ -1285,10 +1293,7 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace) goto skip;case SECCOMP_RET_TRAP : -/* Show the handler the original registers. */ -syscall_rollback (current,current_pt_regs ()); -/* Let the filter pass back 16 bits of data. */ -force_sig_seccomp (this_syscall, data, false); +seccomp_nack_syscall (this_syscall, data, false); goto skip;case SECCOMP_RET_TRACE :
@@ -1360,10 +1365,7 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)/* Dump core only if this is the last remaining thread. */ if (action !=SECCOMP_RET_KILL_THREAD || (atomic_read (¤t->signal->live) ==1 )) { -/* Show the original registers in the dump. */ -syscall_rollback (current,current_pt_regs ()); -/* Trigger a coredump with SIGSYS */ -force_sig_seccomp (this_syscall, data, true); +seccomp_nack_syscall (this_syscall, data, true); }else {do_exit (SIGSYS ); }
Signature · 1 line
2.52.0
RFC PATCH 2/2 seccomp: drop syscall exit events for rejected syscalls
In reply to Oleg Nesterovseccomp_nack_syscall() calls syscall_rollback(), which means that the syscall exit path sees the original syscall number as the return value.
This confuses audit_syscall_exit(), trace_syscall_exit(), and ptrace, causing them to report completely bogus syscall exit events.
Add a new SYSCALL_WORK_SECCOMP_EXIT flag set by seccomp_nack_syscall(), and change syscall_exit_work() to return early if this flag is set. After all, this syscall was never actually executed.
Note that syscall_exit_work() has to clear SYSCALL_WORK_SECCOMP_EXIT for the !force_coredump case, and that is why we actually need the new flag:seccomp_nack_syscall() can't just clear SYSCALL_AUDIT/TRACEPOINT/TRACE.
--- include/linux/entry-common.h | 9 ++++++++- include/linux/thread_info.h | 2 ++ kernel/seccomp.c | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-)
include/linux/entry-common.h +8 -1
@@ -34,7 +34,8 @@SYSCALL_WORK_SYSCALL_TRACE | \SYSCALL_WORK_SYSCALL_AUDIT | \SYSCALL_WORK_SYSCALL_USER_DISPATCH | \ - SYSCALL_WORK_SYSCALL_EXIT_TRAP) +SYSCALL_WORK_SYSCALL_EXIT_TRAP | \ + SYSCALL_WORK_SECCOMP_EXIT)/** * arch_ptrace_report_syscall_entry - Architecture specific ptrace_report_syscall_entry() wrapper
@@ -235,6 +236,12 @@ static __always_inline void syscall_exit_work(struct pt_regs *regs, unsigned lon } } +if (work &SYSCALL_WORK_SECCOMP_EXIT ) { +/* Rejected by seccomp, no valid syscall exit state */ +clear_syscall_work (SECCOMP_EXIT ); +return ; + } +audit_syscall_exit (regs);if (work &SYSCALL_WORK_SYSCALL_TRACEPOINT )
include/linux/thread_info.h +2 -0
@@ -40,6 +40,7 @@ enum {#ifdef CONFIG_GENERIC_ENTRY enum syscall_work_bit {SYSCALL_WORK_BIT_SECCOMP , +SYSCALL_WORK_BIT_SECCOMP_EXIT ,SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT ,SYSCALL_WORK_BIT_SYSCALL_TRACE , SYSCALL_WORK_BIT_SYSCALL_EMU,
@@ -50,6 +51,7 @@ enum syscall_work_bit { };#define SYSCALL_WORK_SECCOMP BIT(SYSCALL_WORK_BIT_SECCOMP) +#define SYSCALL_WORK_SECCOMP_EXIT BIT(SYSCALL_WORK_BIT_SECCOMP_EXIT)#define SYSCALL_WORK_SYSCALL_TRACEPOINT BIT(SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT)#define SYSCALL_WORK_SYSCALL_TRACE BIT(SYSCALL_WORK_BIT_SYSCALL_TRACE)#define SYSCALL_WORK_SYSCALL_EMU BIT(SYSCALL_WORK_BIT_SYSCALL_EMU)
kernel/seccomp.c +4 -0
@@ -1262,6 +1262,10 @@ static void seccomp_nack_syscall(int this_syscall, int data, bool force_coredumpsyscall_rollback (current,current_pt_regs ());/* Let the filter pass back 16 bits of data. */ force_sig_seccomp (this_syscall, data, force_coredump); +#ifdef CONFIG_GENERIC_ENTRY +/* No valid syscall exit state after syscall_rollback() */ +set_syscall_work (SECCOMP_EXIT ); +#endif }static int __seccomp_filter (int this_syscall,const bool recheck_after_trace)
Signature · 1 line
2.52.0
Kees Cook
maintainerQuoted 9 lines · Oleg Nesterov
seccomp_nack_syscall()callssyscall_rollback(), which means that the syscall exit path sees the original syscall number as the return value.This confuses
audit_syscall_exit(),trace_syscall_exit(), and ptrace, causing them to report completely bogus syscall exit events.Add a new
SYSCALL_WORK_SECCOMP_EXITflag set byseccomp_nack_syscall(), and changesyscall_exit_work()to return early if this flag is set. After all, this syscall was never actually executed.
I think this looks good. I'd like to cover the non-generic syscall paths, though, too? (Otherwise we immediately have a behavioral difference between e.g. x86 and arm64.)
Signature · 1 line
Kees Cook
Quoted 5 lines · Kees Cook
Quoted 3 lines · Oleg Nesterov
seccomp_nack_syscall()callssyscall_rollback(), which means that the syscall exit path sees the original syscall number as the return value.
Quoted 8 lines
Quoted 6 lines
This confuses
audit_syscall_exit(),trace_syscall_exit(), and ptrace, causing them to report completely bogus syscall exit events.Add a new
SYSCALL_WORK_SECCOMP_EXITflag set byseccomp_nack_syscall(), and changesyscall_exit_work()to return early if this flag is set. After all, this syscall was never actually executed.I think this looks good.
Great,
Quoted 2 lines
I'd like to cover the non-generic syscall
paths, though, too?
OK, I'll try to make the "extended" V2 soon.
Quoted 2 lines
(Otherwise we immediately have a behavioral
difference between e.g. x86 and arm64.)
Yes, yes, agreed, I even mentioned this in 0/2.
Thanks!
Oleg.