linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gaurav Singh <gaurav1086@gmail.com>
To: gaurav1086@gmail.com, "David S. Miller" <davem@davemloft.net>,
	Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>,
	Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
	Jakub Kicinski <kuba@kernel.org>, Shaohua Li <shli@fb.com>,
	netdev@vger.kernel.org (open list:NETWORKING [IPv4/IPv6]),
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] [net/ipv6] ip6_output: Add ipv6_pinfo null check
Date: Sat,  8 Aug 2020 13:06:52 -0400	[thread overview]
Message-ID: <20200808170653.8515-1-gaurav1086@gmail.com> (raw)
In-Reply-To: <20200728021348.4116-1-gaurav1086@gmail.com>

This PR fixes a possible segmentation violation.

In function: ip6_xmit(), we have
const struct ipv6_pinfo *np = inet6_sk(sk); which returns NULL
unconditionally (regardless sk being  NULL or not).

In include/linux/ipv6.h:

static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
{
    return NULL;
}

Further down the function, there's a check:
if (np) hlimit = hp->htop_limit

Thereafter, we have a call
ip6_flow_hdr(hdr, tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel,
ip6_autoflowlabel(net, np), fl6));

Hence np = NULL gets passed in
the function ip6_autoflowlabel() that accesses np without check which
may cause a segment violation.

Fixes: 513674b5a2c9c ("net: reevalulate autoflowlabel setting after sysctl setting")

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 net/ipv6/ip6_output.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 8a8c2d0cfcc8..94a07c9bd925 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -181,10 +181,10 @@ int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
 
 bool ip6_autoflowlabel(struct net *net, const struct ipv6_pinfo *np)
 {
-	if (!np->autoflowlabel_set)
-		return ip6_default_np_autolabel(net);
-	else
+	if (np && np->autoflowlabel_set)
 		return np->autoflowlabel;
+	else
+		return ip6_default_np_autolabel(net);
 }
 
 /*
-- 
2.17.1


  parent reply	other threads:[~2020-08-08 17:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27  3:38 [PATCH] [net/ipv6] ip6_output: Add ipv6_pinfo null check Gaurav Singh
2020-07-27  5:18 ` kernel test robot
2020-07-27 10:34 ` kernel test robot
2020-07-27 18:39 ` David Miller
2020-07-27 19:50 ` Cong Wang
2020-07-28  2:13 ` Gaurav Singh
2020-07-28  3:12   ` Cong Wang
2020-07-28 14:41     ` Eric Dumazet
2020-08-08 17:06   ` Gaurav Singh [this message]
2020-08-08 17:37     ` Cong Wang

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=20200808170653.8515-1-gaurav1086@gmail.com \
    --to=gaurav1086@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=shli@fb.com \
    --cc=yoshfuji@linux-ipv6.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).