ipv6: ip6_fib: fix possible null-pointer-dereference in ipv6_route_native_seq_show
Subsystems (3)
PATCH 1/1 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.
--- 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
Quoted 7 lines
In the
ipv6_route_native_seq_showfunction, thefib6_nhvariable is assigned the value fromnexthop_fib6_nh(rt->nh), which could return NULL. This creates a risk of a null-pointer-dereference when accessingfib6_nh->fib_nh_gw_family. This can be resolved by checking iffib6_nhis non-NULL before accessingfib6_nh->fib_nh_gw_familyand assign dev using dev =fib6_nh?fib6_nh->fib_nh_dev: NULL; to prevent null-pointer dereference errors.
…
* Please choose an imperative wording for an improved change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.12-rc5#n94
* Would you like to append parentheses to function names?
* I suggest to omit the word “possible” from the summary phrase.
* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.12-rc5#n145
Regards,
Markus
A message that is not in the archive (sent off-list or not yet received): CAH_kV5EXr6B3vU3mbwHYaCHdSeCcVw9DiNT4on5rNwiAE+svRg@mail.gmail.com
Quoted 4 lines
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.Would you like to send another improved patch version (instead of a reply) according to a change review?
Regards,
Markus
Paolo Abeni
maintainerQuoted 9 lines · Yi Zou
In the
ipv6_route_native_seq_showfunction, thefib6_nhvariable is assigned the value fromnexthop_fib6_nh(rt->nh), which could return NULL. This creates a risk of a null-pointer-dereference when accessingfib6_nh->fib_nh_gw_family. This can be resolved by checking iffib6_nhis non-NULL before accessingfib6_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 <[email protected]>
Please send a new revision, including a the target tree in the subj prefix - in this case 'net' and a suitable Fixes tag.
/P
David Ahern
maintainerQuoted 11 lines · Paolo Abeni
Quoted 8 lines · Yi Zou
In the
ipv6_route_native_seq_showfunction, thefib6_nhvariable is assigned the value fromnexthop_fib6_nh(rt->nh), which could return NULL. This creates a risk of a null-pointer-dereference when accessingfib6_nh->fib_nh_gw_family. This can be resolved by checking iffib6_nhis non-NULL before accessingfib6_nh->fib_nh_gw_family
and assign dev using dev =fib6_nh?fib6_nh->fib_nh_dev: NULL;
to prevent null-pointer dereference errors.
Quoted 7 lines
Quoted 1 line
Signed-off-by Yi Zou <[email protected]>Please send a new revision, including a the target tree in the subj prefix - in this case 'net' and a suitable Fixes tag.
/P
I would also like to understand why you believe NULL can really happen - excluding memory corruption or custom patches to a kernel. If you look at the make up of nexthop_fib6_nh it is defensive around bugs elsewhere (nhsel > number of nexthops) and future changes (support for ipv6 nexthops that are not IPV6 addresses).
That comment applies to all of these patches around nexthop_fib6_nh possibly returning NULL.