netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Lesokhin <ilyal@mellanox.com>
To: netdev@vger.kernel.org, davem@davemloft.net
Cc: davejwatson@fb.com, aviadye@mellanox.com,
	Ilya Lesokhin <ilyal@mellanox.com>,
	Boris Pismenny <borisp@mellanox.com>
Subject: [PATCH v2 net-next 1/3] ipv6: Prevent unexpected sk->sk_prot changes
Date: Tue, 15 Aug 2017 14:08:38 +0300	[thread overview]
Message-ID: <1502795320-22538-2-git-send-email-ilyal@mellanox.com> (raw)
In-Reply-To: <1502795320-22538-1-git-send-email-ilyal@mellanox.com>

With this patch IPV6 code ensure that only sockets with the
expected sk->sk_prot are converted to IPV4.

Signed-off-by: Boris Pismenny <borisp@mellanox.com>
---
 net/ipv6/ipv6_sockglue.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 02d795f..318cd344 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -174,6 +174,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
 		if (val == PF_INET) {
 			struct ipv6_txoptions *opt;
 			struct sk_buff *pktopt;
+			struct proto *expected_prot;
 
 			if (sk->sk_type == SOCK_RAW)
 				break;
@@ -199,6 +200,17 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
 				break;
 			}
 
+			if (sk->sk_protocol == IPPROTO_TCP &&
+			    sk->sk_prot != &tcpv6_prot)
+				break;
+
+			expected_prot = &udpv6_prot;
+			if (sk->sk_protocol == IPPROTO_UDPLITE)
+				expected_prot = &udplitev6_prot;
+
+			if (sk->sk_prot != expected_prot)
+				break;
+
 			fl6_free_socklist(sk);
 			__ipv6_sock_mc_close(sk);
 
-- 
1.8.3.1

  reply	other threads:[~2017-08-15 11:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 11:08 [PATCH v2 net-next 0/3] Use correct sk->sk_prot for IPV6 Ilya Lesokhin
2017-08-15 11:08 ` Ilya Lesokhin [this message]
2017-08-15 11:39   ` [PATCH v2 net-next 1/3] ipv6: Prevent unexpected sk->sk_prot changes Eric Dumazet
2017-08-15 11:59   ` Eric Dumazet
2017-08-15 13:08     ` Boris Pismenny
2017-08-15 14:45       ` Eric Dumazet
2017-08-23  7:49         ` Ilya Lesokhin
2017-08-15 11:08 ` [PATCH v2 net-next 2/3] net: Export tcpv6_prot Ilya Lesokhin
2017-08-15 11:08 ` [PATCH v2 net-next 3/3] tls: Use correct sk->sk_prot for IPV6 Ilya Lesokhin

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=1502795320-22538-2-git-send-email-ilyal@mellanox.com \
    --to=ilyal@mellanox.com \
    --cc=aviadye@mellanox.com \
    --cc=borisp@mellanox.com \
    --cc=davejwatson@fb.com \
    --cc=davem@davemloft.net \
    --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).