lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 4 Jul 2019 22:55:04 +0300
From:   Ido Schimmel <idosch@...sch.org>
To:     David Miller <davem@...emloft.net>
Cc:     netdev@...r.kernel.org, dsahern@...il.com, jiri@...lanox.com,
        shalomt@...lanox.com, mlxsw@...lanox.com, idosch@...lanox.com
Subject: Re: [PATCH net] ipv4: Fix NULL pointer dereference in
 ipv4_neigh_lookup()

On Thu, Jul 04, 2019 at 12:24:49PM -0700, David Miller wrote:
> From: Ido Schimmel <idosch@...sch.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;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ