mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: Nikolay Aleksandrov <razor@blackwall.org>,
	Li Zhong <floridsleeves@gmail.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: pabeni@redhat.com, kuba@kernel.org, edumazet@google.com,
	davem@davemloft.net, yoshfuji@linux-ipv6.org
Subject: Re: [PATCH v1] net/ipv4/nexthop: check the return value of nexthop_find_by_id()
Date: Sat, 17 Sep 2022 08:46:42 -0600	[thread overview]
Message-ID: <b11141f6-95b7-883e-d924-b9b2699eb980@kernel.org> (raw)
In-Reply-To: <9974177e-7067-aacd-1c53-7e82616f3c3f@blackwall.org>

On 9/17/22 2:29 AM, Nikolay Aleksandrov wrote:
> On 17/09/2022 05:30, Li Zhong wrote:
>> Check the return value of nexthop_find_by_id(), which could be NULL on
>> when not found. So we check to avoid null pointer dereference.
>>
>> Signed-off-by: Li Zhong <floridsleeves@gmail.com>
>> ---
>>  net/ipv4/nexthop.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
>> index 853a75a8fbaf..9f91bb78eed5 100644
>> --- a/net/ipv4/nexthop.c
>> +++ b/net/ipv4/nexthop.c
>> @@ -2445,6 +2445,10 @@ static struct nexthop *nexthop_create_group(struct net *net,
>>  		struct nh_info *nhi;
>>  
>>  		nhe = nexthop_find_by_id(net, entry[i].id);
>> +		if (!nhe) {
>> +			err = -EINVAL;
>> +			goto out_no_nh;
>> +		}
>>  		if (!nexthop_get(nhe)) {
>>  			err = -ENOENT;
>>  			goto out_no_nh;
> 
> These are validated in nh_check_attr_group() and should exist at this point.
> Since remove_nexthop() should run under rtnl I don't see a way for a nexthop
> to disappear after nh_check_attr_group() and before nexthop_create_group().
> 

exactly. That lookup can't fail because the ids have been validated and
all of this is under rtnl preventing nexthop removes.


  reply	other threads:[~2022-09-17 14:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-17  2:30 Li Zhong
2022-09-17  8:29 ` Nikolay Aleksandrov
2022-09-17 14:46   ` David Ahern [this message]
2022-09-18  1:54     ` Li Zhong

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=b11141f6-95b7-883e-d924-b9b2699eb980@kernel.org \
    --to=dsahern@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=floridsleeves@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=yoshfuji@linux-ipv6.org \
    /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®