aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-05-29 03:20:48 -0400
committerDavid S. Miller <davem@davemloft.net>2010-05-29 03:20:48 -0400
commit2903037400a26e7c0cc93ab75a7d62abfacdf485 (patch)
treec29d8b3199d8fa52856e5edcd374411f962d7c11
parent7dfde179c38056b91d51e60f3d50902387f27c84 (diff)
net: fix sk_forward_alloc corruptions
As David found out, sock_queue_err_skb() should be called with socket lock hold, or we risk sk_forward_alloc corruption, since we use non atomic operations to update this field. This patch adds bh_lock_sock()/bh_unlock_sock() pair to three spots. (BH already disabled) 1) skb_tstamp_tx() 2) Before calling ip_icmp_error(), in __udp4_lib_err() 3) Before calling ipv6_icmp_error(), in __udp6_lib_err() Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/skbuff.c4
-rw-r--r--net/ipv4/udp.c2
-rw-r--r--net/ipv6/udp.c6
3 files changed, 10 insertions, 2 deletions
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 4667d4d7c162..f2913ae2b52c 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -2992,7 +2992,11 @@ void skb_tstamp_tx(struct sk_buff *orig_skb,
2992 memset(serr, 0, sizeof(*serr)); 2992 memset(serr, 0, sizeof(*serr));
2993 serr->ee.ee_errno = ENOMSG; 2993 serr->ee.ee_errno = ENOMSG;
2994 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING; 2994 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
2995
2996 bh_lock_sock(sk);
2995 err = sock_queue_err_skb(sk, skb); 2997 err = sock_queue_err_skb(sk, skb);
2998 bh_unlock_sock(sk);
2999
2996 if (err) 3000 if (err)
2997 kfree_skb(skb); 3001 kfree_skb(skb);
2998} 3002}
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index b9d0d409516f..acdc9be833cc 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -634,7 +634,9 @@ void __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
634 if (!harderr || sk->sk_state != TCP_ESTABLISHED) 634 if (!harderr || sk->sk_state != TCP_ESTABLISHED)
635 goto out; 635 goto out;
636 } else { 636 } else {
637 bh_lock_sock(sk);
637 ip_icmp_error(sk, skb, err, uh->dest, info, (u8 *)(uh+1)); 638 ip_icmp_error(sk, skb, err, uh->dest, info, (u8 *)(uh+1));
639 bh_unlock_sock(sk);
638 } 640 }
639 sk->sk_err = err; 641 sk->sk_err = err;
640 sk->sk_error_report(sk); 642 sk->sk_error_report(sk);
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 87be58673b55..3048f906c042 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -466,9 +466,11 @@ void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
466 if (sk->sk_state != TCP_ESTABLISHED && !np->recverr) 466 if (sk->sk_state != TCP_ESTABLISHED && !np->recverr)
467 goto out; 467 goto out;
468 468
469 if (np->recverr) 469 if (np->recverr) {
470 bh_lock_sock(sk);
470 ipv6_icmp_error(sk, skb, err, uh->dest, ntohl(info), (u8 *)(uh+1)); 471 ipv6_icmp_error(sk, skb, err, uh->dest, ntohl(info), (u8 *)(uh+1));
471 472 bh_unlock_sock(sk);
473 }
472 sk->sk_err = err; 474 sk->sk_err = err;
473 sk->sk_error_report(sk); 475 sk->sk_error_report(sk);
474out: 476out: