From: subashab@codeaurora.org Date: Fri, 23 Jan 2015 22:26:02 +0000 (+0000) Subject: ping: Fix race in free in receive path X-Git-Tag: submit/tizen/20171013.014523~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=653756932975bded4c5a1e2b873650600b6778eb;p=profile%2Fmobile%2Fplatform%2Fkernel%2Flinux-3.10-sc7730.git ping: Fix race in free in receive path [ Upstream commit fc752f1f43c1c038a2c6ae58cc739ebb5953ccb0 ] An exception is seen in ICMP ping receive path where the skb destructor sock_rfree() tries to access a freed socket. This happens because ping_rcv() releases socket reference with sock_put() and this internally frees up the socket. Later icmp_rcv() will try to free the skb and as part of this, skb destructor is called and which leads to a kernel panic as the socket is freed already in ping_rcv(). -->|exception -007|sk_mem_uncharge -007|sock_rfree -008|skb_release_head_state -009|skb_release_all -009|__kfree_skb -010|kfree_skb -011|icmp_rcv -012|ip_local_deliver_finish Fix this incorrect free by cloning this skb and processing this cloned skb instead. This patch was suggested by Eric Dumazet Signed-off-by: Subash Abhinov Kasiviswanathan Cc: Eric Dumazet Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman [sw0312.kim: cherry-pick from linux-3.10.y to apply CVE] Signed-off-by: Seung-Woo Kim Change-Id: I0d137abf0735314648cd2cdaabe5b818b6dff956 --- diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index 248aca2..947210e 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c @@ -965,8 +965,11 @@ void ping_rcv(struct sk_buff *skb) sk = ping_lookup(net, skb, ntohs(icmph->un.echo.id)); if (sk != NULL) { + struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); + pr_debug("rcv on socket %p\n", sk); - ping_queue_rcv_skb(sk, skb_get(skb)); + if (skb2) + ping_queue_rcv_skb(sk, skb2); sock_put(sk); return; }