aboutsummaryrefslogtreecommitdiffstats
path: root/net/bridge
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2012-02-09 16:13:19 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-02-13 14:06:13 -0500
commit8a533666d1591cf4ea596c6bd710e2fe682cb56a (patch)
tree0c525703fd834499c659490b3cb38835fde14f51 /net/bridge
parent323a479328cbc2fb5cf647790f7414ca570a577b (diff)
net: fix NULL dereferences in check_peer_redir()
[ Upstream commit d3aaeb38c40e5a6c08dd31a1b64da65c4352be36, along with dependent backports of commits: 69cce1d1404968f78b177a0314f5822d5afdbbfb 9de79c127cccecb11ae6a21ab1499e87aa222880 218fa90f072e4aeff9003d57e390857f4f35513e 580da35a31f91a594f3090b7a2c39b85cb051a12 f7e57044eeb1841847c24aa06766c8290c202583 e049f28883126c689cf95859480d9ee4ab23b7fa ] 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net/bridge')
-rw-r--r--net/bridge/br_netfilter.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index 56149ec36d7..3dc7f5446a9 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -343,24 +343,26 @@ static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
343static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb) 343static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
344{ 344{
345 struct nf_bridge_info *nf_bridge = skb->nf_bridge; 345 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
346 struct neighbour *neigh;
346 struct dst_entry *dst; 347 struct dst_entry *dst;
347 348
348 skb->dev = bridge_parent(skb->dev); 349 skb->dev = bridge_parent(skb->dev);
349 if (!skb->dev) 350 if (!skb->dev)
350 goto free_skb; 351 goto free_skb;
351 dst = skb_dst(skb); 352 dst = skb_dst(skb);
353 neigh = dst_get_neighbour(dst);
352 if (dst->hh) { 354 if (dst->hh) {
353 neigh_hh_bridge(dst->hh, skb); 355 neigh_hh_bridge(dst->hh, skb);
354 skb->dev = nf_bridge->physindev; 356 skb->dev = nf_bridge->physindev;
355 return br_handle_frame_finish(skb); 357 return br_handle_frame_finish(skb);
356 } else if (dst->neighbour) { 358 } else if (neigh) {
357 /* the neighbour function below overwrites the complete 359 /* the neighbour function below overwrites the complete
358 * MAC header, so we save the Ethernet source address and 360 * MAC header, so we save the Ethernet source address and
359 * protocol number. */ 361 * protocol number. */
360 skb_copy_from_linear_data_offset(skb, -(ETH_HLEN-ETH_ALEN), skb->nf_bridge->data, ETH_HLEN-ETH_ALEN); 362 skb_copy_from_linear_data_offset(skb, -(ETH_HLEN-ETH_ALEN), skb->nf_bridge->data, ETH_HLEN-ETH_ALEN);
361 /* tell br_dev_xmit to continue with forwarding */ 363 /* tell br_dev_xmit to continue with forwarding */
362 nf_bridge->mask |= BRNF_BRIDGED_DNAT; 364 nf_bridge->mask |= BRNF_BRIDGED_DNAT;
363 return dst->neighbour->output(skb); 365 return neigh->output(skb);
364 } 366 }
365free_skb: 367free_skb:
366 kfree_skb(skb); 368 kfree_skb(skb);