mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ipv6: route: fix possible null-pointer-dereference in ip6_route_info_create
@ 2024-11-01  3:58 Yi Zou
  2024-11-05 17:31 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: Yi Zou @ 2024-11-01  3:58 UTC (permalink / raw)
  To: davem
  Cc: 21210240012, 21302010073, dsahern, edumazet, pabeni, kuba,
	netdev, linux-kernel, Yi Zou

In the ip6_route_info_create function, the variable fib6_nh is
assigned the return value of nexthop_fib6_nh(rt->nh), which could
result in fib6_nh being NULL. Immediately after this assignment,
there is a potential dereference of fib6_nh in the following code:
if (!ipv6_addr_any(&cfg->fc_prefsrc)) {
 struct net_device *dev = fib6_nh->fib_nh_dev;
This lead to a null pointer dereference (NPD) risk if fib6_nh is
NULL. The issue can be resolved by adding a NULL check before the
deference line.

Signed-off-by: Yi Zou <03zouyi09.25@gmail.com>
---
 net/ipv6/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index b4251915585f..919592fa4e64 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3821,7 +3821,7 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
 			rt->fib6_flags = RTF_REJECT | RTF_NONEXTHOP;
 	}
 
-	if (!ipv6_addr_any(&cfg->fc_prefsrc)) {
+	if (!ipv6_addr_any(&cfg->fc_prefsrc) && fib6_nh) {
 		struct net_device *dev = fib6_nh->fib_nh_dev;
 
 		if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) {
-- 
2.44.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-05 17:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-01  3:58 [PATCH] ipv6: route: fix possible null-pointer-dereference in ip6_route_info_create Yi Zou
2024-11-05 17:31 ` David Ahern

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®