diff options
author | Moritz Jodeit <moritz@cvs.openbsd.org> | 2006-04-22 19:26:06 +0000 |
---|---|---|
committer | Moritz Jodeit <moritz@cvs.openbsd.org> | 2006-04-22 19:26:06 +0000 |
commit | 554254748ba070f7afb59034cc4a0eef2ac9879d (patch) | |
tree | 0bd8f020502762be1adecddf1df13cb3e5f4472a /usr.sbin/tcpdump/privsep.c | |
parent | 8c222593b60c6f9647300c1b42eac8c4406d8dfe (diff) |
Set signal handlers directly after the fork(2), so that we avoid
situations, where the privileged child dies before the unprivileged
parent has set a signal handler for SIGCHLD.
ok deraadt@ canacar@
Diffstat (limited to 'usr.sbin/tcpdump/privsep.c')
-rw-r--r-- | usr.sbin/tcpdump/privsep.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/usr.sbin/tcpdump/privsep.c b/usr.sbin/tcpdump/privsep.c index 9f27b403c7f..275cc52a5b7 100644 --- a/usr.sbin/tcpdump/privsep.c +++ b/usr.sbin/tcpdump/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.24 2006/04/22 17:24:33 moritz Exp $ */ +/* $OpenBSD: privsep.c,v 1.25 2006/04/22 19:26:05 moritz Exp $ */ /* * Copyright (c) 2003 Can Erkin Acar @@ -107,6 +107,8 @@ int priv_fd = -1; volatile pid_t child_pid = -1; static volatile sig_atomic_t cur_state = STATE_INIT; +extern void set_slave_signals(void); + static void impl_open_bpf(int, int *); static void impl_open_dump(int, const char *); static void impl_open_output(int, const char *); @@ -134,6 +136,7 @@ priv_init(int argc, char **argv) char *cmdbuf, *infile = NULL; char *RFileName = NULL; char *WFileName = NULL; + sigset_t allsigs, oset; if (geteuid() != 0) errx(1, "need root privileges"); @@ -146,6 +149,9 @@ priv_init(int argc, char **argv) if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, socks) == -1) err(1, "socketpair() failed"); + sigfillset(&allsigs); + sigprocmask(SIG_BLOCK, &allsigs, &oset); + child_pid = fork(); if (child_pid < 0) err(1, "fork() failed"); @@ -173,9 +179,15 @@ priv_init(int argc, char **argv) close(socks[0]); priv_fd = socks[1]; + + set_slave_signals(); + sigprocmask(SIG_SETMASK, &oset, NULL); + return (0); } + sigprocmask(SIG_SETMASK, &oset, NULL); + /* Child - drop suid privileges */ gid = getgid(); uid = getuid(); |