From: David Ahern <dsahern@gmail.com>
To: David Miller <davem@davemloft.net>, idosch@idosch.org
Cc: netdev@vger.kernel.org, jiri@mellanox.com, shalomt@mellanox.com,
mlxsw@mellanox.com, idosch@mellanox.com
Subject: Re: [PATCH net] ipv4: Fix NULL pointer dereference in ipv4_neigh_lookup()
Date: Fri, 5 Jul 2019 09:37:53 -0600 [thread overview]
Message-ID: <dfb3bb3c-c077-7b8f-75e9-4185d997b024@gmail.com> (raw)
In-Reply-To: <20190704.122449.742393341056317443.davem@davemloft.net>
On 7/4/19 1:24 PM, David Miller wrote:
> From: Ido Schimmel <idosch@idosch.org>
> Date: Thu, 4 Jul 2019 19:26:38 +0300
>
>> Both ip_neigh_gw4() and ip_neigh_gw6() can return either a valid pointer
>> or an error pointer, but the code currently checks that the pointer is
>> not NULL.
> ...
>> @@ -447,7 +447,7 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
>> n = ip_neigh_gw4(dev, pkey);
>> }
>>
>> - if (n && !refcount_inc_not_zero(&n->refcnt))
>> + if (!IS_ERR(n) && !refcount_inc_not_zero(&n->refcnt))
>> n = NULL;
>>
>> rcu_read_unlock_bh();
>
> Don't the callers expect only non-error pointers?
>
> All of this stuff is so confusing and fragile...
>
The intention was to fold the lookup and neigh_create calls into a
single helper.
The lookup can return NULL if an entry does not exist; the create can
return an ERR_PTR (variety of reasons in ___neigh_create). So the end
result is that the new helper (lookup + create) can return a valid neigh
entry or an ERR_PTR.
When I converted ipv4_neigh_lookup and folded in the refcount bump, I
missed updating the above check to account for ERR_PTR.
Ido's patch looks correct to me. Thanks, Ido.
Reviewed-by: David Ahern <dsahern@gmail.com>
next prev parent reply other threads:[~2019-07-05 15:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-04 16:26 [PATCH net] ipv4: Fix NULL pointer dereference in ipv4_neigh_lookup() Ido Schimmel
2019-07-04 19:24 ` David Miller
2019-07-04 19:55 ` Ido Schimmel
2019-07-05 15:37 ` David Ahern [this message]
2019-07-05 23:19 ` David Miller
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=dfb3bb3c-c077-7b8f-75e9-4185d997b024@gmail.com \
--to=dsahern@gmail.com \
--cc=davem@davemloft.net \
--cc=idosch@idosch.org \
--cc=idosch@mellanox.com \
--cc=jiri@mellanox.com \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=shalomt@mellanox.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;
as well as URLs for NNTP newsgroup(s).