net: fix NULL dereferences in check_peer_redir()
Gergely Kalman reported crashes in check_peer_redir().
It appears commit f39925dbde
(ipv4: Cache learned redirect
information in inetpeer.) added a race, leading to possible NULL ptr
dereference.
Since we can now change dst neighbour, we should make sure a reader can
safely use a neighbour.
Add RCU protection to dst neighbour, and make sure check_peer_redir()
can be called safely by different cpus in parallel.
As neighbours are already freed after one RCU grace period, this patch
should not add typical RCU penalty (cache cold effects)
Many thanks to Gergely for providing a pretty report pointing to the
bug.
Reported-by: Gergely Kalman <synapse@hippy.csoma.elte.hu>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
28f4881cbf
commit
f2c31e32b3
@ -204,9 +204,15 @@ static inline int ip_finish_output2(struct sk_buff *skb)
|
||||
skb = skb2;
|
||||
}
|
||||
|
||||
rcu_read_lock();
|
||||
neigh = dst_get_neighbour(dst);
|
||||
if (neigh)
|
||||
return neigh_output(neigh, skb);
|
||||
if (neigh) {
|
||||
int res = neigh_output(neigh, skb);
|
||||
|
||||
rcu_read_unlock();
|
||||
return res;
|
||||
}
|
||||
rcu_read_unlock();
|
||||
|
||||
if (net_ratelimit())
|
||||
printk(KERN_DEBUG "ip_finish_output2: No header cache and no neighbour!\n");
|
||||
|
Reference in New Issue
Block a user