Skip to content

Commit 7adf324

Browse files
sbrivio-rhdavem330
authored andcommitted
ipv6: route: Fix return value of ip6_neigh_lookup() on neigh_create() error
In ip6_neigh_lookup(), we must not return errors coming from neigh_create(): if creation of a neighbour entry fails, the lookup should return NULL, in the same way as it's done in __neigh_lookup(). Otherwise, callers legitimately checking for a non-NULL return value of the lookup function might dereference an invalid pointer. For instance, on neighbour table overflow, ndisc_router_discovery() crashes ndisc_update() by passing ERR_PTR(-ENOBUFS) as 'neigh' argument. Reported-by: Jianlin Shi <jishi@redhat.com> Fixes: f8a1b43 ("net/ipv6: Create a neigh_lookup for FIB entries") Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 202700e commit 7adf324

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/ipv6/route.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw,
210210
n = __ipv6_neigh_lookup(dev, daddr);
211211
if (n)
212212
return n;
213-
return neigh_create(&nd_tbl, daddr, dev);
213+
214+
n = neigh_create(&nd_tbl, daddr, dev);
215+
return IS_ERR(n) ? NULL : n;
214216
}
215217

216218
static struct neighbour *ip6_dst_neigh_lookup(const struct dst_entry *dst,

0 commit comments

Comments
 (0)