Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: "Jason A. Donenfeld" Newsgroups: gnu.bash.bug Subject: Re: process substitution fd lifetime race condition Date: Mon, 20 Apr 2020 16:02:39 -0600 Lines: 24 Approved: bug-bash@gnu.org Message-ID: References: <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> <01e85de9-95ef-20fd-7221-a54a0a2a304a@case.edu> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1587420179 18408 209.51.188.17 (20 Apr 2020 22:02:59 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Chester Ramey Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=mime-version :references:in-reply-to:from:date:message-id:subject:to:cc :content-type; s=mail; bh=I9s6JE5Grmt0d39cpB0nWZS6VDA=; b=Nk1LOF wJd0R3dfSBzNABAqnW5t6LhGzRsDxOknpVYTdYOvrnRHrTlwLkeqKAkUv4gpRNZI cBeIWv1keyx3MFDfat2ggXHukW+OiQ4bnsJ/ctzutvdA3py6LH0b02vGa9vkZZn2 YcYurZMAl7XCcPa20jMn8pDVbkQHXQKsonBnxUqHWp8RhiNp8eKZjbYuGcJGXhSf YIBJrdQUFBTTRbFV5A+UPUDXGgEMDZlPhaA8m5aeCPyS9wbysEllJ/0qcwXaoPbJ eGHT2KAPiXJKNKjKtJb4kv/tyc4IFnnuxZnn6ZsBQ+Hj/rFnXqxK/BJhmv19C5hA /OqW1xDDxQdbIQ3g== X-Gm-Message-State: AGi0Puaau2Bpc0wyuacTD8g5dT6QHVC0684H9bEv6ELD4qFCMEPAqC7r H7WDDsugZZn69VDXmPZ/nx5vjScwSP6V8HgzB0A= X-Google-Smtp-Source: APiQypL5lgCE89mzeGn8cGD3dkrs26fu7j7xG+xogOeS96VvYO4cPxiRxGfOwhOzqmshZ2+1BwEerOdWZuSxdhKG7A8= X-Received: by 2002:a02:b88e:: with SMTP id p14mr12062120jam.36.1587420170517; Mon, 20 Apr 2020 15:02:50 -0700 (PDT) In-Reply-To: <01e85de9-95ef-20fd-7221-a54a0a2a304a@case.edu> X-Gmail-Original-Message-ID: Received-SPF: pass client-ip=192.95.5.64; envelope-from=Jason@zx2c4.com; helo=mail.zx2c4.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/20 17:01:28 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Received-From: 192.95.5.64 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> <01e85de9-95ef-20fd-7221-a54a0a2a304a@case.edu> Xref: csiph.com gnu.bash.bug:16209 On Mon, Apr 20, 2020 at 3:58 PM Chet Ramey wrote: > OK, good. It was either that or closing the fd after reaping the child > process -- I couldn't tell 100% from the system call trace. The latter is an interesting possibility. I assume SIGCHLD comes in through a signal handler, so it's asynchronous, which means it could race. But in the case that fd 63 hasn't already been closed, wont subsequent fifos use different fds, which means the signal handler doesn't need to synchronize with anything? Either way, glad to hear that your patch fixes the issue. Looking forward to the release of 5.0.017. It seems like process substitution fifo lifetime is really tricky. You can't really reference track, since the path is just a string that could be manipulated. So how do you know when it's safe to clean up that fd and that nobody is using it? I suppose you have a set of lexical heuristics that fit for "most common cases"? And I guess those are undocumented and can't really be relied upon since evidently they do change. I wonder if one general improvement would be to never close a fifo if it has data in it, but it's read position is still at zero.