Skip to contentSkip to conversation

Commit 5cec93c216db77c45f7ce970d46283bcb1933884 breaks the Chromium seccomp sandbox

3.1 REGRESSION Nix 3 participants 7 messages Nov 14, 2011 Secure computing

lore
Share & tools
lore

Nix

author
#0 lore raw

With this commit installed:

commit 5cec93c216db77c45f7ce970d46283bcb1933884

Author: Andy Lutomirski <[email protected]>
Date:   Sun Jun 5 13:50:24 2011 -0400

x86-64: Emulate legacy vsyscalls

With CONFIG_SECCOMP set, and the Chromium seccomp sandbox compiled in and enabled (which is not the default), on a system running glibc 2.12.x (thus, relying on emulated vsyscalls), Chromium renderers sometimes hang or abruptly abort before rendering anything (both of which show as pages that never complete rendering and eventually get a Chromium kill request dialog). The hang is consistent for a given page, but not all pages hang. (One that *does* hang is the chrome://extensions page, so network access is not the problem here.)

vsyscall=native does not help.

Turning off CONFIG_SECCOMP, or running Chromium with the seccomp sandbox disabled, fixes it.

I speculate that do_emulate_vsyscall() is broken, but it's hard to debug the Chromium renderer sandboxing to see what's failing because the multiple layers of sandboxing get in the way, as they are designed to :) (also, I am not in any way shape or form a Chromium hacker). Chromium does downright terrible things to convert syscalls into IPC calls outside the seccomp sandbox (mostly to a separate, nonseccomped, assembler thread in the same process, but in some cases via IPC to an entirely separate process for validation followed by IPC back and execution in that separate thread). I suspect this delicate dance (for which see seccompsandbox/ in a Chromium source tree) has been disrupted.

I have raised Chromium bug
<http://code.google.com/p/chromium/issues/detail?id=104084> to attract the Chromium hackers' attention to this, and am Cc:ing a Chromium hacker whose fingers are all over the seccomp sandbox as well. Hopefully the cause, or a diagnostic trick, will be obvious to someone other than me.

Signature · 1 line
NULL && (void)
#1 lore raw
Quoted 17 lines · Nix

With this commit installed:

commit 5cec93c216db77c45f7ce970d46283bcb1933884
Author: Andy Lutomirski <[email protected]>
Date:   Sun Jun 5 13:50:24 2011 -0400

   x86-64: Emulate legacy vsyscalls

With CONFIG_SECCOMP set, and the Chromium seccomp sandbox compiled in and enabled (which is not the default), on a system running glibc 2.12.x (thus, relying on emulated vsyscalls), Chromium renderers sometimes hang or abruptly abort before rendering anything (both of which show as pages that never complete rendering and eventually get a Chromium kill request dialog). The hang is consistent for a given page, but not all pages hang. (One that *does* hang is the chrome://extensions page, so network access is not the problem here.)

Quoted 8 lines

vsyscall=native does not help.

Turning off CONFIG_SECCOMP, or running Chromium with the seccomp sandbox disabled, fixes it.

I speculate that do_emulate_vsyscall() is broken, but it's hard to debug the Chromium renderer sandboxing to see what's failing because the multiple layers of sandboxing get in the way, as they are designed to :)

I don't buy that explanation -- with vsyscall=native, do_emulate_vsyscall shouldn't be called at all. I have a much simpler
explanation: the Chromium sandbox is calling vsyscalls in seccomp mode, which has no business working.

The attached patch (in vsyscall=native mode) should help diagnose exactly what's wrong. But I wouldn't be surprised if you can trigger the exact same failure on older kernels by doing

# echo acpi_pm >/sys/devices/system/clocksource/clocksource0/current_clocksource

and then going to the broken page. Just because vgettimeofday sometimes doesn't issue a syscall (and is therefore not caught by the seccomp code) doesn't mean it never issues a syscall.

If the crash is in vtime instead, then there's an argument to be made that time and vtime should be allowed in seccomp mode, in which case it's an easy change to make. But if I'm right, I think that Chromium should stop using vsyscalls from inside the sandbox.

--Andy

#2 lore raw
Quoted 4 lines · Andrew Lutomirski

The attached patch (in vsyscall=native mode) should help diagnose exactly what's wrong.  But I wouldn't be surprised if you can trigger the exact same failure on older kernels by doing

Now with actual attachment.

--Andy

kernel/seccomp.c +1 -0
index 57d4b13..29deaf8 100644
@@ -54,6 +54,7 @@ void __secure_computing(int this_syscall)
 #ifdef SECCOMP_DEBUG
 	dump_stack();
 #endif
+	printk(KERN_ERR "Killing %d due to bad seccomp syscall %d\n", (int)current->pid, (int)this_syscall);
 	do_exit(SIGKILL);
 }
 
#3 lore raw
In reply to Andrew Lutomirski
Quoted 24 lines · Andrew Lutomirski
Quoted 22 lines · Nix

With this commit installed:

commit 5cec93c216db77c45f7ce970d46283bcb1933884
Author: Andy Lutomirski <[email protected]>
Date:   Sun Jun 5 13:50:24 2011 -0400

   x86-64: Emulate legacy vsyscalls

With CONFIG_SECCOMP set, and the Chromium seccomp sandbox compiled in and enabled (which is not the default), on a system running glibc 2.12.x (thus, relying on emulated vsyscalls), Chromium renderers sometimes hang or abruptly abort before rendering anything (both of which show as pages that never complete rendering and eventually get a Chromium kill request dialog). The hang is consistent for a given page, but not all pages hang. (One that *does* hang is the chrome://extensions page, so network access is not the problem here.)

vsyscall=native does not help.

Turning off CONFIG_SECCOMP, or running Chromium with the seccomp sandbox disabled, fixes it.

Quoted 8 lines
Quoted 3 lines

I speculate that do_emulate_vsyscall() is broken, but it's hard to debug the Chromium renderer sandboxing to see what's failing because the multiple layers of sandboxing get in the way, as they are designed to :)

I don't buy that explanation -- with vsyscall=native, do_emulate_vsyscall shouldn't be called at all.  I have a much simpler
explanation: the Chromium sandbox is calling vsyscalls in seccomp mode, which has no business working.

I think the problem is that seccomp-sandbox attempts to patch the vsyscall page.  It replaces the SYSCALL instructions in this page with jumps to seccomp-sandbox's handler.  (More accurately, seccomp-sandbox creates a patched copy of the vsyscall page.  It redirects glibc's indirect jumps so that they go to the patched copy of the vsyscall page instead of to the original.)  The code for this is in patchVSystemCalls() in library.cc
(http://code.google.com/p/seccompsandbox/source/browse/trunk/library.cc).

If the vsyscall page's code no longer invokes the kernel via SYSCALL instructions but via some other trap, seccomp-sandbox's trick will no longer work, because it doesn't know to patch the instructions that do this new trap.

Mark

#4 lore raw
Quoted 43 lines · Mark Seaborn
Quoted 24 lines · Andrew Lutomirski
Quoted 22 lines · Nix

With this commit installed:

commit 5cec93c216db77c45f7ce970d46283bcb1933884
Author: Andy Lutomirski <[email protected]>
Date:   Sun Jun 5 13:50:24 2011 -0400

   x86-64: Emulate legacy vsyscalls

With CONFIG_SECCOMP set, and the Chromium seccomp sandbox compiled in and enabled (which is not the default), on a system running glibc 2.12.x (thus, relying on emulated vsyscalls), Chromium renderers sometimes hang or abruptly abort before rendering anything (both of which show as pages that never complete rendering and eventually get a Chromium kill request dialog). The hang is consistent for a given page, but not all pages hang. (One that *does* hang is the chrome://extensions page, so network access is not the problem here.)

vsyscall=native does not help.

Turning off CONFIG_SECCOMP, or running Chromium with the seccomp sandbox disabled, fixes it.

Quoted 8 lines
Quoted 3 lines

I speculate that do_emulate_vsyscall() is broken, but it's hard to debug the Chromium renderer sandboxing to see what's failing because the multiple layers of sandboxing get in the way, as they are designed to :)

I don't buy that explanation -- with vsyscall=native, do_emulate_vsyscall shouldn't be called at all.  I have a much simpler
explanation: the Chromium sandbox is calling vsyscalls in seccomp mode, which has no business working.

I think the problem is that seccomp-sandbox attempts to patch the vsyscall page.  It replaces the SYSCALL instructions in this page with jumps to seccomp-sandbox's handler.  (More accurately, seccomp-sandbox creates a patched copy of the vsyscall page.  It redirects glibc's indirect jumps so that they go to the patched copy of the vsyscall page instead of to the original.)  The code for this is in patchVSystemCalls() in library.cc
(http://code.google.com/p/seccompsandbox/source/browse/trunk/library.cc).

Quoted 4 lines

If the vsyscall page's code no longer invokes the kernel via SYSCALL instructions but via some other trap, seccomp-sandbox's trick will no longer work, because it doesn't know to patch the instructions that do this new trap.

The vsyscall code is now:

mov $__NR_whatever %rax
syscall
ret

It used to be weirder, but we changed to to avoid breaking things like this. The secret is that, if vsyscall=emulate, the vsyscall page is not executable and we use the page fault to invoke do_emulate_vsyscall. But userspace can't tell it's not executable without actually jumping there, and with vsyscall=native, it's just a normal syscall.

I'll try to build a sandboxing copy of chromium tomorrow to see if I can reproduce it.

--Andy

author
#5 lore raw

On 14 Nov 2011, Andrew Lutomirski stated:

Quoted 3 lines · Mark Seaborn
Quoted 2 lines

I think the problem is that seccomp-sandbox attempts to patch the vsyscall page.

I grepped for vsyscall to try to avoid making an idiot of myself like this. A shame I misspelt it. :/

Quoted 13 lines

The vsyscall code is now:

mov $__NR_whatever %rax
syscall
ret

It used to be weirder, but we changed to to avoid breaking things like this. The secret is that, if vsyscall=emulate, the vsyscall page is not executable and we use the page fault to invoke do_emulate_vsyscall. But userspace can't tell it's not executable without actually jumping there, and with vsyscall=native, it's just a normal syscall.

Quoted 2 lines

I'll try to build a sandboxing copy of chromium tomorrow to see if I can reproduce it.

If you look at line 909 of seccompsandbox/library.cc (in
http://git.chromium.org/external/seccompsandbox.git) the problem does indeed jump out at you. That nice manual disassembly using == isn't going to work anymore. It even helpfully dies with a message saying that it can't patch the vsyscall page, but the message gets thrown away by some higher layer.

I suspect we want two functions and something to recognize what the vsyscall page looks like and choose between them, rather than making this already tricky function even uglier.

(To build Chromium with sandboxing, the recipe is little more than making sure you haven't passed in -Dselinux, and starting Chromium with --enable-seccomp-sandbox. It's turned off by default because it slows Chromium down, not because it doesn't work. :) )

Signature · 1 line
NULL && (void)
#6 lore raw
In reply to Andrew Lutomirski
Quoted 21 lines · Andrew Lutomirski
Quoted 9 lines · Mark Seaborn

I think the problem is that seccomp-sandbox attempts to patch the vsyscall page.  It replaces the SYSCALL instructions in this page with jumps to seccomp-sandbox's handler.  (More accurately, seccomp-sandbox creates a patched copy of the vsyscall page.  It redirects glibc's indirect jumps so that they go to the patched copy of the vsyscall page instead of to the original.)  The code for this is in patchVSystemCalls() in library.cc
(http://code.google.com/p/seccompsandbox/source/browse/trunk/library.cc).

Quoted 4 lines

If the vsyscall page's code no longer invokes the kernel via SYSCALL instructions but via some other trap, seccomp-sandbox's trick will no longer work, because it doesn't know to patch the instructions that do this new trap.

The vsyscall code is now:

       mov $__NR_whatever %rax
       syscall
       ret

Quoted 6 lines

It used to be weirder, but we changed to to avoid breaking things like this.  The secret is that, if vsyscall=emulate, the vsyscall page is not executable and we use the page fault to invoke do_emulate_vsyscall.  But userspace can't tell it's not executable without actually jumping there, and with vsyscall=native, it's just a normal syscall.

Ah, that's much nicer. In that case, the fix should just be a case of adding the new syscall numbers to the whitelist in system_call_table.cc.

The current hang might just be occurring because libpthread's timeout calculations come out wrong. libpthread doesn't check for errors from its calls to vsyscall routines, at least in nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S in the version I checked.

Quoted 2 lines

I'll try to build a sandboxing copy of chromium tomorrow to see if I can reproduce it.

You don't necessarily need to build Chromium. You can try running "make test" in a checkout of seccompsandbox. That might not catch the problem, though. I did not realise that the vsyscall page was still used by glibc when I wrote those tests.

Cheers,
Mark