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

vipw: improve child error handling #1504

Merged
merged 1 commit into from Nov 15, 2021
Merged

vipw: improve child error handling #1504

merged 1 commit into from Nov 15, 2021

Conversation

stoeckmann
Copy link
Contributor

Always set SIGCHLD handler to default, even if the caller of vipw has
set SIGCHLD to ignore. If SIGCHLD is ignored no zombie processes would
be created, which in turn could mean that kill is called with an already
recycled pid.

Also improved error message if child process fails.

Proof of Concept:

  1. Compile nochld:
    --
    #include <signal.h>
    #include <unistd.h>
    int main(void) {
    char *argv[] = { "vipw", NULL };
    signal(SIGCHLD, SIG_IGN);
    execvp("vipw", argv);
    return 1;
    }
    --
  2. Run nochld
  3. Suspend child vi, which suspends vipw too:
    kill -STOP childpid
  4. Kill vi:
    kill -9 childpid
  5. You can see with ps that childpid is no zombie but disappeared
  6. Bring vipw back into foreground
    fg
  7. See misleading warning message

You will get an improperly formatted warning message. Also the wake up
kill call sent SIGCONT to "childpid" which could have been assigned
to another process already.

This is definitely not a vulnerability. It would take super user
operations, at which point an attacker would have already elevated
permissions.

Signed-off-by: Tobias Stoeckmann tobias@stoeckmann.org

Always set SIGCHLD handler to default, even if the caller of vipw has
set SIGCHLD to ignore. If SIGCHLD is ignored no zombie processes would
be created, which in turn could mean that kill is called with an already
recycled pid.

Also improved error message if child process fails.

Proof of Concept:

1. Compile nochld:
--
 #include <signal.h>
 #include <unistd.h>
 int main(void) {
	char *argv[] = { "vipw", NULL };
	signal(SIGCHLD, SIG_IGN);
	execvp("vipw", argv);
	return 1;
 }
--
2. Run nochld
3. Suspend child vi, which suspends vipw too:
`kill -STOP childpid`
4. Kill vi:
`kill -9 childpid`
5. You can see with ps that childpid is no zombie but disappeared
6. Bring vipw back into foreground
`fg`
7. See misleading warning message

You will get an improperly formatted warning message. Also the wake up
kill call sent SIGCONT to "childpid" which could have been assigned
to another process already.

This is definitely not a vulnerability. It would take super user
operations, at which point an attacker would have already elevated
permissions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
@karelzak karelzak merged commit 330dcf9 into util-linux:master Nov 15, 2021
@karelzak
Copy link
Collaborator

Good catch.

I found another place (sys-utils/nsenter.c) where we call kill(child), but we don't care about SIGCHLD setting.

It seems that signal(SIGCHLD, SIG_DFL) is good manner almost always when we use waitpid(), I have added it also to unshare, more and fsck. And it's already used in sys-utils/flock.c.

Thanks.

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

Successfully merging this pull request may close these issues.

None yet

2 participants