ipv6: ip6_fib: fix null-pointer dereference in ipv6_route_native_seq_show()
Subsystems (3)
PATCH 1/1 ipv6: ip6_fib: fix null-pointer dereference in ipv6_route_native_seq_show()
Check if fib6_nh is non-NULL before accessing fib6_nh->fib_nh_gw_family in ipv6_route_native_seq_show() to prevent a null-pointer dereference. Assign dev as dev = fib6_nh ? fib6_nh->fib_nh_dev : NULL to ensure safe handling when nexthop_fib6_nh(rt->nh) returns NULL.
--- net/ipv6/ip6_fib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv6/ip6_fib.c +2 -2
@@ -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 :"" );
Signature · 1 line
2.44.0
Jakub Kicinski
maintainerQuoted 4 lines · On Sun, 3 Nov 2024 04:08:20 +0800 Yi Zou wrote:
Check if
fib6_nhis non-NULL before accessingfib6_nh->fib_nh_gw_familyinipv6_route_native_seq_show()to prevent a null-pointer dereference. Assign dev as dev =fib6_nh?fib6_nh->fib_nh_dev: NULL to ensure safe handling whennexthop_fib6_nh(rt->nh)returns NULL.
Are you just sending this patch because nexthop_fib6_nh() may return NULL? Not sure it can happen since we know we're walking a v6-only table here.
Please try to crash it and add a stack trace to the commit message.
BTW your last posting was white space damaged. Stick to git send-email
Quoted 7 lines · Yi Zou
Check if
fib6_nhis non-NULL before accessingfib6_nh->fib_nh_gw_familyinipv6_route_native_seq_show()to prevent a null-pointer dereference. Assign dev as dev =fib6_nh?fib6_nh->fib_nh_dev: NULL to ensure safe handling whennexthop_fib6_nh(rt->nh)returns NULL.Fixes 0379e8e6a9ef ("ipv6: ip6_fib: avoid NPD in ipv6_route_native_seq_show()")
I could not find this commit in upstream trees.
Please make sure to sort out the details before sending a patch.