On Tue, Oct 09, 2012 at 08:18:21AM -0600, Eric Blake wrote: > On 10/09/2012 03:05 AM, Richard W.M. Jones wrote: > > On Tue, Oct 09, 2012 at 09:54:45AM +0100, Richard W.M. Jones wrote: > >> The F_DUPFD_CLOEXEC fix that Al Viro posted fixes 3/4 of the > >> bugs, but I'm still investigating this one: > >> > >>> test-dup3.c:108: assertion failed > >>> # ASSERT (dup3 (fd, fd, o_flags) == -1); > > > > Thanks to Jim for pointing out this is a kernel bug, because the > > proposed standard for dup3 specifies that fd1 != fd2 else error: > > > > http://austingroupbugs.net/view.php?id=411 > > I agree that it is a regression in behavior, and wrote that Austin Group > wording based on the previous Linux behavior. However, rather than > claiming it is a kernel bug, we must also consider whether it should be > fixed in glibc; after all, if the kernel is easier to implement dup2 and > dup3 alike (with no special casing of dup-to-self), it's not too hard > for glibc to special-case a dup-to-self check without even calling into > the kernel.
The fix is pretty simple. It looks as if some code got dropped when it was moved from one file to another. 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
From 0944e30e12dec6544b3602626b60ff412375c78f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" <rjo...@redhat.com> Date: Tue, 9 Oct 2012 14:42:45 +0100 Subject: [PATCH] dup3: Return an error when oldfd == newfd. The following commit: commit fe17f22d7fd0e344ef6447238f799bb49f670c6f Author: Al Viro <v...@zeniv.linux.org.uk> Date: Tue Aug 21 11:48:11 2012 -0400 take purely descriptor-related stuff from fcntl.c to file.c was supposed to be just code motion, but it dropped the following two lines: if (unlikely(oldfd == newfd)) return -EINVAL; from the dup3 system call. dup3 is not specified by POSIX, so Linux can do what it likes. However the POSIX proposal for dup3 [1] states that it should return an error if oldfd == newfd. [1] http://austingroupbugs.net/view.php?id=411 Signed-off-by: Richard W.M. Jones <rjo...@redhat.com> Tested-by: Richard W.M. Jones <rjo...@redhat.com> --- fs/file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/file.c b/fs/file.c index 0f1bda4..d3b5fa8 100644 --- a/fs/file.c +++ b/fs/file.c @@ -922,6 +922,9 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags) if ((flags & ~O_CLOEXEC) != 0) return -EINVAL; + if (unlikely(oldfd == newfd)) + return -EINVAL; + if (newfd >= rlimit(RLIMIT_NOFILE)) return -EMFILE; -- 1.7.10.4