From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Richard W.M. Jones" Subject: Re: [regression] F_DUPFD_CLOEXEC breakage fix Date: Tue, 9 Oct 2012 09:53:01 +0100 Message-ID: <20121009085301.GL24071@rhmail.home.annexia.org> References: <20121008171517.GA15039@rhmail.home.annexia.org> <20121008172103.GB15039@rhmail.home.annexia.org> <87a9vwrgtl.fsf@rho.meyering.net> <20121008215030.GI24071@rhmail.home.annexia.org> <20121008215325.GC15039@rhmail.home.annexia.org> <20121008222158.GQ2616@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8BIT Cc: Linus Torvalds , Jim Meyering , bug-gnulib@gnu.org, linux-fsdevel@vger.kernel.org To: Al Viro Return-path: Received: from mx1.redhat.com ([209.132.183.28]:37198 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754120Ab2JIIxI convert rfc822-to-8bit (ORCPT ); Tue, 9 Oct 2012 04:53:08 -0400 Content-Disposition: inline In-Reply-To: <20121008222158.GQ2616@ZenIV.linux.org.uk> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Mon, Oct 08, 2012 at 11:21:58PM +0100, Al Viro wrote: > On Mon, Oct 08, 2012 at 10:53:25PM +0100, Richard W.M. Jones wrote: > > On Mon, Oct 08, 2012 at 10:50:30PM +0100, Richard W.M. Jones wrote: > > [.. discussion on gnulib test-cloexec test snipped ..] > > > I'm suspicious this is a kernel bug: > > > > > > creat("test-cloexec.tmp", 0600) = 3 > > > fcntl(3, F_GETFD) = 0 > > > fcntl(3, F_GETFD) = 0 > > > fcntl(3, F_SETFD, FD_CLOEXEC) = 0 > > > fcntl(3, F_GETFD) = 0x1 (flags FD_CLOEXEC) > > > fcntl(3, F_GETFD) = 0x1 (flags FD_CLOEXEC) > > > fcntl(3, F_SETFD, 0) = 0 > > > fcntl(3, F_GETFD) = 0 > > > fcntl(3, F_DUPFD_CLOEXEC, 0) = 4 > > > fcntl(4, F_GETFD) = 0 > > > write(2, "test-cloexec.c:97: assertion failed\n", 36) = 36 > > > > > > It seems to me from the description in the man page that > > > F_DUPFD_CLOEXEC ought to be setting the FD_CLOEXEC flag on file > > > descriptor 4, so either it's not or else F_GETFD isn't reading the > > > flag for some reason. > > Interesting... Oh, crap. OK, that's easily fixed: in fs/fcntl.c > err = f_dupfd(arg, filp, FD_CLOEXEC); > should get s/FD_/O_/. Linus, could you apply the following? > > Fix a braino in F_DUPFD_CLOEXEC; f_dupfd() expects flags for > alloc_fd()/get_unused_fd()/etc. and there clone-on-exec if > O_CLOEXEC, not FD_CLOEXEC. > > Signed-off-by: Al Viro I can confirm that this patch fixed the problem for me. Tested-by: Richard W.M. Jones > --- > diff --git a/fs/fcntl.c b/fs/fcntl.c > index 8f70429..71a600a 100644 > --- a/fs/fcntl.c > +++ b/fs/fcntl.c > @@ -258,7 +258,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, > err = f_dupfd(arg, filp, 0); > break; > case F_DUPFD_CLOEXEC: > - err = f_dupfd(arg, filp, FD_CLOEXEC); > + err = f_dupfd(arg, filp, O_CLOEXEC); > break; > case F_GETFD: > err = get_close_on_exec(fd) ? FD_CLOEXEC : 0; Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/