WSL: Failing (and invisible in strace) clone syscall related to privileged namespaces and chrome's setuid sandbox

Build 16215

We already knew that chromium couldn’t be launched with its usual sandbox due to the fact that user namespaces aren’t implemented. I assumed privileged namespaces were not completely implemented either, though I had heard some of the devs say that privileged namespaces as a concept already exist in the underlying native NT context.

Chromium also includes a setuid sandbox implementation for kernels that don’t implement user namespaces (notably Arch, though I used a clean Ubuntu Xenial image to do this test), and you can launch chromium in this way with the flag --disable-namespace-sandbox, which disables the user namespace sandbox but enables the classic setuid sandbox.

In the user namespace sandbox case, we also get a line in between that actually shows the failing syscall:

clone(child_stack=0x7ffff8384930, flags=CLONE_NEWUSER|SIGCHLD) = -1 EINVAL (Invalid argument)

Now the weird part is this: Let’s try to run that without an strace first:

$ google-chrome --headless --disable-gpu --disable-namespace-sandbox
clone: Invalid argument

we get (among other errors, I know) that there is a clone syscall receiving an invalid parameter or option.

But when you look into the strace, there’s no EINVAL on a Clone syscall, so somewhere some clone syscall is failing on unimplemented surface but is also failing to be picked up in the strace, unlike in the namespace sandbox case.

Straces: for setuid sandbox: suidsandbox.txt

for user namespaces sandbox: unamespaces.txt

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 38 (11 by maintainers)

Most upvoted comments

@therealkenc - Well would you look at that…

chrome

The change to add CLONE_FS support is pretty small so I think I can squeeze it in for Fall Creator’s update. As always, thanks @therealkenc for all the help!

@therealkenc - I liked your idea of stubbing netlink support so I decided to see what would happen if I allowed creation of NETLINK_KOBJECT_UEVENT netlink sockets that will never receive any messages. With that change and the CLONE_FS change I above I’m able to launch chromium without any workarounds.

Unfortunately I can’t do a similar think for all netlink families. For example, allowing creation of NETLINK_AUDIT sockets but don’t actually support the messages opens worms (sudo, adduser, passwd all start failing).

I’m submitting a CR for this change now.

@therealkenc and @fpqc - Keep digging, you might find some surprises… 😃

@fpqc - no that clone call still fails but chrome appears to recover from the error.

Awesome. Fun, no? Now all you need to do is track why VSCode doesn’t launch (toy electron apps are fine). Give an inch, they’ll ask for a mile 😜.

@therealkenc - Dug into this a bit this afternoon. Once I implemented the CLONE_FS flag chromium makes it a bit further, but ultimately fails when trying to talk to udev over netlink sockets (I think).

[0801/165544.343755:WARNING:audio_manager.cc(293)] Multiple instances of AudioManager detected
[0801/165544.344512:WARNING:audio_manager.cc(254)] Multiple instances of AudioManager detected
[0801/165548.842971:FATAL:udev_linux.cc(20)] Check failed: monitor_.
#0 0x7fabeeec2df7 base::debug::StackTrace::StackTrace()
#1 0x7fabeeee435c logging::LogMessage::~LogMessage()
#2 0x7fabe7289001 <unknown>
#3 0x7fabe722447f media::DeviceMonitorLinux::Initialize()
#4 0x7fabeeec38c3 base::debug::TaskAnnotator::RunTask()
#5 0x7fabeeeec31d base::MessageLoop::RunTask()
#6 0x7fabeeeecdc8 base::MessageLoop::DoWork()
#7 0x7fabeeeef0e9 base::MessagePumpLibevent::Run()
#8 0x7fabeeeec049 base::MessageLoop::RunHandler()
#9 0x7fabeef177b0 base::RunLoop::Run()
#10 0x7fabe8f2beb6 content::BrowserThreadImpl::IOThreadRun()
#11 0x7fabe8f2c063 content::BrowserThreadImpl::Run()
#12 0x7fabeef4ce77 base::Thread::ThreadMain()
#13 0x7fabeef46fa3 <unknown>
#14 0x7fabef1e76da start_thread
#15 0x7fabd8ce8d7f clone

Received signal 6
#0 0x7fabeeec2df7 base::debug::StackTrace::StackTrace()
#1 0x7fabeeec296f <unknown>
#2 0x7fabef1f1670 <unknown>
#3 0x7fabd8c1577f gsignal
#4 0x7fabd8c1737a abort
#5 0x7fabeeec1022 base::debug::BreakDebugger()
#6 0x7fabeeee465a logging::LogMessage::~LogMessage()
#7 0x7fabe7289001 <unknown>
#8 0x7fabe722447f media::DeviceMonitorLinux::Initialize()
#9 0x7fabeeec38c3 base::debug::TaskAnnotator::RunTask()
#10 0x7fabeeeec31d base::MessageLoop::RunTask()
#11 0x7fabeeeecdc8 base::MessageLoop::DoWork()
#12 0x7fabeeeef0e9 base::MessagePumpLibevent::Run()
#13 0x7fabeeeec049 base::MessageLoop::RunHandler()
#14 0x7fabeef177b0 base::RunLoop::Run()
#15 0x7fabe8f2beb6 content::BrowserThreadImpl::IOThreadRun()
#16 0x7fabe8f2c063 content::BrowserThreadImpl::Run()
#17 0x7fabeef4ce77 base::Thread::ThreadMain()
#18 0x7fabeef46fa3 <unknown>
#19 0x7fabef1e76da start_thread
#20 0x7fabd8ce8d7f clone
  r8: 0000000000000000  r9: 00007fab8a7be8e0 r10: 0000000000000008 r11: 0000000000000008
 r12: 00007fab8a7befa8 r13: 00007fab8a7bf220 r14: 00007fab8a7befb8 r15: 00007fabd9646060
  di: 0000000000000002  si: 00007fab8a7be8e0  bp: 00007fab8a7bf3a0  bx: 0000000000000000
  dx: 0000000000000000  ax: 0000000000000000  cx: 0000000000000008  sp: 00007fab8a7be958
  ip: 00007fabd8c1577f efl: 0000000000000246 cgf: 00000053002b0033 erf: 0000000000000000
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.

CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWPID, CLONE_NEWNS all work. I am actually a little embarrassed I didn’t notice. I have not tried CLONE_NEWNET because it is academic in the context of WSL.

Need some more bits for systemd though. I did a short run at it last night but my heart wasn’t in it. But take that over to #994.

From your first post, the issue here was and remains:

[pid   519] clone(child_stack=0, flags=CLONE_FS|SIGCHLD) = -1 EINVAL (Invalid argument)

…full stop…

Anyway, quick question: Does WSL support PID namespaces?

Yep. Funny thing, I think maybe it’s been there for a while. And to answer your next question, I’m looking into it.

wsl-namespace

Amusingly enough @benhillis’ work on #962 moved this forward. 16251 now gets over the execve(). Actually if I was a little quicker on the uptake I would have thought of #962 when I saw the EPERM. Same mode of failure.

Having missed that, I did get the “subsequent clone()” failure hypothesis right. Child stack of zero Actually it was CLONE_FS. Don’t think I have seen that before.

[pid   519] clone(child_stack=0, flags=CLONE_FS|SIGCHLD) = -1 EINVAL (Invalid argument)

So @fpqc now ya know.

Since I am here, I have to underline this ticket has nada to do with “namespaces”, even though the word is used 18 times in this thread so far including in the issue title (so says ctrl-f). The whole point of --disable-namespace-sandbox is you are on a kernel without them. Eye on the ball.

Hmmm. I assumed CLONE_FS was implemented (it shows up in quick issue search). You get over the udev netlink socket problem with libudev-stub, natch 😉.

I can’t underline how easy it is to stub the netlink socket part in the WSL kernel if you guys feel like it. My userspace stub just opens a AF_UNIX dgram socket here. Which is totally the wrong family, but it isn’t like userspace knows any different. The next thing userspace does with the socket descriptor is select(), which never fires. You don’t need to actually implement the protocol.

I ask because in the release notes for when they added mount namespaces, they did mention that at least initially, unsharing was not working properly.

image

and you could just open a new issue

Heh, don’t look at me. I don’t even run Chrome on WSL. 😉

PS does unshare()ing those other kernel namespaces work as expected as well?

I haven’t done an unshare() test case or anything like that, but yes. It has to work, or it would be a resource leak.

Oh I see what you mean. Yeah that counts, and “nada” is clearly overstated. It would be more correct to say “the problem right now is not related to namespaces”. So apologies for that.

[n.b. I just didn’t want to see this ticket go down the same path as #1962, which is a mount -t drvfs bug/limitation. An otherwise useful ticket with an actionable problem was lost because an unrelated four letter acronym was repeated two dozen times.]

or is it just reporting a clone problem incorrectly?

Maybe. But probably not. That error message to stderr didn’t come from divine intervention. But either way that particular execve succeeds on Real Linux and fails on WSL.

Note chrome goes out of it’s way to thwart strace when running sandboxed (either kind), so what you could be seeing is a successful execve when not under strace on WSL, and then a subsequent clone fail, for reasons. As I mentioned, bog standard suid proper works on WSL, as far as it goes. The arguments passed to clone calls preceding the execve don’t look that noteworthy from an EINVAL standpoint, AFAICT.

All of which would be noteworthy if I thought Stephen actually put chrome in play.

Oh yeah, repro:

sudo apt-get install ubuntu-desktop libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt-get install -f  # probably
google-chrome --headless --disable-gpu --disable-namespace-sandbox

so somewhere some clone syscall is failing on unimplemented surface

This is the fail:

[pid 22732] execve("/opt/google/chrome/chrome-sandbox", 
    ["/opt/google/chrome/chrome-sandbo"..., "/opt/google/chrome/chrome", 
        "--type=zygote", "--headless", "--headless"], [/* 20 vars */]) = -1 
    EPERM (Operation not permitted)

I didn’t track it very far. Takes on Real Linux natch. Running suid binaries on WSL works as far as it goes.

In any case, the suid sandbox is nearly dead. Still be valuable (on its own merits) looking into why the execve goes south.