Netdev List
 help / color / mirror / Atom feed
From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: davem@davemloft.net, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH 1/2] net: ipv4: Fix a possible null-pointer dereference in inet_csk_rebuild_route()
Date: Fri, 26 Jul 2019 10:25:34 +0800	[thread overview]
Message-ID: <20190726022534.24994-1-baijiaju1990@gmail.com> (raw)

In inet_csk_rebuild_route(), rt is assigned to NULL on line 1071.
On line 1076, rt is used:
    return &rt->dst;
Thus, a possible null-pointer dereference may occur.

To fix this bug, rt is checked before being used.

This bug is found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 net/ipv4/inet_connection_sock.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index f5c163d4771b..27d9d80f3401 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1073,7 +1073,10 @@ static struct dst_entry *inet_csk_rebuild_route(struct sock *sk, struct flowi *f
 		sk_setup_caps(sk, &rt->dst);
 	rcu_read_unlock();
 
-	return &rt->dst;
+	if (rt)
+		return &rt->dst;
+	else
+		return NULL;
 }
 
 struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu)
-- 
2.17.0


             reply	other threads:[~2019-07-26  2:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-26  2:25 Jia-Ju Bai [this message]
2019-07-26  9:15 ` [PATCH 1/2] net: ipv4: Fix a possible null-pointer dereference in inet_csk_rebuild_route() Nicolas Dichtel
2019-07-27 20:25 ` David Miller

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=20190726022534.24994-1-baijiaju1990@gmail.com \
    --to=baijiaju1990@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --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