From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12462 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] re-fix child reaping in wordexp Date: Mon, 5 Feb 2018 12:27:14 -0500 Message-ID: <20180205172714.GY1627@brightrain.aerifal.cx> References: <20180205143837.26009-1-amonakov@ispras.ru> <20180205162715.GW1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1517851537 22319 195.159.176.226 (5 Feb 2018 17:25:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 5 Feb 2018 17:25:37 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12478-gllmg-musl=m.gmane.org@lists.openwall.com Mon Feb 05 18:25:32 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1eikWC-00054O-D7 for gllmg-musl@m.gmane.org; Mon, 05 Feb 2018 18:25:24 +0100 Original-Received: (qmail 5948 invoked by uid 550); 5 Feb 2018 17:27:27 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 5924 invoked from network); 5 Feb 2018 17:27:26 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12462 Archived-At: On Mon, Feb 05, 2018 at 08:07:44PM +0300, Alexander Monakov wrote: > On Mon, 5 Feb 2018, Rich Felker wrote: > > > In general retrying waitpid on EINTR is not robust in case pid reuse is > > > possible, but fixing that requires changing waitpid call sites to only > > > do that with signals blocked (where that's not already the case). > > > > I don't follow this. Unless there's a bug in the kernel, this should > > not be functionally different from SA_RESTART. A return with EINTR > > means the child was not reaped. > > The problem I had in mind is that you don't know if a signal handler or > another thread had (yes, incorrectly) already reaped that child when you > are about to retry waitpid. > > With signals blocked, you issue just one waitpid, and you need very rapid > pid reuse to happen, after someone successfully reaps your child > even before you enter waitpid. > > Of course this is a bit moot since the other thread/sighandler shouldn't > be issuing wildcard waits in the first place, and if rapid pid reuse > does not happen you safely leave the retry loop with ECHILD. But this is > why I said "not robust" rather than "incorrect". OK, that makes sense -- it's a matter of tiny window vs unboundedly-large window. And in this case EINTR is not relevant; the same unboundedly-large window can happen if you have a long-running signal handler with SA_RESTART. Rich