Commit 3a06a68b40164cc73b89017a5ec9eec925037631
Committed by
Greg Kroah-Hartman
1 parent
faf8cf001d
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 <subashab@codeaurora.org> Cc: Eric Dumazet <edumazet@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Showing 1 changed file with 4 additions and 1 deletions Side-by-side Diff
net/ipv4/ping.c
... | ... | @@ -965,8 +965,11 @@ |
965 | 965 | |
966 | 966 | sk = ping_lookup(net, skb, ntohs(icmph->un.echo.id)); |
967 | 967 | if (sk != NULL) { |
968 | + struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); | |
969 | + | |
968 | 970 | pr_debug("rcv on socket %p\n", sk); |
969 | - ping_queue_rcv_skb(sk, skb_get(skb)); | |
971 | + if (skb2) | |
972 | + ping_queue_rcv_skb(sk, skb2); | |
970 | 973 | sock_put(sk); |
971 | 974 | return; |
972 | 975 | } |