NetBSD Problem Report #24682
Received: (qmail 3742 invoked by uid 605); 5 Mar 2004 16:36:42 -0000
Message-Id: <20040305163638.18DDC21037@smistad.uninett.no>
Date: Fri, 5 Mar 2004 17:36:38 +0100 (CET)
From: he@netbsd.org
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: he@netbsd.org
To: gnats-bugs@gnats.netbsd.org
Subject: syslogd may die if HUP arrives in a certain phase of DNS lookup
X-Send-Pr-Version: 3.95
>Number: 24682
>Category: bin
>Synopsis: syslogd may die if HUP arrives in a certain phase of DNS lookup
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: itojun
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Mar 05 16:37:01 +0000 2004
>Closed-Date: Mon Jun 07 11:16:35 +0000 2004
>Last-Modified: Mon Jun 07 11:16:35 +0000 2004
>Originator: Havard Eidnes
>Release: NetBSD 1.6_STABLE 11 Dec 2002
>Organization:
>Environment:
System: NetBSD nnn.nnn.nnn 1.6_STABLE NetBSD 1.6_STABLE (NNN) #2: Thu Dec 12 11:23:32 CET 2002 he@nnn.nnn.nnn:/usr/src/sys/arch/i386/compile/NNN i386
Architecture: i386
Machine: i386
>Description:
Syslogd may die if HUP signal to reinitialize arrives while
doing a DNS lookup, because a malloc() may be attempted while
the DNS lookup code is doing a free():
(gdb) target core /syslogd.core
Core was generated by `syslogd'.
Program terminated with signal 11, Segmentation fault.
#0 0x804a5eb in cfline (
line=0xbfbfbe98 "*.err;kern.*;auth.notice;authpriv.none;mail.crit;local7,local6,local5.none\t/dev/console", f=0x0)
at /usr/src/usr.sbin/syslogd/syslogd.c:1320
1320 memset(f, 0, sizeof(*f));
(gdb) p f
$1 = (struct filed *) 0x0
(gdb) where
#0 0x804a5eb in cfline (
line=0xbfbfbe98 "*.err;kern.*;auth.notice;authpriv.none;mail.crit;local7,local6,local5.none\t/dev/console", f=0x0)
at /usr/src/usr.sbin/syslogd/syslogd.c:1320
#1 0x804a368 in init (signo=1) at /usr/src/usr.sbin/syslogd/syslogd.c:1246
#2 0xbfbfdfdc in ?? ()
#3 0x807e6f5 in free ()
#4 0x8052e8f in _dns_gethtbyaddr ()
#5 0x806cb75 in nsdispatch ()
#6 0x80524ad in gethostbyaddr ()
#7 0x805147e in getnameinfo ()
#8 0x80511fa in getnameinfo ()
#9 0x8049e4d in cvthname (f=0xbfbfd4ac)
at /usr/src/usr.sbin/syslogd/syslogd.c:1066
#10 0x80490bf in main (argc=1, argv=0xbfbfd674)
at /usr/src/usr.sbin/syslogd/syslogd.c:540
#11 0x804825c in ___start ()
(gdb)
(gdb)
Suspended
nnn# ls -l /syslogd.core
-rw------- 1 root wheel 290816 Mar 5 03:00 /syslogd.core
nnn#
nnn# crontab -l
...
# rotate log files every hour, if necessary
0 * * * * /usr/bin/newsyslog
...
>How-To-Repeat:
Run a moderately busy syslog server; watch it occasionally
drop core when it's being reinitialized.
>Fix:
This is an untested patch, but I think the cvthname() function
also needs to be protected from the HUP and ALRM signals, and
the easiest way seems to be to do as shown here.
The same patch seems to be applicable to -current.
--- syslogd.c.orig Wed Dec 11 17:43:15 2002
+++ syslogd.c Fri Mar 5 17:25:04 2004
@@ -234,6 +234,7 @@
char *argv[];
{
int ch, *funix, i, j, fklog, len, linesize;
+ int omask;
int *nfinetix, nfklogix, nfunixbaseix, nfds;
int funixsize = 0, funixmaxsize = 0;
struct sockaddr_un sunx, fromunix;
@@ -536,9 +537,14 @@
}
line[i] = '\0';
- if (!reject)
+ if (!reject) {
+ omask = sigblock(
+ sigmask(SIGHUP)|
+ sigmask(SIGALRM));
printline(cvthname(&frominet),
line);
+ (void)sigsetmask(omask);
+ }
}
}
}
@@ -714,14 +720,12 @@
int flags;
{
struct filed *f;
- int fac, msglen, omask, prilev;
+ int fac, msglen, prilev;
char *timestamp;
dprintf("logmsg: pri 0%o, flags 0x%x, from %s, msg %s\n",
pri, flags, from, msg);
- omask = sigblock(sigmask(SIGHUP)|sigmask(SIGALRM));
-
/*
* Check to see if msg looks non-standard.
*/
@@ -755,7 +759,6 @@
fprintlog(f, flags, msg);
(void)close(f->f_file);
}
- (void)sigsetmask(omask);
return;
}
for (f = Files; f; f = f->f_next) {
@@ -812,7 +815,6 @@
}
}
}
- (void)sigsetmask(omask);
}
void
>Release-Note:
>Audit-Trail:
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
To: gnats-bugs@netbsd.org
Cc: itojun@iijlab.net
Subject: Re: bin/24682
Date: Sat, 06 Mar 2004 23:36:05 +0900
i guess a proper fix would be to:
- make signal handler real small, like
void
signalhandler(int sig)
{
gothup = 1;
}
- in the main loop handle "gothup" variable change
itojun
State-Changed-From-To: open->feedback
State-Changed-By: itojun
State-Changed-When: Sat Mar 6 14:42:10 UTC 2004
State-Changed-Why:
i guess the race is gone with revision 1.64, could you try it out?
Responsible-Changed-From-To: bin-bug-people->itojun
Responsible-Changed-By: itojun
Responsible-Changed-When: Sat Mar 6 14:42:10 UTC 2004
Responsible-Changed-Why:
mine
From: Jun-ichiro itojun Hagino <itojun@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: pr/24682 CVS commit: src/usr.sbin/syslogd
Date: Sat, 6 Mar 2004 14:42:00 +0000 (UTC)
Module Name: src
Committed By: itojun
Date: Sat Mar 6 14:42:00 UTC 2004
Modified Files:
src/usr.sbin/syslogd: syslogd.c
Log Message:
make SIGHUP handler very small, and call init() from the main poll() loop.
should fix PR bin/24682.
To generate a diff of this commit:
cvs rdiff -r1.63 -r1.64 src/usr.sbin/syslogd/syslogd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: Havard Eidnes <he@netbsd.org>
To: itojun@netbsd.org
Cc: gnats-bugs@gnats.netbsd.org, gnats-admin@netbsd.org
Subject: Re: bin/24682
Date: Sat, 06 Mar 2004 19:47:17 +0100 (CET)
> Synopsis: syslogd may die if HUP arrives in a certain phase of DNS lookup
>
> State-Changed-From-To: open->feedback
> State-Changed-By: itojun
> State-Changed-When: Sat Mar 6 14:42:10 UTC 2004
> State-Changed-Why:
> i guess the race is gone with revision 1.64, could you try it out?
I discussed this with some of my friends yesterday, and the suggestion
was to do as your commit message indicates. I'm told, BTW, that if
you want to be really portable, the "gothup" variable should be of
type sig_atomic_t. In our case that doesn't make any difference,
though (it's typedef'ed to int, at least on the i386 port).
Some of the hunks from 1.64 failed when applied to the netbsd-1-6
code; I've hand-adapted the diff to the netbsd-1-6 code; and the
result is attached below. I'm running this version now on the host
where the problem was observed.
It's of course a separate question whether just this diff or a
wholesale upgrade of syslogd is the appropriate thing to do on the
netbsd-1-6 branch.
Thanks,
- Havard
Index: syslogd.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.51.2.1
diff -u -r1.51.2.1 syslogd.c
--- syslogd.c 25 May 2002 17:44:49 -0000 1.51.2.1
+++ syslogd.c 6 Mar 2004 18:40:46 -0000
@@ -207,6 +207,7 @@
int UseNameService = 1; /* make domain name queries */
int NumForwards = 0; /* number of forwarding actions in conf file */
char **LogPaths; /* array of pathnames to read messages from */
+int gothup = 0; /* got SIGHUP */
void cfline __P((char *, struct filed *));
char *cvthname __P((struct sockaddr_storage *));
@@ -216,11 +217,12 @@
void fprintlog __P((struct filed *, int, char *));
int getmsgbufsize __P((void));
int* socksetup __P((int));
-void init __P((int));
+void init __P((void));
void logerror __P((const char *, ...));
void logmsg __P((int, char *, char *, int));
void printline __P((char *, char *));
void printsys __P((char *));
+void sighup (int);
void reapchild __P((int));
void usage __P((void));
void wallmsg __P((struct filed *, struct iovec *));
@@ -392,7 +394,7 @@
dprintf("Listening on unix dgram socket `%s'\n", *pp);
}
- init(0);
+ init();
if ((fklog = open(_PATH_KLOG, O_RDONLY, 0)) < 0) {
dprintf("Can't open `%s' (%d)\n", _PATH_KLOG, errno);
@@ -402,7 +404,7 @@
dprintf("Off & running....\n");
- (void)signal(SIGHUP, init);
+ (void)signal(SIGHUP, sighup);
/* setup pollfd set. */
readfds = (struct pollfd *)malloc(sizeof(struct pollfd) *
@@ -473,6 +475,10 @@
if (rv < 0) {
if (errno != EINTR)
logerror("poll() failed");
+ if (gothup) {
+ init();
+ gothup = 0;
+ }
continue;
}
dprintf("Got a message (%d)\n", rv);
@@ -1025,6 +1031,13 @@
}
void
+sighup(int signo)
+{
+
+ gothup = 1;
+}
+
+void
reapchild(signo)
int signo;
{
@@ -1157,8 +1170,7 @@
* INIT -- Initialize syslogd from configuration table
*/
void
-init(signo)
- int signo;
+init(void)
{
int i;
FILE *cf;
From: itojun@itojun.org (Jun-ichiro itojun Hagino)
To: he@netbsd.org
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/24682
Date: Sun, 7 Mar 2004 06:01:30 +0900 (JST)
> > Synopsis: syslogd may die if HUP arrives in a certain phase of DNS lookup
> >
> > State-Changed-From-To: open->feedback
> > State-Changed-By: itojun
> > State-Changed-When: Sat Mar 6 14:42:10 UTC 2004
> > State-Changed-Why:
> > i guess the race is gone with revision 1.64, could you try it out?
>
> I discussed this with some of my friends yesterday, and the suggestion
> was to do as your commit message indicates. I'm told, BTW, that if
> you want to be really portable, the "gothup" variable should be of
> type sig_atomic_t. In our case that doesn't make any difference,
> though (it's typedef'ed to int, at least on the i386 port).
i made it "volatile sig_atomic_t".
(volatile as the value can change during execution of a function by
signal)
(not about syslogd itself but) there are so many good improvements
in openbsd wrt signal handling, so we should review those and bring
good stuff in.
> Some of the hunks from 1.64 failed when applied to the netbsd-1-6
> code; I've hand-adapted the diff to the netbsd-1-6 code; and the
> result is attached below. I'm running this version now on the host
> where the problem was observed.
your 1.6 diff looks fine.
itojun
From: "Erik E. Fair" <fair@NetBSD.org>
To: NetBSD GNATS Bug Tracking System <gnats-bugs@NetBSD.org>
Cc:
Subject: Re: bin/24682
Date: Sat, 5 Jun 2004 20:37:18 -0700
Was the patch for 1.6 ever committed to the release branch?
Can this PR be closed?
-Erik
From: Matthias Scheler <tron@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: pr/24682 CVS commit: [netbsd-1-6] src/usr.sbin/syslogd
Date: Mon, 7 Jun 2004 08:57:41 +0000 (UTC)
Module Name: src
Committed By: tron
Date: Mon Jun 7 08:57:41 UTC 2004
Modified Files:
src/usr.sbin/syslogd [netbsd-1-6]: syslogd.c
Log Message:
Apply patch (request by he in ticket #1707):
Avoid crashes in syslogd(8) which could happen if it reloaded the
configuration at the wrong moment. Fixes PR bin/24682.
To generate a diff of this commit:
cvs rdiff -r1.51.2.1 -r1.51.2.2 src/usr.sbin/syslogd/syslogd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: feedback->closed
State-Changed-By: he
State-Changed-When: Mon Jun 7 11:16:00 UTC 2004
State-Changed-Why:
Patch submitted for pullup to netbsd-1-6, and pull-up processed.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.