From: Purva Yeshi <purvayeshi550@gmail.com>
To: "David S . Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Purva Yeshi <purvayeshi550@gmail.com>
Subject: [PATCH] net: ipv6: Fix NULL dereference in ipv6_route_check_nh
Date: Wed, 26 Mar 2025 16:22:15 +0530 [thread overview]
Message-ID: <20250326105215.23853-1-purvayeshi550@gmail.com> (raw)
Fix Smatch-detected error:
net/ipv6/route.c:3427 ip6_route_check_nh() error:
we previously assumed '_dev' could be null
Ensure _dev and idev are checked for NULL before dereferencing in
ip6_route_check_nh. Assign NULL explicitly when fib_nh_dev is NULL
to prevent unintended dereferences.
Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
---
net/ipv6/route.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index ef2d23a1e3d5..ad5b3098eba0 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3424,9 +3424,20 @@ static int ip6_route_check_nh(struct net *net,
if (dev != res.nh->fib_nh_dev)
err = -EHOSTUNREACH;
} else {
- *_dev = dev = res.nh->fib_nh_dev;
- netdev_hold(dev, dev_tracker, GFP_ATOMIC);
- *idev = in6_dev_get(dev);
+ if (res.nh->fib_nh_dev) { /* Ensure fib_nh_dev is valid */
+ dev = res.nh->fib_nh_dev;
+
+ if (_dev) /* Only assign if _dev is not NULL */
+ *_dev = dev;
+
+ netdev_hold(dev, dev_tracker, GFP_ATOMIC);
+ *idev = in6_dev_get(dev);
+ } else {
+ if (_dev)
+ *_dev = NULL; /* Explicitly set NULL */
+ if (idev)
+ *idev = NULL; /* Explicitly set NULL */
+ }
}
return err;
--
2.34.1
next reply other threads:[~2025-03-26 10:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 10:52 Purva Yeshi [this message]
2025-03-26 12:57 ` Sabrina Dubroca
2025-03-27 13:41 ` David Ahern
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=20250326105215.23853-1-purvayeshi550@gmail.com \
--to=purvayeshi550@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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
all inboxes | Powered by JetHome®