From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zeniv.linux.org.uk ([195.92.253.2]:48508 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753192AbeCQPFr (ORCPT ); Sat, 17 Mar 2018 11:05:47 -0400 Date: Sat, 17 Mar 2018 15:05:34 +0000 From: Al Viro To: Jeff Layton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, "J. Bruce Fields" , Thomas Gleixner , Daniel P =?iso-8859-1?Q?=2E_Berrang=E9?= , Kate Stewart , Dan Williams , Philippe Ombredanne , Greg Kroah-Hartman Subject: Re: [PATCH] locks: change POSIX lock ownership on execve when files_struct is displaced Message-ID: <20180317150533.GM30522@ZenIV.linux.org.uk> References: <20180317142520.30520-1-jlayton@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180317142520.30520-1-jlayton@kernel.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Sat, Mar 17, 2018 at 10:25:20AM -0400, Jeff Layton wrote: > From: Jeff Layton > > POSIX mandates that open fds and their associated file locks should be > preserved across an execve. This works, unless the process is > multithreaded at the time that execve is called. > > In that case, we'll end up unsharing the files_struct but the locks will > still have their fl_owner set to the address of the old one. Eventually, > when the other threads die and the last reference to the old > files_struct is put, any POSIX locks get torn down since it looks like > a close occurred on them. > > The result is that all of your open files will be intact with none of > the locks you held before execve. The simple answer to this is "use OFD > locks", but this is a nasty surprise and it violates the spec. > > On a successful execve, change ownership of any POSIX file_locks > associated with the old files_struct to the new one, if we ended up > swapping it out. TBH, I don't like the way you implement that. Why not simply use iterate_fd()?