All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org, dsahern@gmail.com, 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: Thu, 4 Jul 2019 22:55:04 +0300	[thread overview]
Message-ID: <20190704195504.GA20705@splinter> (raw)
In-Reply-To: <20190704.122449.742393341056317443.davem@davemloft.net>

On Thu, Jul 04, 2019 at 12:24:49PM -0700, 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?

It is actually OK to return an error pointer here. In fact, before the
commit I cited the function returned the return value of neigh_create().

If you think it's clearer, we can do this instead:

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 8ea0735a6754..40697fcd2889 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -447,6 +447,9 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
                n = ip_neigh_gw4(dev, pkey);
        }
 
+       if (IS_ERR(n))
+               n = NULL;
+
        if (n && !refcount_inc_not_zero(&n->refcnt))
                n = NULL;

  reply	other threads:[~2019-07-04 19:55 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 [this message]
2019-07-05 15:37   ` David Ahern
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=20190704195504.GA20705@splinter \
    --to=idosch@idosch.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --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 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.