From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFAA9368D6E for ; Tue, 12 May 2026 07:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778569625; cv=none; b=jU4/UuaBEep3h/Vm9A+F48+DkKL7xK7J6i7tgJA1sl8JPxDMvvti+QroM9+0iuNyER2HfW1Kow4WQNfxwdIWvZwTzf+F/AJ4Jr+x6CZQohc0806TQLRfuAYyX3A8oxF+fe24zNmR9RKE5l8u8kkaCRHSA9qsCwS27yiagjNVOo0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778569625; c=relaxed/simple; bh=vS9bD3PJ6QBZRXfBeufUTv14f2N0oWCBZ2zQWoQYBfs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OyqnCfgSl95++8h8k0rQ5FRbdo9688JLeSWw84vkNMh3LhRjXhDT7Ab7GqRfF9Mgt3ZtZTSOQm3gpZs9ykj6Q6OsvpD3kjy+zFIDI7rhQIuL6Y1XVWw21ETOx43+hXomrICi60cuNAtGMAhuNNB4eWMn+jNxTF2qts5Vi3nSNVI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GJMwEO8t; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=pKU8V+Bd; arc=none smtp.client-ip=170.10.133.124 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.b="GJMwEO8t"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="pKU8V+Bd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778569617; 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=gAb8hIM0aTA1jBLlkdpVPpG/v1UTe85oY7sMeZc2mf0=; b=GJMwEO8tv6QtR6qDflyt0mCGRnsiVChuyroUbQYLzhc/3v/oqUeeq5K39rcP7XPyQY8lyK w/Pv+rwgo2T41bqh+FJ+ZyKZ39Sb4r1/7w1wGoAFAxX+eucBhguyXF0cD0fQvZlcWjMRG4 pBcPhmYvlqMKjbTQcVGev0hlrg4Mw9c= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-tOz8KKucP8adABj_T88KMw-1; Tue, 12 May 2026 03:06:56 -0400 X-MC-Unique: tOz8KKucP8adABj_T88KMw-1 X-Mimecast-MFC-AGG-ID: tOz8KKucP8adABj_T88KMw_1778569615 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-488c0120047so30349495e9.0 for ; Tue, 12 May 2026 00:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778569615; x=1779174415; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=gAb8hIM0aTA1jBLlkdpVPpG/v1UTe85oY7sMeZc2mf0=; b=pKU8V+BdcYL2C2ens4Jnikn9y71oQ8Wz7BcQUa1MpgaxYfdSrv4qCLHxCz71FBy038 cjWNbSLk/uVD0K1jzgHyk87ZMKMPTuaHg4rTrKTxbUy8O8zeKloAOi52JqauQiVDe0tT LjjZM/AD+IpSAgcplCR94NvZgI20PKw+461tCW7FZL53LnhLX1KOPcrDhE9nyftIyFsQ 1vAPYID8Nr4PGgdMBh2/Vj/dm9yJlbcQ3Q+9Q0u4gB4RBWgsai7aPjamHSrNn6cjG8Rv 7dob7I3NhsmJnaG/MR49CtkkGL+JSfQ9+JIBQ/zn+0k60D24j09QTsiUjq6xL8KssnV/ CxBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778569615; x=1779174415; h=in-reply-to:content-disposition: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; bh=gAb8hIM0aTA1jBLlkdpVPpG/v1UTe85oY7sMeZc2mf0=; b=MrMJJ2adZdaGtjKpO+vztNxRtksWg0JF8f0qrg9hVAtyQ7uDerCXYCh2DRv9vt8rqC m1tCETZc0pVbg1QG6TXYpAyE9HNFnZfrclxwcRPrPfDsJFq3PQyyoStBAnvO2/ZREnOF PTmOMboN35mpTKx63WE9KbLXHcGWLvH6Qq+6+shYziiK5CuOBrrzW4LuHGw1ETpOsf8J GlV4zARp37pumJKShKczMxvhvKS1UPU7YvYqKnVeJ11Lvhoy39m9dExfMV2Bnp8TCpdQ bB5/wTOF7uH1F4kH+9IPSFurrzrl0VQJzg9XcN31aVsJ46xXUkfCaA+4ISvLSoaLpzUa R1Vg== X-Forwarded-Encrypted: i=1; AFNElJ+bI+y/BFoIAPz2YHsM3bFFyx/zIXXysChyVnIWkj7oNOck3kwXPgSGWkF69///FFQqlL5UzuRlkU4t/YA=@vger.kernel.org X-Gm-Message-State: AOJu0YyDaITuWwvl/vuqoRGbGHqIVClgY5KDtgnAxOBh0okX4so0f7lz hACgNiD4A8FoUxfUON1i3+2PqTg6BjOZ48Um1JipsfqXfvcFGi05yo79g+leIdRNK1KE1SA5WHb dRsrqXXvFVu1hyK0RQU+A/EM0H0Bjw6aTSRmbSZ6m89T8qFDvJCD5VxXMpYLNjdLnfA== X-Gm-Gg: Acq92OGMih7boPdEQxJcFh3uuHwNMV/3gjSFw8klo68OaGUIZ4sWWKJcgV75WBSdlwb SB+m7y2og4M0/0b9QpnPGLK3tCLEQOAd2HLj2nwM3YRsO6UAYQ6QKRNvN98EmK9Uq/uba9fU3MO c6s+XtWnf0JR9HpTfzIuw60rfR2NNwXRRu8Wv4nNZxwIpYLTQBzOA9rIjyoK4HsqnXFYpfQYGyL HseF2ctTntdJlcGD4zHWS+BaDI1IkjERfxDhkpWHUnmSofDJbGoNf0uqnRbPrhBaOuqpd1mcbre 83NE1S8y0JmQyHwmAxEuHt35g4X3ToD4Myb2p75YjikSuUydU8p+SzqhfweI2c8hMjxDViWTP7D BfSDqj8sN+w0H+xdZhfKxX94lwMKsJ9l1ZNIBIxffOuHBI3oKPCHBih0Nb9vvwb92Cz4tjhlN2w == X-Received: by 2002:a05:600c:3b08:b0:489:149a:f9e6 with SMTP id 5b1f17b1804b1-48e8fe80569mr22965905e9.28.1778569614919; Tue, 12 May 2026 00:06:54 -0700 (PDT) X-Received: by 2002:a05:600c:3b08:b0:489:149a:f9e6 with SMTP id 5b1f17b1804b1-48e8fe80569mr22965345e9.28.1778569614432; Tue, 12 May 2026 00:06:54 -0700 (PDT) Received: from sgarzare-redhat (host-87-16-204-231.retail.telecomitalia.it. [87.16.204.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e9052cd24sm24611725e9.3.2026.05.12.00.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 00:06:53 -0700 (PDT) Date: Tue, 12 May 2026 09:06:51 +0200 From: Stefano Garzarella To: Minh Nguyen Cc: Bryan Tan , Vishnu Dasa , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , bcm-kernel-feedback-list@broadcom.com, netdev@vger.kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH net v2] vsock/vmci: fix UAF when peer resets connection during handshake Message-ID: References: <20260512025851.189140-1-minhnguyen.080505@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20260512025851.189140-1-minhnguyen.080505@gmail.com> On Tue, May 12, 2026 at 09:58:51AM +0700, Minh Nguyen wrote: >vmci_transport_recv_connecting_server() jumps to its destroy: label >and performs an unconditional sock_put(pending) to release the >explicit sock_hold() taken by vmci_transport_recv_listen() before >schedule_delayed_work(). The existing comment claimed this was safe >because the listen handler removes pending from the pending list on >the way out, which would prevent vsock_pending_work() from dropping >the same reference later. > >That assumption breaks for a peer RST. The default arm of the packet >switch sets: > > err = pkt->type == VMCI_TRANSPORT_PACKET_TYPE_RST ? 0 : -EINVAL; > >and vmci_transport_recv_listen() only calls vsock_remove_pending() >when err < 0: > > if (err < 0) > vsock_remove_pending(sk, pending); > >For RST (err == 0) the socket stays on the pending list, so when >vsock_pending_work() fires it takes the is_pending=true path and >drops all three references itself: the pending-list reference via >vsock_remove_pending(), then the two trailing sock_put(sk) calls. >The unconditional sock_put() in destroy: had already dropped the >explicit sock_hold() reference, so the second trailing sock_put(sk) >in vsock_pending_work() is a write into the freed AF_VSOCK slab >object. KASAN reports a slab-use-after-free write of 4 bytes from >refcount_warn_saturate() on the workqueue path: > > BUG: KASAN: slab-use-after-free in refcount_warn_saturate > Write of size 4 at addr ffff88800b1cac80 by task kworker > Workqueue: events vsock_pending_work > Call Trace: > refcount_warn_saturate > vsock_pending_work > process_one_work > worker_thread > >Triggering the bug requires only the ability to open a VSOCK >connection to the target and send a RST before the listener accepts. > >Skip the sock_put() in destroy: when err == 0 so it only compensates >the cases where vmci_transport_recv_listen() actually calls >vsock_remove_pending(). RST is the only path that reaches destroy: >with err == 0; every other path produces a negative value, so their >behaviour is unchanged. > >Verified on lts-6.12.79 with KASAN enabled (CONFIG_KASAN_INLINE=y, >kasan_multi_shot): same trigger binary, same VM, 100 iterations: >without this patch 52 KASAN slab-use-after-free reports fire; with >this patch applied, 0 reports. > >Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") >Cc: stable@vger.kernel.org >Signed-off-by: Minh Nguyen >Assisted-by: Claude:claude-opus-4-7 >--- >v2: > - Resubmit to netdev per Stefano Garzarella's request after v1 review. > - Retested the PoC with the patch applied on lts-6.12.79 with KASAN > enabled: 52/100 unpatched -> 0/100 patched (same trigger binary, > same VM, 100 iterations); test summary captured in the commit > message. > - Changed Cc: stable@kernel.org -> stable@vger.kernel.org now that the > bug is no longer embargoed. > - Rebased onto net/main (no functional change to the diff). > >v1 was sent to security@kernel.org on 2026-05-10 (not on lore archives; >no public link available). v1 review summary, for reference: > - Stefano Garzarella (vsock maintainer): "Overall LGTM, but I'd wait > vmware guys on this that know this code better." Asked for retest > and resubmission via the net tree workflow. > - Bryan Tan (VMCI maintainer): "Thanks for the fix, it looks good to > me." Also noted that no modern VMware product allows guest-to-guest > VMCI communication, so the practical attack surface is host -> guest. > > net/vmw_vsock/vmci_transport.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) Acked-by: Stefano Garzarella > >diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c >index 4296ca1..88d7128 100644 >--- a/net/vmw_vsock/vmci_transport.c >+++ b/net/vmw_vsock/vmci_transport.c >@@ -1269,14 +1269,16 @@ vmci_transport_recv_connecting_server(struct sock *listener, > destroy: > pending->sk_err = skerr; > pending->sk_state = TCP_CLOSE; >- /* As long as we drop our reference, all necessary cleanup will handle >- * when the cleanup function drops its reference and our destruct >- * implementation is called. Note that since the listen handler will >- * remove pending from the pending list upon our failure, the cleanup >- * function won't drop the additional reference, which is why we do it >- * here. >+ /* Drop the reference taken by vmci_transport_recv_listen() before >+ * schedule_delayed_work() only on real errors. For a peer RST >+ * (err == 0) the listener leaves pending on the pending list, and >+ * vsock_pending_work() will drop that reference itself when it >+ * later cleans the socket up. Calling sock_put() here in that >+ * case would be a double-put and free the socket while >+ * vsock_pending_work() still holds it. > */ >- sock_put(pending); >+ if (err < 0) >+ sock_put(pending); > > return err; > } > >base-commit: be48e5fe51a5864566307998286a699d6b986934 >-- >2.54.0 >