[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241101044828.55960-1-03zouyi09.25@gmail.com>
Date: Fri, 1 Nov 2024 12:48:28 +0800
From: Yi Zou <03zouyi09.25@...il.com>
To: davem@...emloft.net
Cc: 21210240012@...udan.edu.cn,
21302010073@...udan.edu.cn,
dsahern@...nel.org,
edumazet@...gle.com,
pabeni@...hat.com,
kuba@...nel.org,
netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
Yi Zou <03zouyi09.25@...il.com>
Subject: [PATCH] ipv6: ip6_fib: fix possible null-pointer-dereference in ipv6_route_native_seq_show
In the ipv6_route_native_seq_show function, the fib6_nh variable
is assigned the value from nexthop_fib6_nh(rt->nh), which could
return NULL. This creates a risk of a null-pointer-dereference
when accessing fib6_nh->fib_nh_gw_family. This can be resolved by
checking if fib6_nh is non-NULL before accessing fib6_nh->fib_nh_gw_family
and assign dev using dev = fib6_nh ? fib6_nh->fib_nh_dev : NULL;
to prevent null-pointer dereference errors.
Signed-off-by: Yi Zou <03zouyi09.25@...il.com>
---
net/ipv6/ip6_fib.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index eb111d20615c..6632ab65d206 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -2555,14 +2555,14 @@ static int ipv6_route_native_seq_show(struct seq_file *seq, void *v)
#else
seq_puts(seq, "00000000000000000000000000000000 00 ");
#endif
- if (fib6_nh->fib_nh_gw_family) {
+ if (fib6_nh && fib6_nh->fib_nh_gw_family) {
flags |= RTF_GATEWAY;
seq_printf(seq, "%pi6", &fib6_nh->fib_nh_gw6);
} else {
seq_puts(seq, "00000000000000000000000000000000");
}
- dev = fib6_nh->fib_nh_dev;
+ dev = fib6_nh ? fib6_nh->fib_nh_dev : NULL;
seq_printf(seq, " %08x %08x %08x %08x %8s\n",
rt->fib6_metric, refcount_read(&rt->fib6_ref), 0,
flags, dev ? dev->name : "");
--
2.44.0
Powered by blists - more mailing lists