syslog() thread unsafety

Eugene Grosbein eugen at grosbein.net
Wed Jun 14 16:40:03 UTC 2017


14.06.2017 21:12, Konstantin Belousov wrote:

> If the issue is that mpd5 cancels logging thread, and this leaves the
> mutex in the locked state, the right solution is to establish a cleanup
> handler around the locked region.  Note that this can only work if the
> cancellation is in deferred mode, async mode is unsafe by definition.
> 
> Try something like this, untested even a minimal bit.

[skip]

I've given it a spin with unpatched mpd5 and it seems to work just fine now.
I'm curious, should these two lines be swapped?

+	THREAD_LOCK();
+	pthread_cleanup_push(syslog_cancel_cleanup, NULL);

It seems it could be a race between another thread's pthread_cancel()
and pthread_cleanup_push() here.

Anyway, we have several other places in the lib/ with similar code
possibly missing pthread_cleanup_push():

lib/libc/gen: popen.c, getlogin.c
lib/libc/stdio: findfp.c, fclose.c

Please consider committing the fix at least for syslog.c




More information about the freebsd-stable mailing list