seccomp update (next)
Hi,
Please pull these seccomp changes for next. These have been tested by myself and Andy, and close a long-standing issue with seccomp where tracers could change the syscall out from under seccomp.
Thanks!
-Kees
The following changes since commit 40d273782ff16fe1a7445cc05c66a447dfea3433:
security: tomoyo: simplify the gc kthread creation (2016-06-06 20:23:55 +1000)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git tags/seccomp-next
for you to fetch changes up to 26703c636c1f3272b39bd0f6d04d2e970984f1b6:
um/ptrace: run seccomp after ptrace (2016-06-14 10:54:47 -0700)
----------------------------------------------------------------
Fix seccomp vs ptrace ordering to plug syscall filter bypass issue.
----------------------------------------------------------------
Andy Lutomirski (2):
seccomp: Add a seccomp_data parameter secure_computing() x86/entry: Get rid of two-phase syscall entry work
Kees Cook (12):
seccomp: add tests for ptrace hole
seccomp: remove 2-phase API
seccomp: recheck the syscall after RET_TRACE x86/ptrace: run seccomp after ptrace arm/ptrace: run seccomp after ptrace arm64/ptrace: run seccomp after ptrace MIPS/ptrace: run seccomp after ptrace parisc/ptrace: run seccomp after ptrace s390/ptrace: run seccomp after ptrace powerpc/ptrace: run seccomp after ptrace tile/ptrace: run seccomp after ptrace um/ptrace: run seccomp after ptrace
arch/arm/kernel/ptrace.c | 13 +- arch/arm64/kernel/ptrace.c | 8 +- arch/mips/kernel/ptrace.c | 9 +- arch/parisc/kernel/ptrace.c | 9 +- arch/powerpc/kernel/ptrace.c | 46 +++---- arch/s390/kernel/ptrace.c | 21 ++- arch/tile/kernel/ptrace.c | 11 +- arch/um/kernel/skas/syscall.c | 9 +- arch/x86/entry/common.c | 106 +++------------- arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- arch/x86/include/asm/ptrace.h | 6 - include/linux/seccomp.h | 14 +- kernel/seccomp.c | 144 ++++++++------------- tools/testing/selftests/seccomp/seccomp_bpf.c | 176 ++++++++++++++++++++++++-- 14 files changed, 309 insertions(+), 265 deletions(-)
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security
Quoted 5 lines · Kees Cook
Hi,
Please pull these seccomp changes for next. These have been tested by myself and Andy, and close a long-standing issue with seccomp where tracers could change the syscall out from under seccomp.
Pulled to security -next.
Signature · 2 lines
James Morris <[email protected]>
Quoted 9 lines · James Morris
Quoted 5 lines · Kees Cook
Hi,
Please pull these seccomp changes for next. These have been tested by myself and Andy, and close a long-standing issue with seccomp where tracers could change the syscall out from under seccomp.
Pulled to security -next.
As a heads up: I think this doesn't quite close the hole on x86. Consider:
64-bit task arranges to be traced by a 32-bit task (or presumably a 64-bit task that calls ptrace via int80).
Tracer does PTRACE_SYSCALL.
Tracee does a normal syscall.
Tracer writes tracee's orig_ax, thus invoking this thing in arch/x86/kernel/ptrace.c:
if (syscall_get_nr(child, regs) >= 0)
child->thread.status |= TS_COMPAT;Tracer resumes and gets confused.
I think the right fix is to just delete:
if (syscall_get_nr(child, regs) >= 0)
child->thread.status |= TS_COMPAT;from ptrace.c. The comment above it is garbage, too.
--Andy
Quoted 26 lines · Andy Lutomirski
Quoted 9 lines · James Morris
Quoted 5 lines · Kees Cook
Hi,
Please pull these seccomp changes for next. These have been tested by myself and Andy, and close a long-standing issue with seccomp where tracers could change the syscall out from under seccomp.
Pulled to security -next.
As a heads up: I think this doesn't quite close the hole on x86. Consider:
64-bit task arranges to be traced by a 32-bit task (or presumably a 64-bit task that calls ptrace via int80).
Tracer does
PTRACE_SYSCALL.Tracee does a normal syscall.
Tracer writes tracee's
orig_ax, thus invoking this thing inarch/x86/kernel/ptrace.c:if (syscall_get_nr(child, regs) >= 0) child->thread.status |= TS_COMPAT;
Quoted 8 lines
Tracer resumes and gets confused.
I think the right fix is to just delete:
if (syscall_get_nr(child, regs) >= 0) child->thread.status |= TS_COMPAT;from
ptrace.c. The comment above it is garbage, too.
I'm perfectly happy to see it removed. I can't make sense of the comment. :)
That said, the only confusion I see is pretty minor. The arch is saved before the tracer could force TS_COMPAT, so nothing confused is handed to seccomp (the first time). And the syscall will continue to be looked up on sys_call_table not ia32_sys_call_table.
The only thing I see is if the tracer has also added a SECCOMP_RET_TRACE filter, after which the recheck will reload all the seccomp info, including the arch. And at this point, a sensible filter will reject a non-matching architecture.
Maybe I'm missing something more?
-Kees
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security
Quoted 35 lines · Kees Cook
Quoted 33 lines · Andy Lutomirski
Quoted 9 lines · James Morris
Quoted 5 lines · Kees Cook
Hi,
Please pull these seccomp changes for next. These have been tested by myself and Andy, and close a long-standing issue with seccomp where tracers could change the syscall out from under seccomp.
Pulled to security -next.
As a heads up: I think this doesn't quite close the hole on x86. Consider:
64-bit task arranges to be traced by a 32-bit task (or presumably a 64-bit task that calls ptrace via int80).
Tracer does
PTRACE_SYSCALL.Tracee does a normal syscall.
Tracer writes tracee's
orig_ax, thus invoking this thing inarch/x86/kernel/ptrace.c:if (syscall_get_nr(child, regs) >= 0) child->thread.status |= TS_COMPAT;Tracer resumes and gets confused.
I think the right fix is to just delete:
if (syscall_get_nr(child, regs) >= 0) child->thread.status |= TS_COMPAT;
Quoted 8 lines
Quoted 1 line
from
ptrace.c. The comment above it is garbage, too.I'm perfectly happy to see it removed. I can't make sense of the comment. :)
That said, the only confusion I see is pretty minor. The arch is saved before the tracer could force
TS_COMPAT, so nothing confused is handed to seccomp (the first time). And the syscall will continue to be looked up onsys_call_tablenotia32_sys_call_table.
Hmm, right, but...
Quoted 6 lines
The only thing I see is if the tracer has also added a
SECCOMP_RET_TRACEfilter, after which the recheck will reload all the seccomp info, including the arch. And at this point, a sensible filter will reject a non-matching architecture.
Yes for some filters, but others might have different logic for different arches, at which point there's a minor bypass.
Quoted 2 lines
Maybe I'm missing something more?
You can also use this to do a 64-bit syscall with in_compat_syscall() returning true, which could cause issues for audit and maybe some ioctl handlers irrespective of this patch series. I'll see about getting it fixed in x86/urgent.
Quoted 57 lines · Andy Lutomirski
Quoted 35 lines · Kees Cook
Quoted 33 lines · Andy Lutomirski
Quoted 9 lines · James Morris
Quoted 5 lines · Kees Cook
Hi,
Please pull these seccomp changes for next. These have been tested by myself and Andy, and close a long-standing issue with seccomp where tracers could change the syscall out from under seccomp.
Pulled to security -next.
As a heads up: I think this doesn't quite close the hole on x86. Consider:
64-bit task arranges to be traced by a 32-bit task (or presumably a 64-bit task that calls ptrace via int80).
Tracer does
PTRACE_SYSCALL.Tracee does a normal syscall.
Tracer writes tracee's
orig_ax, thus invoking this thing inarch/x86/kernel/ptrace.c:if (syscall_get_nr(child, regs) >= 0) child->thread.status |= TS_COMPAT;Tracer resumes and gets confused.
I think the right fix is to just delete:
if (syscall_get_nr(child, regs) >= 0) child->thread.status |= TS_COMPAT;Quoted 8 lines
Quoted 1 line
from
ptrace.c. The comment above it is garbage, too.I'm perfectly happy to see it removed. I can't make sense of the comment. :)
That said, the only confusion I see is pretty minor. The arch is saved before the tracer could force
TS_COMPAT, so nothing confused is handed to seccomp (the first time). And the syscall will continue to be looked up onsys_call_tablenotia32_sys_call_table.Hmm, right, but...
Quoted 6 lines
The only thing I see is if the tracer has also added a
SECCOMP_RET_TRACEfilter, after which the recheck will reload all the seccomp info, including the arch. And at this point, a sensible filter will reject a non-matching architecture.Yes for some filters, but others might have different logic for different arches, at which point there's a minor bypass.
Quoted 7 lines
Quoted 2 lines
Maybe I'm missing something more?
You can also use this to do a 64-bit syscall with
in_compat_syscall()returning true, which could cause issues for audit and maybe some ioctl handlers irrespective of this patch series. I'll see about getting it fixed in x86/urgent.
Hi Kees and James-
On further consideration:
(a) that TS_COMPAT thing is highly, highly buggy -- much buggier and more confusing than I thought, and not in the way I thought.
(b) it doesn't interfere with seccomp at all, so fixing it is not at all a prerequisite for these changes.
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC