mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: Yi Zou <03zouyi09.25@gmail.com>, davem@davemloft.net
Cc: 21210240012@m.fudan.edu.cn, 21302010073@m.fudan.edu.cn,
	dsahern@kernel.org, edumazet@google.com, pabeni@redhat.com,
	kuba@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ipv6: route: fix possible null-pointer-dereference in ip6_route_info_create
Date: Tue, 5 Nov 2024 10:31:44 -0700	[thread overview]
Message-ID: <79463950-3acf-45a0-a7fa-30a9c9236292@kernel.org> (raw)
In-Reply-To: <20241101035843.52230-1-03zouyi09.25@gmail.com>

On 10/31/24 9:58 PM, Yi Zou wrote:
> 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,

not really. IPv6 can only have nexthops in the IPv6 address family, and
nexthop_mpath_select will never return NULL since `0` is always valid
index if the group exists.


> 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)) {



      reply	other threads:[~2024-11-05 17:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-01  3:58 Yi Zou
2024-11-05 17:31 ` David Ahern [this message]

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=79463950-3acf-45a0-a7fa-30a9c9236292@kernel.org \
    --to=dsahern@kernel.org \
    --cc=03zouyi09.25@gmail.com \
    --cc=21210240012@m.fudan.edu.cn \
    --cc=21302010073@m.fudan.edu.cn \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --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®