All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Zhong <floridsleeves@gmail.com>
To: David Ahern <dsahern@kernel.org>
Cc: Nikolay Aleksandrov <razor@blackwall.org>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	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 18:54:35 -0700	[thread overview]
Message-ID: <CAMEuxRrrw8PSbpKjd6W-pvRc9fLCJUvqtqdAM1JwhLpizx7ZMw@mail.gmail.com> (raw)
In-Reply-To: <b11141f6-95b7-883e-d924-b9b2699eb980@kernel.org>

On Sat, Sep 17, 2022 at 7:46 AM David Ahern <dsahern@kernel.org> wrote:
>
> 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.
>

Thanks for all your replies. That makes sense to me.

      reply	other threads:[~2022-09-18  1:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-17  2:30 [PATCH v1] net/ipv4/nexthop: check the return value of nexthop_find_by_id() Li Zhong
2022-09-17  8:29 ` Nikolay Aleksandrov
2022-09-17 14:46   ` David Ahern
2022-09-18  1:54     ` Li Zhong [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=CAMEuxRrrw8PSbpKjd6W-pvRc9fLCJUvqtqdAM1JwhLpizx7ZMw@mail.gmail.com \
    --to=floridsleeves@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.