From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Richard W.M. Jones" Subject: [PATCH regression] dup3: Return an error when oldfd == newfd. Date: Tue, 9 Oct 2012 15:27:43 +0100 Message-ID: <20121009142743.GA20047@rhmail.home.annexia.org> References: <20121009091521.GM24071@rhmail.home.annexia.org> <20121009092549.GA19680@rhmail.home.annexia.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8BIT To: Al Viro , linux-fsdevel@vger.kernel.org, Jim Meyering , Linus Torvalds Return-path: Received: from mx1.redhat.com ([209.132.183.28]:12322 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753703Ab2JIO1t convert rfc822-to-8bit (ORCPT ); Tue, 9 Oct 2012 10:27:49 -0400 Content-Disposition: inline In-Reply-To: <20121009092549.GA19680@rhmail.home.annexia.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: I have tested the attached patch to fix the dup3 regression. Rich. >>From 0944e30e12dec6544b3602626b60ff412375c78f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" 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 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 Tested-by: Richard W.M. Jones --- 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