netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: cebbert@redhat.com
Cc: socketpair_bug@rich-paul.net, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, viro@ftp.linux.org.uk
Subject: Re: BUG in sys_socketpair
Date: Mon, 29 Oct 2007 21:55:00 -0700 (PDT)	[thread overview]
Message-ID: <20071029.215500.114909860.davem@davemloft.net> (raw)
In-Reply-To: <4720E424.7060509@redhat.com>

From: Chuck Ebbert <cebbert@redhat.com>
Date: Thu, 25 Oct 2007 14:44:52 -0400

> On 10/25/2007 10:11 AM, Rich Paul wrote:
> > In 2.6.23, there seems to be a minor bug in sys_socketpair.  When the
> > calls to sock_alloc_fd fail, it aborts the routine, but it returns the
> > variable err, which is not set in this case.
> > 
> > The result is a silent failure if you have too many files open and call
> > socketpair.
> > 
> > Here is a simple UNTESTED patch (not even compiled) which should resolve the
> > issue.
> > 
> > 
> > --- net/socket.c.orig   2007-10-25 10:03:56.000000000 -0400
> > +++ net/socket.c        2007-10-25 10:04:00.000000000 -0400
> Should be "err = fd1" (spaces), otherwise looks good.
> 
> Original did:
> 
> 	err = sock_map_fd(sock1);
> 	if (err < 0)
> 		goto out_release_both;
> 	fd1 = err;

Thanks everyone, I'll commit the following both to 2.6.x GIT
and -stable.

>From 42f3fc7e989554e9952bdf28af137e4e4570f067 Mon Sep 17 00:00:00 2001
From: David S. Miller <davem@sunset.davemloft.net>
Date: Mon, 29 Oct 2007 21:54:02 -0700
Subject: [PATCH] [NET]: Fix error reporting in sys_socketpair().

If either of the two sock_alloc_fd() calls fail, we
forget to update 'err' and thus we'll erroneously
return zero in these cases.

Based upon a report and patch from Rich Paul, and
commentary from Chuck Ebbert.

Signed-off-by: David S. Miller <davem@davemloft.net>
---
 net/socket.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index 540013e..5d879fd 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1250,11 +1250,14 @@ asmlinkage long sys_socketpair(int family, int type, int protocol,
 		goto out_release_both;
 
 	fd1 = sock_alloc_fd(&newfile1);
-	if (unlikely(fd1 < 0))
+	if (unlikely(fd1 < 0)) {
+		err = fd1;
 		goto out_release_both;
+	}
 
 	fd2 = sock_alloc_fd(&newfile2);
 	if (unlikely(fd2 < 0)) {
+		err = fd2;
 		put_filp(newfile1);
 		put_unused_fd(fd1);
 		goto out_release_both;
-- 
1.5.2.5


      reply	other threads:[~2007-10-30  4:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-25 14:11 BUG in sys_socketpair Rich Paul
2007-10-25 18:44 ` Chuck Ebbert
2007-10-30  4:55   ` David Miller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071029.215500.114909860.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=cebbert@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=socketpair_bug@rich-paul.net \
    --cc=viro@ftp.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).