netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, Eric Wong <normalperson@yhbt.net>,
	Hannes Frederic Sowa <hannes@stressinduktion.org>
Subject: [patch] net: clamp ->msg_namelen instead of returning an error
Date: Wed, 27 Nov 2013 15:40:21 +0300	[thread overview]
Message-ID: <20131127124021.GA2025@elgon.mountain> (raw)
In-Reply-To: <20131127115120.GC20630@order.stressinduktion.org>

If kmsg->msg_namelen > sizeof(struct sockaddr_storage) then in the
original code that would lead to memory corruption in the kernel if you
had audit configured.  If you didn't have audit configured it was
harmless.

There are some programs such as beta versions of Ruby which use too
large of a buffer and returning an error code breaks them.  We should
clamp the ->msg_namelen value instead.

Reported-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/net/socket.c b/net/socket.c
index 0b18693f2be6..e83c416708af 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1973,7 +1973,7 @@ static int copy_msghdr_from_user(struct msghdr *kmsg,
 	if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
 		return -EFAULT;
 	if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
-		return -EINVAL;
+		kmsg->msg_namelen = sizeof(struct sockaddr_storage);
 	return 0;
 }
 
diff --git a/net/compat.c b/net/compat.c
index 618c6a8a911b..dd32e34c1e2c 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -72,7 +72,7 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
 	    __get_user(kmsg->msg_flags, &umsg->msg_flags))
 		return -EFAULT;
 	if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
-		return -EINVAL;
+		kmsg->msg_namelen = sizeof(struct sockaddr_storage);
 	kmsg->msg_name = compat_ptr(tmp1);
 	kmsg->msg_iov = compat_ptr(tmp2);
 	kmsg->msg_control = compat_ptr(tmp3);

  reply	other threads:[~2013-11-27 12:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-18 10:10 question about klen in move_addr_to_user() Dan Carpenter
2013-03-19 13:55 ` David Miller
2013-10-02 18:58   ` [patch] net: heap overflow in __audit_sockaddr() Dan Carpenter
2013-10-02 21:11     ` Ben Hutchings
2013-10-02 21:26       ` Dan Carpenter
2013-10-02 21:27       ` [patch v2] " Dan Carpenter
2013-10-03 20:06         ` David Miller
2013-11-27 11:32         ` Eric Wong
2013-11-27 11:51           ` Hannes Frederic Sowa
2013-11-27 12:40             ` Dan Carpenter [this message]
2013-11-27 19:42               ` [patch] net: clamp ->msg_namelen instead of returning an error Eric Wong
2013-11-27 21:27               ` Eric Dumazet
2013-11-29 21:13                 ` David Miller
2013-11-27 20:24             ` [patch v2] net: heap overflow in __audit_sockaddr() Linus Torvalds
2013-11-27 21:18               ` Hannes Frederic Sowa
2013-11-27 13:56           ` David Laight

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=20131127124021.GA2025@elgon.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=hannes@stressinduktion.org \
    --cc=netdev@vger.kernel.org \
    --cc=normalperson@yhbt.net \
    /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).