* F_DUPFD_CLOEXEC broken in 3.7.0
[not found] ` <20121008215325.GC15039@rhmail.home.annexia.org>
@ 2012-10-08 22:05 ` Richard W.M. Jones
2012-10-09 14:07 ` Cong Wang
2012-10-08 22:21 ` [regression] F_DUPFD_CLOEXEC breakage fix Al Viro
1 sibling, 1 reply; 5+ messages in thread
From: Richard W.M. Jones @ 2012-10-08 22:05 UTC (permalink / raw)
To: Jim Meyering, eblake; +Cc: Al Viro, LKML
[-- Attachment #1: Type: text/plain, Size: 1432 bytes --]
Let's move this to LKML ...
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.
>
> Al Viro (CC'd) made some changes in this area recently ..
Attached is a self-contained test program that demonstrates the bug.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org
[-- Attachment #2: cloexec.c --]
[-- Type: text/plain, Size: 578 bytes --]
/* Test if F_DUPFD_CLOEXEC works right.
* by Richard W.M. Jones.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
int
main ()
{
char *file = "/tmp/cloexec.tmp";
int fd = creat (file, 0600);
int fd2;
int flags;
assert (fd >= 0);
fd2 = fcntl (fd, F_DUPFD_CLOEXEC, 0);
assert (fd2 >= 0);
flags = fcntl (fd2, F_GETFD);
assert (flags >= 0);
if ((flags & FD_CLOEXEC) == 0) {
fprintf (stderr, "F_DUPFD_CLOEXEC failed to set FD_CLOEXEC flag!\n");
exit (EXIT_FAILURE);
}
exit (EXIT_SUCCESS);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [regression] F_DUPFD_CLOEXEC breakage fix
[not found] ` <20121008215325.GC15039@rhmail.home.annexia.org>
2012-10-08 22:05 ` F_DUPFD_CLOEXEC broken in 3.7.0 Richard W.M. Jones
@ 2012-10-08 22:21 ` Al Viro
2012-10-09 8:53 ` Richard W.M. Jones
1 sibling, 1 reply; 5+ messages in thread
From: Al Viro @ 2012-10-08 22:21 UTC (permalink / raw)
To: Linus Torvalds
Cc: Jim Meyering, bug-gnulib, Richard W.M. Jones, linux-fsdevel
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 <viro@zeniv.linux.org.uk>
---
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;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [regression] F_DUPFD_CLOEXEC breakage fix
2012-10-08 22:21 ` [regression] F_DUPFD_CLOEXEC breakage fix Al Viro
@ 2012-10-09 8:53 ` Richard W.M. Jones
0 siblings, 0 replies; 5+ messages in thread
From: Richard W.M. Jones @ 2012-10-09 8:53 UTC (permalink / raw)
To: Al Viro; +Cc: Linus Torvalds, Jim Meyering, bug-gnulib, linux-fsdevel
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 <viro@zeniv.linux.org.uk>
I can confirm that this patch fixed the problem for me.
Tested-by: Richard W.M. Jones <rjones@redhat.com>
> ---
> 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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: F_DUPFD_CLOEXEC broken in 3.7.0
2012-10-08 22:05 ` F_DUPFD_CLOEXEC broken in 3.7.0 Richard W.M. Jones
@ 2012-10-09 14:07 ` Cong Wang
2012-10-09 14:10 ` Richard W.M. Jones
0 siblings, 1 reply; 5+ messages in thread
From: Cong Wang @ 2012-10-09 14:07 UTC (permalink / raw)
To: Richard W.M. Jones; +Cc: Jim Meyering, eblake, Al Viro, LKML
On Tue, Oct 9, 2012 at 6:05 AM, Richard W.M. Jones <rjones@redhat.com> wrote:
> Let's move this to LKML ...
>
> 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.
>>
>> Al Viro (CC'd) made some changes in this area recently ..
>
> Attached is a self-contained test program that demonstrates the bug.
>
Seems we passed a wrong flag to f_dupfd()...
Does the following patch help?
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;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: F_DUPFD_CLOEXEC broken in 3.7.0
2012-10-09 14:07 ` Cong Wang
@ 2012-10-09 14:10 ` Richard W.M. Jones
0 siblings, 0 replies; 5+ messages in thread
From: Richard W.M. Jones @ 2012-10-09 14:10 UTC (permalink / raw)
To: Cong Wang; +Cc: Jim Meyering, eblake, Al Viro, LKML
On Tue, Oct 09, 2012 at 10:07:22PM +0800, Cong Wang wrote:
> On Tue, Oct 9, 2012 at 6:05 AM, Richard W.M. Jones <rjones@redhat.com> wrote:
> > Let's move this to LKML ...
> >
> > 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.
> >>
> >> Al Viro (CC'd) made some changes in this area recently ..
> >
> > Attached is a self-contained test program that demonstrates the bug.
> >
>
> Seems we passed a wrong flag to f_dupfd()...
> Does the following patch help?
>
> 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;
Yes .. the same patch has already been sent upstream.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-10-09 14:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20121008171517.GA15039@rhmail.home.annexia.org>
[not found] ` <20121008172103.GB15039@rhmail.home.annexia.org>
[not found] ` <87a9vwrgtl.fsf@rho.meyering.net>
[not found] ` <20121008215030.GI24071@rhmail.home.annexia.org>
[not found] ` <20121008215325.GC15039@rhmail.home.annexia.org>
2012-10-08 22:05 ` F_DUPFD_CLOEXEC broken in 3.7.0 Richard W.M. Jones
2012-10-09 14:07 ` Cong Wang
2012-10-09 14:10 ` Richard W.M. Jones
2012-10-08 22:21 ` [regression] F_DUPFD_CLOEXEC breakage fix Al Viro
2012-10-09 8:53 ` Richard W.M. Jones
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.