diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index f847cf1fbeaf..91c1d6cad497 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -609,6 +609,28 @@ static void unix_write_space(struct sock *sk) rcu_read_unlock(); } +static void scm_stat_add(struct sock *sk, struct sk_buff *skb) +{ + struct scm_fp_list *fp = UNIXCB(skb).fp; + struct unix_sock *u = unix_sk(sk); + + if (unlikely(fp && fp->count)) { + atomic_add(fp->count, &u->scm_stat.nr_fds); + unix_add_edges(fp, u); + } +} + +static void scm_stat_del(struct sock *sk, struct sk_buff *skb) +{ + struct scm_fp_list *fp = UNIXCB(skb).fp; + struct unix_sock *u = unix_sk(sk); + + if (unlikely(fp && fp->count)) { + atomic_sub(fp->count, &u->scm_stat.nr_fds); + unix_del_edges(fp); + } +} + /* When dgram socket disconnects (or changes its peer), we clear its receive * queue of packets arrived from previous peer. First, it allows to do * flow control based only on wmem_alloc; second, sk connected to peer @@ -616,8 +638,19 @@ static void unix_write_space(struct sock *sk) static void unix_dgram_disconnected(struct sock *sk, struct sock *other) { if (!skb_queue_empty(&sk->sk_receive_queue)) { - skb_queue_purge_reason(&sk->sk_receive_queue, - SKB_DROP_REASON_UNIX_DISCONNECT); + struct sk_buff_head tmp; + struct sk_buff *skb; + + __skb_queue_head_init(&tmp); + + spin_lock(&sk->sk_receive_queue.lock); + skb_queue_splice_init(&sk->sk_receive_queue, &tmp); + spin_unlock(&sk->sk_receive_queue.lock); + + while ((skb = __skb_dequeue(&tmp)) != NULL) { + scm_stat_del(sk, skb); + kfree_skb_reason(skb, SKB_DROP_REASON_UNIX_DISCONNECT); + } wake_up_interruptible_all(&unix_sk(sk)->peer_wait); @@ -2059,28 +2092,6 @@ static bool unix_skb_scm_eq(const struct sock *sk, struct sk_buff *skb, unix_secdata_eq(scm, skb); } -static void scm_stat_add(struct sock *sk, struct sk_buff *skb) -{ - struct scm_fp_list *fp = UNIXCB(skb).fp; - struct unix_sock *u = unix_sk(sk); - - if (unlikely(fp && fp->count)) { - atomic_add(fp->count, &u->scm_stat.nr_fds); - unix_add_edges(fp, u); - } -} - -static void scm_stat_del(struct sock *sk, struct sk_buff *skb) -{ - struct scm_fp_list *fp = UNIXCB(skb).fp; - struct unix_sock *u = unix_sk(sk); - - if (unlikely(fp && fp->count)) { - atomic_sub(fp->count, &u->scm_stat.nr_fds); - unix_del_edges(fp); - } -} - static void unix_orphan_scm(struct sock *sk, struct sk_buff *skb) { scm_stat_del(sk, skb);