netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcus Meissner <meissner@suse.de>
To: Reinhard Max <max@suse.de>, David Miller <davem@davemloft.net>,
	netdev@vger.kernel.org
Subject: [PATCH] net/ipv6: check for mistakenly passed in non-AF_INET6 sockaddrs
Date: Mon, 6 Jun 2011 18:00:07 +0200	[thread overview]
Message-ID: <20110606160007.GD28535@suse.de> (raw)
In-Reply-To: <alpine.LNX.2.00.1106061538210.13876@nitsch.suse.de>

On Mon, Jun 06, 2011 at 03:47:30PM +0200, Reinhard Max wrote:
> 
> On Wed, 1 Jun 2011 at 21:03, David Miller wrote:
> 
> >Since we haven't been validating the sin_family field for 18+ years, 
> >the chance to break some applications is very real.
> >
> >But I think it's more important to fix this (and force any broken 
> >apps to set sin_family correctly).  So I will apply this, thanks.
> 
> I think a corresponding check should also go into inet6_bind() in 
> net/ipv6/af_inet6.c .

Good idea,

Same check as for IPv4, also do for IPv6.

(If you passed in a IPv4 sockaddr_in here, the sizeof check
 in the line before would have triggered already though.)

Signed-off-by: Marcus Meissner <meissner@suse.de>
Cc: Reinhard Max <max@suse.de>

Ciao, Marcus
---
 net/ipv6/af_inet6.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index b7919f9..d450a2f 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -272,6 +272,10 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 
 	if (addr_len < SIN6_LEN_RFC2133)
 		return -EINVAL;
+
+	if (addr->sin6_family != AF_INET6)
+		return -EINVAL;
+
 	addr_type = ipv6_addr_type(&addr->sin6_addr);
 	if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
 		return -EINVAL;
-- 
1.7.4.1


  reply	other threads:[~2011-06-06 16:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-25 15:59 Bad behaviour when unintentionally mixing ipv4 and ipv6 addresses Marcus Meissner
2011-06-02  4:03 ` David Miller
2011-06-06 13:47   ` Reinhard Max
2011-06-06 16:00     ` Marcus Meissner [this message]
2011-06-06 21:48       ` [PATCH] net/ipv6: check for mistakenly passed in non-AF_INET6 sockaddrs David Miller
2011-06-07  7:25       ` Reinhard Max

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=20110606160007.GD28535@suse.de \
    --to=meissner@suse.de \
    --cc=davem@davemloft.net \
    --cc=max@suse.de \
    --cc=netdev@vger.kernel.org \
    /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).