From: Eric Dumazet Date: Fri, 6 Apr 2012 08:49:10 +0000 (+0200) Subject: net: fix a race in sock_queue_err_skb() X-Git-Tag: v2.6.34.15~161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0fb4f06b9f82f4ffee41bd19e3da44deabed78e;p=thirdparty%2Fkernel%2Fstable.git net: fix a race in sock_queue_err_skb() commit 110c43304db6f06490961529536c362d9ac5732f upstream. As soon as an skb is queued into socket error queue, another thread can consume it, so we are not allowed to reference skb anymore, or risk use after free. Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller [PG: net/core/skbuff.c --> include/net/sock.h on 2.6.34 baseline] Signed-off-by: Paul Gortmaker --- diff --git a/include/net/sock.h b/include/net/sock.h index b365fc2597c3a..133e350c6fa3b 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1428,6 +1428,8 @@ extern int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb); static inline int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb) { + int len = skb->len; + /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces number of warnings when compiling with -W --ANK */ @@ -1437,7 +1439,7 @@ static inline int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb) skb_set_owner_r(skb, sk); skb_queue_tail(&sk->sk_error_queue, skb); if (!sock_flag(sk, SOCK_DEAD)) - sk->sk_data_ready(sk, skb->len); + sk->sk_data_ready(sk, len); return 0; }