Patch "net: stream: purge sk_error_queue in sk_stream_kill_queues()" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    net: stream: purge sk_error_queue in sk_stream_kill_queues()

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     net-stream-purge-sk_error_queue-in-sk_stream_kill_qu.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 4f6352c5c3ef6ca33f1d4ea735b93dda1728e7dd
Author: Eric Dumazet <edumazet@xxxxxxxxxx>
Date:   Fri Dec 16 16:29:17 2022 +0000

    net: stream: purge sk_error_queue in sk_stream_kill_queues()
    
    [ Upstream commit e0c8bccd40fc1c19e1d246c39bcf79e357e1ada3 ]
    
    Changheon Lee reported TCP socket leaks, with a nice repro.
    
    It seems we leak TCP sockets with the following sequence:
    
    1) SOF_TIMESTAMPING_TX_ACK is enabled on the socket.
    
       Each ACK will cook an skb put in error queue, from __skb_tstamp_tx().
       __skb_tstamp_tx() is using skb_clone(), unless
       SOF_TIMESTAMPING_OPT_TSONLY was also requested.
    
    2) If the application is also using MSG_ZEROCOPY, then we put in the
       error queue cloned skbs that had a struct ubuf_info attached to them.
    
       Whenever an struct ubuf_info is allocated, sock_zerocopy_alloc()
       does a sock_hold().
    
       As long as the cloned skbs are still in sk_error_queue,
       socket refcount is kept elevated.
    
    3) Application closes the socket, while error queue is not empty.
    
    Since tcp_close() no longer purges the socket error queue,
    we might end up with a TCP socket with at least one skb in
    error queue keeping the socket alive forever.
    
    This bug can be (ab)used to consume all kernel memory
    and freeze the host.
    
    We need to purge the error queue, with proper synchronization
    against concurrent writers.
    
    Fixes: 24bcbe1cc69f ("net: stream: don't purge sk_error_queue in sk_stream_kill_queues()")
    Reported-by: Changheon Lee <darklight2357@xxxxxxxxxx>
    Signed-off-by: Eric Dumazet <edumazet@xxxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/core/stream.c b/net/core/stream.c
index a61130504827..d7c5413d16d5 100644
--- a/net/core/stream.c
+++ b/net/core/stream.c
@@ -196,6 +196,12 @@ void sk_stream_kill_queues(struct sock *sk)
 	/* First the read buffer. */
 	__skb_queue_purge(&sk->sk_receive_queue);
 
+	/* Next, the error queue.
+	 * We need to use queue lock, because other threads might
+	 * add packets to the queue without socket lock being held.
+	 */
+	skb_queue_purge(&sk->sk_error_queue);
+
 	/* Next, the write queue. */
 	WARN_ON(!skb_queue_empty(&sk->sk_write_queue));
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux