Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setuid and setgid take locks on Linux #83

Open
DemiMarie opened this issue Jan 16, 2017 · 4 comments
Open

setuid and setgid take locks on Linux #83

DemiMarie opened this issue Jan 16, 2017 · 4 comments

Comments

@DemiMarie
Copy link

On Linux, setuid and setgid both take locks, so neither is safe to call in the child after vfork(). Instead, use syscall to issue a raw system call to the kernel.

@snoyberg
Copy link
Collaborator

I at least don't have enough context to understand this bug report, can you clarify?

@simonmichael
Copy link

I wonder if this is related to the fact that rpmlint warns about missing-call-to-setgroups-before-setuid with some haskell executables, such as hledger-web (simonmichael/hledger#1057) and ghcid (https://bugzilla.redhat.com/show_bug.cgi?id=1639089) ?

@bgamari
Copy link
Contributor

bgamari commented Jul 1, 2019

I don't believe this is the same issue that rpmlint is complaining about. That being said, I do believe that the rpmlint warning is a real issue that may even lead to privilege escalation. I've fixed this in #148.

@joeyh
Copy link
Contributor

joeyh commented Sep 14, 2022

I came here after watching this excellent talk. https://www.phoronix.com/news/Linux-LPC2022-io_uring_spawn

As I understand it, the problem would be if another thread were doing something that took the same lock when vfork is called. The lock would then remain held by that thread, which would be suspended for the duration of the vfork. So use of setuid/setgid in the vfork code path could end up blocking on that lock.

This is not the only such problem I'm pretty sure. There is a todo in cbits/posix/fork_exec.c about a similar issue:

        // TODO: Strictly speaking malloc is a no-no after fork() since it
        // may try to take a lock
        char *buf = malloc(buf_len);

And based on the above talk, it's unsafe to do practically anything in the vfork code path except for exec and exit, so even calls to close() in the path between vfork and exec may be unsafe as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants