Re: [PATCH 1/1] af_packet: Raw socket destruction warning fix

From: Eric Dumazet
Date: Wed Feb 10 2016 - 10:09:56 EST


On Wed, 2016-02-10 at 17:35 +0530, Maninder Singh wrote:
> This Patch fixes below warning:-
> WARNING: at net/packet/af_packet.c:xxx packet_sock_destruct
>
> There is following race between packet_rcv and packet_close
> which keeps unfree packet in receive queue.
>
> CPU 1 CPU2
> packet_rcv
>
> packet_close
> skb_set_owner_r(skb, sk);
>
> skb_queue_purge(&sk->sk_receive_queue);
>
> spin_lock(&sk->sk_receive_queue.lock);
> __skb_queue_tail(&sk->sk_receive_queue, skb);
> spin_unlock(&sk->sk_receive_queue.lock);

This absolutely can not happen.

CPU 1 holds rcu read lock, so cpu 2 can not possibly call
skb_queue_purge()

(cpu 1 is blocked in synchronize_net(), waiting that all cpus are no
longer in packet_rcv())

This patch does not address the root cause of your problem, and only
slightly changes probability for the bug to trigger.