From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796200200; b=pDwa/NBSelF5WJEvXc+/In9Bx6LZtNAQco+A/A7idLZ0PNpmT51UfQagwAxP5X5vI/3f Xsgmwxs+Qy+hXAyWAYJUMkXdj/hH+RIVXbJXnRurD65V8kKJE+p3KaHQT6Ed/oet3a4aE 683g+iRfRCtYszlRK/N15dHrPWhZSQ3QWKt9WsYJBf3YFc8i1fecE4ptCgp/t/RQr3CgU IoVSwGoJ0zK8FJSn405yxpFkUwGzLKNZmTFWadWLxXX5gFEFEfBHblraQvzM9FIBM44hb i0uKtAezlVpgx9BOYy+h6p4DArUM9trL1ZQwg59JtL1Ft4JroYlp3Xjtt2pr0+3LJpg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200200; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=QhuXJIrWtyUIj/dE7ROcBphxlTMyzsA1Nds3aj7B87Y=; b=ixnNgNwfhdT16zKTJD0kM2Ia9tfRKDkVBkiDxcZv659XzT4OXVT/X0bX0DLlkYrQrRnw iY1MPUIvHmxVtYCHrajK1g88HGYKDIxAt5zQwhFy9MmkTAFGd2StXKupa/fgyqam5V7LH XkQXaTT4v66gwmaarhVkcF7clKlqmS/NM9tiWz1n9xwcOv/b0QMJP719rP1Xwrx5YyLer iQwO4rlOs459h+8VFlCoi4lLhSquIEzD0iH42RVKc1+VwbhZnfqYRSgWC1zGXfK8LUeEl 0+DV/ZqX2cJ3wyRy6uZPapgHzg39rkUxXWWnhBFJX229WE1fj9nsjPudR96eUXvoDKQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gjRWgi25; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=XcmywCS5; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45F3A606A322 for ; Wed, 2 Dec 2026 08:30:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 45F3A606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gjRWgi25; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=XcmywCS5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796200199; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QhuXJIrWtyUIj/dE7ROcBphxlTMyzsA1Nds3aj7B87Y=; b=gjRWgi25aRNygoVl3Vz02ujDELhuKIDeWf+WSWCdBUpC5q+jdtiQop+9Av/TWIG1drIgWQ gdiU0kCMQ06os8OpTLy+CX4uyRMcRoOQx/iVMyXSZsFF73IEBKajkOpp2xcsIWg3duoLPp ESreJ/9ACLlsuwzsDCfnzi2GbpYFZ+U= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-YHDfZwGrPguuHXJ0CkmCjQ-1; Wed, 2 Dec 2026 08:29:57 +0000 X-MC-Unique: YHDfZwGrPguuHXJ0CkmCjQ-1 X-Mimecast-MFC-AGG-ID: YHDfZwGrPguuHXJ0CkmCjQ_1796200196 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4915ba023d4so8309749f8f.0 for ; Wed, 02 Dec 2026 00:29:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796200196; x=1796804996; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=QhuXJIrWtyUIj/dE7ROcBphxlTMyzsA1Nds3aj7B87Y=; b=XcmywCS5gYaAuso8+xBzYuf8AgVdaOwrsT/yvXowjaAAHgZBpb7KodES0ACCRbQWv7 gjbT4yR0mdul9247mLPg6i3XZEweaVbpzM2X1KAt+LJ+mI4HOBu2sbzPGkCnLjkAzhIE E0BlxZ7BM2txH2kUMrkUwu/dGQCiEnlp+6pfgbu6W14oFQr+KJuLEoJj4fcOpqrN3214 jjWUGB/iSSTTkCVbOghJakC9ej+DNSEOGyXN5pGtrnX4YTuKFueChNc8O8QDAWxQNfwW A+8qeuW+sBe5ay1ccuf2S8Mmwh6M1R+bmfrVW6AYsVG4YXdUUnKgda+xnoNZAzEDpUrE 2ArA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796200196; x=1796804996; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QhuXJIrWtyUIj/dE7ROcBphxlTMyzsA1Nds3aj7B87Y=; b=Oz3MUnuS96eife8Td39xkdXYZo/q5EmMEdgTsezSO3MQSzKytKGvfXMFeEFYivbN/B hCbFvtR47kAk3f63sF3jtlmfzR0scyTOfQIgG3TfTL2uzaEM7XSi8NKXe8z6Wat7RUgs 9UbGXt49gsp7IblyRrWBl1gdpqttpVbjH+fY+nJ26wVNGYFP/dEbGbgxo0S2tM8C2wUh 9Gmrck2JPnap7aJZsL3UxEOofCGJEbAGxVC/SGaZjqIFNSsWbS0b028tYoD/wC3doZF5 W1zGDWcD75JZsr8wASBNndpl8lHXc3fHbihrXE9HwB+FkWByAjK1lNetDSGHwSfCtt9Q bgMg== X-Forwarded-Encrypted: i=1; AL+hErGupAbXgFRBRTyib283oMU9GOGZI+cBL/xY5S8rDKFJEfHUXjKvps3knTLGYHmD50Ip8fNbcR/IO7YXdkY=@vger.kernel.org X-Gm-Message-State: APuU4Z83QFoIFwcPoZ2uMzEssA7Z3NZVPznfrrBoMpM0UyLt5SwLc91C DhXcY7u+tTk5hA2wLdO8ThhhToo+zIguPie7ZsKuREqIYx6hQFlmviYIulIJcqdSbPDi+nqy9Bu JHkXYJh3vnIcR3p7n8ccoWC1M1bSjgVNCnGzRp72rqACB/tpH8uJeKlr9P+hdu8vwtg== X-Gm-Gg: AZFdTZch7jt6Onp16Xef5REOguFBdQPtGqLIRGevBPi55i0PpVyz36G6rHP9G7Zdgrh LgquhPe/a8eJUnBkAfcHaIXRcSHZ90WGBTRaOV+SjsyhBxgpDafNPFlYjnBOPzX1IEL95MDeJGd jS8U1nfkpr00GCBlB2Emr6PnMnoLBofqNkztwhcwsN+Fe6vClAMjbZnQwOU+9D7kEN3JQXJimRd cAlUfcKOVUzmfcTdsydwFpKfGcPEW/F2BRzqorl4lsLbBcbDYKR7JgW/AinTmhCFfHLh9KWHd1S EdFSKHmPgaaB94P/tPyfsLL431vWdZ8AHUmRTlPs5ugi3ZbheJU0+qMVmz26jB5uvKIvFnAO1DU QwhP/flKQjE9JIhVYoGlUCtdLKkBVuI1oFBC+OY48cWLbVxaex8OXz/N0eHP1UH+VKPH05XZf3E fmcuILgu81feEQhA== X-Received: by 2002:a05:6000:2dc5:b0:4a8:1b63:2165 with SMTP id ffacd0b85a97d-4abaab631b4mr81146130f8f.8.1796200196372; Wed, 02 Dec 2026 00:29:56 -0800 (PST) X-Received: by 2002:a05:6000:2dc5:b0:4a8:1b63:2165 with SMTP id ffacd0b85a97d-4abaab631b4mr81146087f8f.8.1796200195922; Wed, 02 Dec 2026 00:29:55 -0800 (PST) Received: from sgarzare-redhat (ip190-139-192-82.pool-bba.aruba.it. [82.192.139.190]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6a67f281sm72700696f8f.22.2026.12.02.00.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 00:29:54 -0800 (PST) Date: Wed, 2 Dec 2026 09:29:48 +0100 From: Stefano Garzarella To: Hu Xinyao Cc: Stefan Hajnoczi , Bobby Eshleman , "Michael S. Tsirkin" , Jason Wang , Eugenio Perez , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close Message-ID: References: <580BB20747AD7900+1796014782.205252-1-huxinyao@kylinsec.com.cn> <4F56BD84AD04C29B+1796182154.53519-reply-vsock-huxinyao@kylinsec.com.cn> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <4F56BD84AD04C29B+1796182154.53519-reply-vsock-huxinyao@kylinsec.com.cn> On Wed, Dec 02, 2026 at 12:29:14PM +0900, Hu Xinyao wrote: >On Tue, Dec 01, 2026 at 06:05:30PM +0100, Stefano Garzarella wrote: >> >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c >> >index 1e762a4..9dade6e 100644 >> >--- a/net/vmw_vsock/virtio_transport_common.c >> >+++ b/net/vmw_vsock/virtio_transport_common.c >> >@@ -1411,10 +1411,10 @@ static void virtio_transport_close_timeout(struct work_struct *work) >> > (void)virtio_transport_reset(vsk, NULL); >> > >> > virtio_transport_do_close(vsk, false); >> >+ } else { >> >+ virtio_transport_cancel_close_work(vsk, false); >> > } >> > >> >- vsk->close_work_scheduled = false; >> >> Why we are removing this? > >Hi Stefano, > >With the else branch added, both branches now call >virtio_transport_cancel_close_work(vsk, false) (the !SOCK_DONE branch >via virtio_transport_do_close(vsk, false), and the SOCK_DONE branch >directly). Okay, I see now. > >In virtio_transport_cancel_close_work(vsk, false), !cancel_timeout is >unconditionally true, so whenever vsk->close_work_scheduled is set it >already clears vsk->close_work_scheduled = false (along with calling >virtio_transport_remove_sock(vsk) and sock_put(sk)), and if it was >already false it remains false. Previously, the trailing assignment only >had an effect when SOCK_DONE was already set and do_close() was skipped, >clearing the flag without releasing the socket reference or removing the >socket. > >Sorry for not spelling that out in the commit message (since >virtio_transport_cancel_close_work() is outside the diff context). >Alternatively, we could avoid the else branch and just replace >"vsk->close_work_scheduled = false;" with an unconditional >"virtio_transport_cancel_close_work(vsk, false);" after the if >(!sock_flag(sk, SOCK_DONE)) block, which is a no-op if do_close() >already ran. Happy to send a v2 whichever way you prefer. Just mention this in the commit message. Without too many words, including only the necessary information. The commit message is already hard enough to understand... This is just how I'd have wrote it (just a suggestion, feel free to write as you prefer): virtio_transport_close() takes a socket reference and schedules vsk->close_work, which runs virtio_transport_close_timeout(). If the peer resets the connection after the work started running but before it takes the socket lock, nobody drops that reference: CPU0 (close_work) CPU1 (rx: OP_RST) close_timeout() lock_sock() lock_sock() /* waits */ do_close(vsk, true) SOCK_DONE = 1 cancel_delayed_work() == false /* ref not dropped */ release_sock() SOCK_DONE set, skip do_close() close_work_scheduled = false /* ref leaked */ Fix it by letting virtio_transport_close_timeout() complete the cleanup when SOCK_DONE is already set. The explicit "close_work_scheduled = false" is no longer needed, since virtio_transport_cancel_close_work() clears it in both branches. ... Thanks, Stefano