Skip to content

Commit 8ade06c

Browse files
committed
ipv6: Fix neigh lookup using NULL device.
In some of the rt6_bind_neighbour() call sites, it hasn't hooked up the rt->dst.dev pointer yet, so we'd deref a NULL pointer when obtaining dev->ifindex for the neighbour hash function computation. Just pass the netdevice explicitly in to fix this problem. Reported-by: Bjarke Istrup Pedersen <gurligebis@gentoo.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f1776da commit 8ade06c

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎net/ipv6/route.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,14 @@ static struct neighbour *ip6_neigh_lookup(const struct dst_entry *dst, const voi
129129
return neigh_create(&nd_tbl, daddr, dst->dev);
130130
}
131131

132-
static int rt6_bind_neighbour(struct rt6_info *rt)
132+
static int rt6_bind_neighbour(struct rt6_info *rt, struct net_device *dev)
133133
{
134-
struct neighbour *n = ip6_neigh_lookup(&rt->dst, &rt->rt6i_gateway);
135-
if (IS_ERR(n))
136-
return PTR_ERR(n);
134+
struct neighbour *n = __ipv6_neigh_lookup(&nd_tbl, dev, &rt->rt6i_gateway);
135+
if (!n) {
136+
n = neigh_create(&nd_tbl, &rt->rt6i_gateway, dev);
137+
if (IS_ERR(n))
138+
return PTR_ERR(n);
139+
}
137140
dst_set_neighbour(&rt->dst, n);
138141

139142
return 0;
@@ -746,7 +749,7 @@ static struct rt6_info *rt6_alloc_cow(const struct rt6_info *ort,
746749
#endif
747750

748751
retry:
749-
if (rt6_bind_neighbour(rt)) {
752+
if (rt6_bind_neighbour(rt, rt->dst.dev)) {
750753
struct net *net = dev_net(rt->dst.dev);
751754
int saved_rt_min_interval =
752755
net->ipv6.sysctl.ip6_rt_gc_min_interval;
@@ -1397,7 +1400,7 @@ int ip6_route_add(struct fib6_config *cfg)
13971400
rt->rt6i_prefsrc.plen = 0;
13981401

13991402
if (cfg->fc_flags & (RTF_GATEWAY | RTF_NONEXTHOP)) {
1400-
err = rt6_bind_neighbour(rt);
1403+
err = rt6_bind_neighbour(rt, dev);
14011404
if (err)
14021405
goto out;
14031406
}
@@ -2084,7 +2087,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
20842087
rt->rt6i_flags |= RTF_ANYCAST;
20852088
else
20862089
rt->rt6i_flags |= RTF_LOCAL;
2087-
err = rt6_bind_neighbour(rt);
2090+
err = rt6_bind_neighbour(rt, rt->dst.dev);
20882091
if (err) {
20892092
dst_free(&rt->dst);
20902093
return ERR_PTR(err);

0 commit comments

Comments
 (0)