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=v4HNxIBPWZwdzDhiQZgbpdEEzZ9SOoX1un0qLYnk+sC9G/YZyBAK/H9oaXrrdNgmcKFU QTfcfUqqGYkeJ4xnPcLoLHYcvXLQ/f0aDLzB08Gaqhh2wXRDjduyUH2VWMZfhPSfQww+j /LAs2kLf9uBR0F7H51P5NVjJTIkuqZuuT+Ctwg7Km8npYwqcm5feSKeURGRM1gadITUSx jOC8Dxaw5mk1EZxPmVufXyJ0n/QtfV9iD+QN5vCaO0pr0goO1v11YbQ1grgaTFjW6oy82 Xmt1vddKhCMxPhq4S7iHRHDqe9ot6dP5+5OT99k0GsfniU5pJG21dBj3lrHV7UyAHkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200201; h=DMARC-Filter:DKIM-Signature:X-MC-Rep:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received: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:In-Reply-To:X-Mimecast-Spam-Score:X-Mimecast-MFC-PROC-ID: X-Mimecast-Originator:Content-Type:Content-Disposition; bh=QhuXJIrWtyUIj/dE7ROcBphxlTMyzsA1Nds3aj7B87Y=; b=vlB4I5iYhuA8K8QlHC8wrz9jwunmpyyp23XtH3oxV0R7WS66Gc3Ez4AARaUrjbKBksBp JhcNEjxQJgEbruIQNGkVVk2vy+ioHNOMSquBRBokplOAyRfItFjZFtCZcIyjXvGQTRgPU TDnYM/CqsqAE0HJCJTKAD7YJXtpYBgQ5PcJBZ4E+Dn4whAxwEFH7Tjr2xrqiCcERBMl+S BPKG6L+dmUmqeMb9qB3Pre0YrtJDxi6j3EFKAVZ9+d/TUWYtnegx1EzNq1kgABZ8N8Kmv M1NUM5gYg+6P4l38pqCuuvWB622o2RiedtYIPJWCUZuSCAVwlF2+GgxUzRJzJPBdPbg== 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; 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 9C457606A31A for ; Wed, 2 Dec 2026 08:30:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C457606A31A 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-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= X-MC-Rep: binary re single Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-126-_ILFd5ZEPn2YbDndKUANGQ-1; Wed, 2 Dec 2026 08:29:57 +0000 X-MC-Unique: _ILFd5ZEPn2YbDndKUANGQ-1 X-Mimecast-MFC-AGG-ID: _ILFd5ZEPn2YbDndKUANGQ_1796200196 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4915ba023d4so8309755f8f.0 for ; Wed, 02 Dec 2026 00:29:57 -0800 (PST) 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=FRKHiaEoub4NRu/RzAMQyVJtrOD+ikUV9rAfYOZxufNteXmNMu7+XQVHAqPjWlvyKf 2dlj+DqRwkRjWczsiyEralKbPy5h1MXOo2IDcSPa3POjj7bjEiIdAFmAzjUMTibUOAl+ v1GbsFf8n9ZmHec06kk6QJ9Tl5mUCfcGcr2IcMU3kNVNDRQhnOFwXkvC5Aic171BmMQw THZxElO4FmdtwhRDgL+UG8xkE0HlJAmjmbyt3ExR7F6xr1WkLioVK9Ou2a6q1Zbu5RLt 1M6rw0rYfzLy4Wy6jFzgNyHMGR+BS0ibnBsG4gGtyTIZUcbuTfpPbkujIdx31leMnORr 4yAQ== X-Forwarded-Encrypted: i=1; AL+hErFymAN2FMlHzRXaEZQ+19nHczbYcvEQHpEhAz8P2FQfI+hp7Moyc208AnhTM+v4lYbGjRgzG2kZbit6jZRxgg==@lists.linux.dev X-Gm-Message-State: APuU4Z/+QaO1aMaWizyaW0nS7pzUIpkl+VPOWsEuJV+qx2AIrkvjJ7nf wGKV/m3zo782C9PQoS7tqNZ9TA1SqgXJ800nAe9FKcOT2/ffVkWXas0kXy5AhsW3ArFDOhU0gjy 8cY5fk7csA2j/owaDRksCVSoqnaYeffhCboopzqaOMHTx29sLKu8mEPMl92/a90G7FYyB X-Gm-Gg: AZFdTZfdfc+DVNmb/+AlSTsVMFJlqZRwII017i0p6S0VIp9F/2HGi/20YJMi2wHYgP+ yySBe2ZU/ktvmFHWXSLC0kKn89mHk3EHAN4RsU5mkQ4lDGuOAe2MfM26gASWm586jBRa1fVNynr KSIyb1/EMzpPNn8npNQBqPn4C9vG5I3cA4Hr89JpUmjMUj3No+fyXUW67wGhBsPo6BkCjkHamji IVkBRR90IICjlPI2alNs2NwnFjaxO2OQYyHqm76fSIJKNEsx5zn9yEFa5A6GBy35DtjutafHUcs 3hEYyoscViZRAjWBN0JRIXjEVxueXrWoeC6WEaxvZ6hnThX0Sj8Al+4AIXaRRpBmCPf5qI7vxwC qARKJWpexXRKuJtE6UC8w86EStUU6AqYDdeqWE15Sad0Fr5VVGzBMTaV8XqYfJPCGJekVSmgiqo Tyy7mDzR1/0jlU1Q== X-Received: by 2002:a05:6000:2dc5:b0:4a8:1b63:2165 with SMTP id ffacd0b85a97d-4abaab631b4mr81146139f8f.8.1796200196401; 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: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 In-Reply-To: <4F56BD84AD04C29B+1796182154.53519-reply-vsock-huxinyao@kylinsec.com.cn> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: udydBGa8W9jG8FJvblmKxsPwwVGUsoCymFO4qUHauqo_1796200196 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline 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