-
Couldn't load subscription status.
- Fork 645
unix: call setgoups before calling setuid/setgid #1105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,6 +330,20 @@ static void uv__process_child_init(const uv_process_options_t* options, | |
| _exit(127); | ||
| } | ||
|
|
||
| if (options->flags & (UV_PROCESS_SETUID | UV_PROCESS_SETGID)) { | ||
| /* When dropping privileges from root, the `setgroups` call will | ||
| * remove any extraneous groups. If we don't call this, then | ||
| * even though our uid has dropped, we may still have groups | ||
| * that enable us to do super-user things. This will fail if we | ||
| * aren't root, so don't bother checking the return value, this | ||
| * is just done as an optimistic privilege dropping function. | ||
| */ | ||
| int saved_errno; | ||
| saved_errno = errno; | ||
| setgroups(0, NULL); | ||
| errno = saved_errno; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be shortened to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Ben, will fix.
|
||
| } | ||
|
|
||
| if ((options->flags & UV_PROCESS_SETGID) && setgid(options->gid)) { | ||
| uv__write_int(error_fd, -errno); | ||
| perror("setgid()"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, clear errno?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean restore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it, but we don't check for it unless any of the remaining function calls fail, so does it matter much? Or is it just good practice? I could just set errno to 0 if setgroups fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better just restore it, yeah it is just for the sake of style.