From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796200201; b=P/oXFNAAN+e2arXn83cZpORdNzC9OokQC09YCpLI8ITU0NX86cLoEiSX+SQvCQhxkNjd 5vK46y3In/qeNGkz5wfBH+ZVL/ln7K1vdK1f83aICHN5TJmXDZESLXJlfGt/t/mn7UfGi 2UbaycGjEK4v9QBxM7IPJO7jTpKqr+pdk9ztTn4l9okQcXdmxjxIW3K9AitrJOm+w0Jat 3ogvX5QlY7V9MKIFYVV9+9cicZmE6JFXVMUDIQhyJJMkpEEhZwVeju4XV9oBUCXL1M7h0 yPzxoGi4GzYemKhit8gcp5yXbhhyOdGXeH6LaSF8BQ3Zy3Kb6efCCVOdiD006B8F0ag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200201; 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=zKwM4dnpPS136/Pp0yol3wu6FztDLAPK2ypd7EWoOvXwSYBlUFWaCCbU3z+k/gO2EGck TlC0/Y894fmAu5lyEDGkPBga23XKgmB05tamfekklF9etspCf/ZOAXHhd/LDRzm5uCbLc KJWBuZID9LvzNeI58rfRQCcngk6UbVh6Oncfr7dmmm8tH/sIu/cJmlujzB/pP7aJkYVvU 0EKj3w4DXil+wwhiuLO8xoYghzetNO0Xa4xnHC3BLcKNE5FivlxqfLtQOnvhP1ve7DWu8 n7Bk+MgXBkNppNM31Wr61vUgpwKG7tfIFFv3/lu/nyvi9s5dFzINVs+vbUEAOp1JHvg== 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.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 4BBDD606A323 for ; Wed, 2 Dec 2026 08:30:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4BBDD606A323 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-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-22-utfS6YmwM5mefqk0jzmoMg-1; Wed, 2 Dec 2026 08:29:57 +0000 X-MC-Unique: utfS6YmwM5mefqk0jzmoMg-1 X-Mimecast-MFC-AGG-ID: utfS6YmwM5mefqk0jzmoMg_1796200196 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4925ef75fc4so7891755f8f.1 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=uL6C8XhiWEkGp/ST2z7EmqZ1o1ASRFEgzKnVhT2n+sE7HHjAuoG+R/XY6PRWQp2JwF zqy3TTNofWTqIaxk23g77yTt9lZrBp/F3BdpzDXRd+bLI07RONb7Jvj5PYA41Ig0i5oj 44d97+2I/9MU3VsGNV1bGN/LpcmXoar5nDh66xvRTOJ0/NpkgT7dbkSjet5aac0D1ZBJ 2SiVHDv37lg8SgO2afyW+fby59IW2sQZZT/rYDgydMM4sou/dZlAgHuUyDJt6Np2aS7Z XuqAKVCY2iAQQNFmLQcbdgWDd4Q/QHNUC2+DCDFowX9b828Nlh4TEKMpAb0PL/0esV26 JuNw== X-Forwarded-Encrypted: i=1; AL+hErF6C4J4dKjTZvsrg5lCl6bUT6MNvD+9MWEtA4TMvVOu0jOrV9Ld7FRBU9LmDuvnqpeoN2T2YJw=@vger.kernel.org X-Gm-Message-State: APuU4Z9795ovsAbGea4AuEP3N8d4WMLwXohjZZbvV69Hky69veuWA/1v vavkfOHk9avkRbh4WBEQRqoQsA8atafQ5GgB+1Qv/a3IheT9nHuFJVmE8dLHi7Sqyxv35V54hcZ EEos09dlrmHZoaEtQgH46WxghgDXGE78Zar1WnXXAn0614Xg5PQAu3ePYhA== X-Gm-Gg: AZFdTZfj+JPUQ2Y+IKonseXltfK549OUDNZOg/sWUkPagWWIUSamTFFZ8EzRlZNrX66 OVwCqMDlP8Yv0JpuhfSU8rWI5XniuIMfVfEczoCeBLbLhn2jiklEWbHf4T8Phb09ps4jtFPYb9j +DViclohFcivL5fz0tK07KqsxSKqxKIfIlGq7dYWlWkHfkAH92P69WZ0ZmboSiKDxwUhkPtmAzU LGpP/dXxnFQMd1AselRVJGn2Z2CcWWSI8r4pQ5qw4XFlqQLZhw2kSMP2TJ7ugJWBG3t712Y27qu TiELFdb+tg9VGD5krWeAXpOXRMHXuDd8dMYjPR4YP2WPC/HE4b9nHfq1xaaNDkJXiNM1abud4Ik koWNH6uTErLPpjhARDIIpL5IJ+lSZvz34lFsbwToVpHT0LBn3P5ltejdviM5D0wwhQUD2kKjgYg Z85Ff0DNTGtRtoxQ== X-Received: by 2002:a05:6000:2dc5:b0:4a8:1b63:2165 with SMTP id ffacd0b85a97d-4abaab631b4mr81146138f8f.8.1796200196395; 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: netdev@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