+ dup2-fix-return-value-with-oldfd-==-newfd-and-invalid-fd.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     dup2: fix return value with oldfd == newfd and invalid fd
has been added to the -mm tree.  Its filename is
     dup2-fix-return-value-with-oldfd-==-newfd-and-invalid-fd.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find
out what to do about this

The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/

------------------------------------------------------
Subject: dup2: fix return value with oldfd == newfd and invalid fd
From: Jeff Mahoney <jeffm@xxxxxxxx>

Fix a regression introduced with 6c5d0512a091480c9f981162227fdb1c9d70e555
("get rid of corner case in dup3() entirely").

The return value of dup2 when oldfd == newfd and the fd isn't valid is not
getting properly sign extended.  We end up with 4294967287 instead of
-EBADF.

I've reproduced this on SLE11 (2.6.27.21), openSUSE Factory (2.6.29-rc5),
and Ubuntu 9.04 (2.6.28).

This patch uses a signed int for the error value so it is properly extended.

Reported-by: Jiri Dluhos <jdluhos@xxxxxxxxxx>
Signed-off-by: Jeff Mahoney <jeffm@xxxxxxxx>
Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Cc: <stable@xxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 fs/fcntl.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff -puN fs/fcntl.c~dup2-fix-return-value-with-oldfd-==-newfd-and-invalid-fd fs/fcntl.c
--- a/fs/fcntl.c~dup2-fix-return-value-with-oldfd-==-newfd-and-invalid-fd
+++ a/fs/fcntl.c
@@ -115,13 +115,14 @@ out_unlock:
 
 SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd)
 {
+	int ret = oldfd;
 	if (unlikely(newfd == oldfd)) { /* corner case */
 		struct files_struct *files = current->files;
 		rcu_read_lock();
 		if (!fcheck_files(files, oldfd))
-			oldfd = -EBADF;
+			ret = -EBADF;
 		rcu_read_unlock();
-		return oldfd;
+		return ret;
 	}
 	return sys_dup3(oldfd, newfd, 0);
 }
_

Patches currently in -mm which might be from jeffm@xxxxxxxx are

origin.patch
dup2-fix-return-value-with-oldfd-==-newfd-and-invalid-fd.patch

--
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Newbies FAQ]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux