aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2011-07-29 15:00:53 -0400
committerDavid S. Miller <davem@davemloft.net>2011-08-03 06:34:12 -0400
commitf2c31e32b378a6653f8de606149d963baf11d7d3 (patch)
tree4eeb8075a93520935381a75514f309228e6824c0 /net/ipv4
parent28f4881cbf9ce285edfc245a8990af36d21c062f (diff)
net: fix NULL dereferences in check_peer_redir()
Gergely Kalman reported crashes in check_peer_redir(). It appears commit f39925dbde778 (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>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/ip_output.c10
-rw-r--r--net/ipv4/route.c14
2 files changed, 16 insertions, 8 deletions
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index ccaaa851ab42..77d3eded665a 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -204,9 +204,15 @@ static inline int ip_finish_output2(struct sk_buff *skb)
204 skb = skb2; 204 skb = skb2;
205 } 205 }
206 206
207 rcu_read_lock();
207 neigh = dst_get_neighbour(dst); 208 neigh = dst_get_neighbour(dst);
208 if (neigh) 209 if (neigh) {
209 return neigh_output(neigh, skb); 210 int res = neigh_output(neigh, skb);
211
212 rcu_read_unlock();
213 return res;
214 }
215 rcu_read_unlock();
210 216
211 if (net_ratelimit()) 217 if (net_ratelimit())
212 printk(KERN_DEBUG "ip_finish_output2: No header cache and no neighbour!\n"); 218 printk(KERN_DEBUG "ip_finish_output2: No header cache and no neighbour!\n");
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 1730689f560e..6afc4eb50591 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1628,16 +1628,18 @@ static int check_peer_redir(struct dst_entry *dst, struct inet_peer *peer)
1628{ 1628{
1629 struct rtable *rt = (struct rtable *) dst; 1629 struct rtable *rt = (struct rtable *) dst;
1630 __be32 orig_gw = rt->rt_gateway; 1630 __be32 orig_gw = rt->rt_gateway;
1631 struct neighbour *n; 1631 struct neighbour *n, *old_n;
1632 1632
1633 dst_confirm(&rt->dst); 1633 dst_confirm(&rt->dst);
1634 1634
1635 neigh_release(dst_get_neighbour(&rt->dst));
1636 dst_set_neighbour(&rt->dst, NULL);
1637
1638 rt->rt_gateway = peer->redirect_learned.a4; 1635 rt->rt_gateway = peer->redirect_learned.a4;
1639 rt_bind_neighbour(rt); 1636
1640 n = dst_get_neighbour(&rt->dst); 1637 n = ipv4_neigh_lookup(&rt->dst, &rt->rt_gateway);
1638 if (IS_ERR(n))
1639 return PTR_ERR(n);
1640 old_n = xchg(&rt->dst._neighbour, n);
1641 if (old_n)
1642 neigh_release(old_n);
1641 if (!n || !(n->nud_state & NUD_VALID)) { 1643 if (!n || !(n->nud_state & NUD_VALID)) {
1642 if (n) 1644 if (n)
1643 neigh_event_send(n, NULL); 1645 neigh_event_send(n, NULL);