thread-unsafe syslog code in libc?

Robert Watson rwatson at FreeBSD.org
Sun Aug 15 10:04:08 PDT 2004


I recently resolved a kernel race reported by Martin Blapp in which a file
descriptor had connect() called on it by one thread, and was
simultaenously close()'d by another. The bug resulted in a kernel crash,
which is certainly not the right response, and I'm working on a number of
aspects of that problem. However, this also speaks to a race in user
space.  The socket in question was being connected to /var/run/log, so I
believe it was made from the libc syslog code.  A glance at
src/lib/libc/gen/syslog.c suggests that things are indeed a bit
un-threadsafe, especially in vsyslog(), where things get connected and
disconnected a fair amount.  I'm guessing we need some sort of
synchronization around use of that file descriptor to prevent this sort of
race from happening in the future, as potentially it might lose log
records, etc.  It's also doing a lot of work by reconnecting so
frequently, and I have to wonder if we can't improve the performance of
applications using syslog by doing a better job at using a single
connection...

Robert N M Watson             FreeBSD Core Team, TrustedBSD Projects
robert at fledge.watson.org      Principal Research Scientist, McAfee Research



More information about the freebsd-threads mailing list