diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2002-02-19 21:04:10 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2002-02-19 21:04:10 +0000 |
commit | f0e40dbb349722f637b3c22ee54a50178a8e237b (patch) | |
tree | bb81be83af3ad5bf31d3012c87f5ad3352c4f201 /usr.sbin | |
parent | 5d92d7c0d99fae64ed5b82f45cbede2ed643c5ca (diff) |
Fix the signal races in rbootd.
Credit to millert@ and deraadt@ for pointing out some of my braindamage.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rbootd/bpf.c | 59 | ||||
-rw-r--r-- | usr.sbin/rbootd/defs.h | 10 | ||||
-rw-r--r-- | usr.sbin/rbootd/rbootd.c | 92 |
3 files changed, 84 insertions, 77 deletions
diff --git a/usr.sbin/rbootd/bpf.c b/usr.sbin/rbootd/bpf.c index 3c669c51c84..df1a31282d1 100644 --- a/usr.sbin/rbootd/bpf.c +++ b/usr.sbin/rbootd/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.5 2001/01/17 00:33:03 pjanzen Exp $ */ +/* $OpenBSD: bpf.c,v 1.6 2002/02/19 21:04:09 miod Exp $ */ /* $NetBSD: bpf.c,v 1.5.2.1 1995/11/14 08:45:42 thorpej Exp $ */ /* @@ -49,7 +49,7 @@ #ifndef lint /*static char sccsid[] = "@(#)bpf.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$OpenBSD: bpf.c,v 1.5 2001/01/17 00:33:03 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: bpf.c,v 1.6 2002/02/19 21:04:09 miod Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -103,7 +103,7 @@ BpfOpen() if (BpfFd < 0) { syslog(LOG_ERR, "bpf: no available devices: %m"); - Exit(0); + DoExit(); } /* @@ -113,7 +113,7 @@ BpfOpen() (void) strncpy(ifr.ifr_name, IntfName, sizeof(ifr.ifr_name)); if (ioctl(BpfFd, BIOCSETIF, (caddr_t)&ifr) < 0) { syslog(LOG_ERR, "bpf: ioctl(BIOCSETIF,%s): %m", IntfName); - Exit(0); + DoExit(); } /* @@ -121,12 +121,12 @@ BpfOpen() */ if (ioctl(BpfFd, BIOCGDLT, (caddr_t)&n) < 0) { syslog(LOG_ERR, "bpf: ioctl(BIOCGDLT): %m"); - Exit(0); + DoExit(); } if (n != DLT_EN10MB) { syslog(LOG_ERR,"bpf: %s: data-link type %d unsupported", IntfName, n); - Exit(0); + DoExit(); } /* @@ -135,7 +135,7 @@ BpfOpen() n = 1; if (ioctl(BpfFd, BIOCIMMEDIATE, (caddr_t)&n) < 0) { syslog(LOG_ERR, "bpf: ioctl(BIOCIMMEDIATE): %m"); - Exit(0); + DoExit(); } /* @@ -155,7 +155,7 @@ BpfOpen() if (ioctl(BpfFd, BIOCPROMISC, (caddr_t)0) < 0) { syslog(LOG_ERR, "bpf: can't set promiscuous mode: %m"); - Exit(0); + DoExit(); } } @@ -164,7 +164,7 @@ BpfOpen() */ if (ioctl(BpfFd, BIOCGBLEN, (caddr_t)&BpfLen) < 0) { syslog(LOG_ERR, "bpf: ioctl(BIOCGBLEN): %m"); - Exit(0); + DoExit(); } if (BpfPkt == NULL) BpfPkt = (u_int8_t *)malloc(BpfLen); @@ -172,7 +172,7 @@ BpfOpen() if (BpfPkt == NULL) { syslog(LOG_ERR, "bpf: out of memory (%u bytes for bpfpkt)", BpfLen); - Exit(0); + DoExit(); } /* @@ -198,7 +198,7 @@ BpfOpen() if (ioctl(BpfFd, BIOCSETF, (caddr_t)&bpf_pgm) < 0) { syslog(LOG_ERR, "bpf: ioctl(BIOCSETF): %m"); - Exit(0); + DoExit(); } } @@ -391,40 +391,3 @@ BpfWrite(rconn) return(1); } - -/* -** BpfClose -- Close a BPF device. -** -** Parameters: -** None. -** -** Returns: -** Nothing. -** -** Side Effects: -** None. -*/ -void -BpfClose() -{ - struct ifreq ifr; - - if (BpfPkt != NULL) { - free((char *)BpfPkt); - BpfPkt = NULL; - } - - if (BpfFd == -1) - return; - -#ifdef MSG_EOR - ifr.ifr_addr.sa_len = RMP_ADDRLEN + 2; -#endif - ifr.ifr_addr.sa_family = AF_UNSPEC; - bcopy(&RmpMcastAddr[0], (char *)&ifr.ifr_addr.sa_data[0], RMP_ADDRLEN); - if (ioctl(BpfFd, SIOCDELMULTI, (caddr_t)&ifr) < 0) - (void) ioctl(BpfFd, BIOCPROMISC, (caddr_t)0); - - (void) close(BpfFd); - BpfFd = -1; -} diff --git a/usr.sbin/rbootd/defs.h b/usr.sbin/rbootd/defs.h index 7eba93dedd7..1743ea76602 100644 --- a/usr.sbin/rbootd/defs.h +++ b/usr.sbin/rbootd/defs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: defs.h,v 1.4 2002/02/16 21:28:08 millert Exp $ */ +/* $OpenBSD: defs.h,v 1.5 2002/02/19 21:04:09 miod Exp $ */ /* $NetBSD: defs.h,v 1.5 1995/10/06 05:12:14 thorpej Exp $ */ /* @@ -152,18 +152,13 @@ extern u_int8_t RmpMcastAddr[]; /* RMP multicast address */ void AddConn(RMPCONN *); int BootDone(RMPCONN *); -void BpfClose(void); char *BpfGetIntfName(char **); int BpfOpen(void); int BpfRead(RMPCONN *, int); int BpfWrite(RMPCONN *); -void DebugOff(int); -void DebugOn(int); void DispPkt(RMPCONN *, int); -void DoTimeout(void); +void DoExit(void); void DspFlnm(u_int, char *); -void Exit(int); -CLIENT *FindClient(RMPCONN *); RMPCONN *FindConn(RMPCONN *); void FreeClients(void); void FreeConn(RMPCONN *); @@ -176,7 +171,6 @@ char *NewStr(char *); u_int8_t *ParseAddr(char *); int ParseConfig(void); void ProcessPacket(RMPCONN *, CLIENT *); -void ReConfig(int); void RemoveConn(RMPCONN *); int SendBootRepl(struct rmp_packet *, RMPCONN *, char *[]); int SendFileNo(struct rmp_packet *, RMPCONN *, char *[]); diff --git a/usr.sbin/rbootd/rbootd.c b/usr.sbin/rbootd/rbootd.c index ce990cebcdd..424b38a8e72 100644 --- a/usr.sbin/rbootd/rbootd.c +++ b/usr.sbin/rbootd/rbootd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rbootd.c,v 1.10 2002/02/19 18:38:02 mpech Exp $ */ +/* $OpenBSD: rbootd.c,v 1.11 2002/02/19 21:04:09 miod Exp $ */ /* $NetBSD: rbootd.c,v 1.5 1995/10/06 05:12:17 thorpej Exp $ */ /* @@ -55,7 +55,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "@(#)rbootd.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$OpenBSD: rbootd.c,v 1.10 2002/02/19 18:38:02 mpech Exp $"; +static char rcsid[] = "$OpenBSD: rbootd.c,v 1.11 2002/02/19 21:04:09 miod Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -74,6 +74,22 @@ static char rcsid[] = "$OpenBSD: rbootd.c,v 1.10 2002/02/19 18:38:02 mpech Exp $ extern char *__progname; /* from crt0.o */ +volatile sig_atomic_t dodebugoff; +volatile sig_atomic_t dodebugon; +volatile sig_atomic_t doreconfig; + +void DebugOff(int); +void DebugOn(int); +void ReConfig(int); +void Exit(int); + +void DoDebugOff(void); +void DoDebugOn(void); +void DoReConfig(void); + +void DoTimeout(void); +CLIENT *FindClient(RMPCONN *); + int main(argc, argv) int argc; @@ -155,7 +171,7 @@ main(argc, argv) syslog(LOG_NOTICE, "restarted (??)"); /* BpfGetIntfName() returns safe names, using %m */ syslog(LOG_ERR, "%s", errmsg); - Exit(0); + DoExit(); } } @@ -170,7 +186,7 @@ main(argc, argv) */ if (gethostname(MyHost, sizeof(MyHost)) < 0) { syslog(LOG_ERR, "gethostname: %m"); - Exit(0); + DoExit(); } MyHost[MAXHOSTNAMELEN] = '\0'; @@ -187,7 +203,7 @@ main(argc, argv) */ if (chdir(BootDir) < 0) { syslog(LOG_ERR, "chdir: %m (%s)", BootDir); - Exit(0); + DoExit(); } /* @@ -197,13 +213,13 @@ main(argc, argv) sigaddset(&hmask, SIGHUP); sigprocmask(SIG_BLOCK, &hmask, &omask); /* prevent reconfig's */ if (GetBootFiles() == 0) /* get list of boot files */ - Exit(0); + DoExit(); if (ParseConfig() == 0) /* parse config file */ - Exit(0); + DoExit(); /* * Open and initialize a BPF device for the appropriate interface. - * If an error is encountered, a message is displayed and Exit() + * If an error is encountered, a message is displayed and DoExit() * is called. */ fd = BpfOpen(); @@ -222,6 +238,22 @@ main(argc, argv) fd_set r; int nsel; + /* + * Check pending actions + */ + if (dodebugoff) { + DoDebugOff(); + dodebugoff = 0; + } + if (dodebugon) { + DoDebugOn(); + dodebugon = 0; + } + if (doreconfig) { + DoReConfig(); + doreconfig = 0; + } + r = rset; if (RmpConns == NULL) { /* timeout isnt necessary */ @@ -236,7 +268,7 @@ main(argc, argv) if (errno == EINTR) continue; syslog(LOG_ERR, "select: %m"); - Exit(0); + DoExit(); } else if (nsel == 0) { /* timeout */ DoTimeout(); /* clear stale conns */ continue; @@ -316,7 +348,7 @@ DoTimeout() ** FindClient -- Find client associated with a packet. ** ** Parameters: -** rconn - the new packet. +** rconn - the new packet. ** ** Returns: ** Pointer to client info if found, NULL otherwise. @@ -359,12 +391,16 @@ void Exit(sig) int sig; { - /* XXX race */ - if (sig > 0) - syslog(LOG_ERR, "going down on signal %d", sig); - else - syslog(LOG_ERR, "going down with fatal error"); - BpfClose(); + struct syslog_data sdata = SYSLOG_DATA_INIT; + + syslog_r(LOG_ERR, &sdata, "going down on signal %d", sig); + _exit(1); +} + +void +DoExit() +{ + syslog(LOG_ERR, "going down on fatal error"); exit(1); } @@ -389,16 +425,21 @@ void ReConfig(signo) int signo; { - /* XXX race */ + doreconfig = 1; +} + +void +DoReConfig() +{ syslog(LOG_NOTICE, "reconfiguring boot server"); FreeConns(); if (GetBootFiles() == 0) - Exit(0); + DoExit(); if (ParseConfig() == 0) - Exit(0); + DoExit(); } /* @@ -417,8 +458,12 @@ void DebugOff(signo) int signo; { - /* XXX race */ + dodebugoff = 1; +} +void +DoDebugOff() +{ if (DbgFp != NULL) (void) fclose(DbgFp); @@ -442,7 +487,12 @@ void DebugOn(signo) int signo; { - /* XXX race */ + dodebugon = 1; +} + +void +DoDebugOn() +{ if (DbgFp == NULL) { if ((DbgFp = fopen(DbgFile, "w")) == NULL) syslog(LOG_ERR, "can't open debug file (%s)", DbgFile); |