From owner-freebsd-stable@freebsd.org Wed Jun 14 16:40:03 2017 Return-Path: Delivered-To: freebsd-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C194FBEED6C for ; Wed, 14 Jun 2017 16:40:03 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from hz.grosbein.net (hz.grosbein.net [78.47.246.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "hz.grosbein.net", Issuer "hz.grosbein.net" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 57CFC701EF; Wed, 14 Jun 2017 16:40:02 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from eg.sd.rdtc.ru (root@eg.sd.rdtc.ru [62.231.161.221]) by hz.grosbein.net (8.15.2/8.15.2) with ESMTPS id v5EGdlHD090495 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Jun 2017 18:39:47 +0200 (CEST) (envelope-from eugen@grosbein.net) X-Envelope-From: eugen@grosbein.net X-Envelope-To: kostikbel@gmail.com Received: from [10.58.0.4] (dadv@[10.58.0.4]) by eg.sd.rdtc.ru (8.15.2/8.15.2) with ESMTPS id v5EGddoZ084349 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Wed, 14 Jun 2017 23:39:39 +0700 (+07) (envelope-from eugen@grosbein.net) Subject: Re: syslog() thread unsafety To: Konstantin Belousov References: <59413EF0.20608@grosbein.net> <20170614141238.GM2088@kib.kiev.ua> Cc: FreeBSD Stable , Gleb Smirnoff From: Eugene Grosbein Message-ID: <594166CB.60709@grosbein.net> Date: Wed, 14 Jun 2017 23:39:39 +0700 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <20170614141238.GM2088@kib.kiev.ua> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=3.1 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_96_Q, LOCAL_FROM autolearn=no autolearn_force=no version=3.4.1 X-Spam-Report: * 2.8 DATE_IN_FUTURE_96_Q Date: is 4 days to 4 months after Received: date * -2.3 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 2.6 LOCAL_FROM From my domains X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on hz.grosbein.net X-Spam-Level: *** X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Jun 2017 16:40:03 -0000 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