From nobody Fri Jun 12 22:50:27 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B6413783AF for ; Tue, 12 May 2026 02:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778554746; cv=none; b=nkh8Xcid58XoeFXrHsgudIaFn4Tp2sfesLdmD9JkaaTBQy/YEEQCPozjRtWCBFnTg5Gl65t81OX1pRW/AFJzx/4Y9OMi9o5SRdJjFll8KKu+W8x8O8c9+mxjkyn7yRlxf0PYskyPvghqEkKWofNIrTstWx3o0YpDd4N1UblGdcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778554746; c=relaxed/simple; bh=qELwf6yVFwCKCy76GRQ3b5WHenmlqq0luRAqIwCu6hs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bzvlajtLu5UE/efyGwghwLaPKUaEBmskud0g5ppNlaxnjczC/ieW9E41GWAaKjRt02J/iNiCbWSyQg5mSMyPHbbQjqSDeUjDySgwM1JKTA0Zd2+kzEBmIf6LA7QiXp45ElMzILQAe9faY35SguUHhoz1auBAA40GqoXl2yRNHA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=L8PoftOC; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L8PoftOC" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2b458ca2296so32837705ad.0 for ; Mon, 11 May 2026 19:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778554745; x=1779159545; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=i/R8nu4FmGtSchXT9i0AhYNs7M9dg3GLRopNafO7mLQ=; b=L8PoftOCWkBHzoslNDycXPYshKTi+1JGR/7UxSoLKdun7CzVeSuyRT1cAsLmgO8Aln XXZSl4TFGRIm18BanBxRUNJ9tjJi5mWYkLOitiQxo/1SkX5QSIxiQyuntg1gUIF2mNMG fHJl/rswAqJs4AHl7v6lZ9CIjsgfIpV5FV/F86WCJ+kFInTJjwGAXJyBqTQyPX5I+qUR wHPTa6OwqKUbiMHTdg5m4MddtdmHcMJOPlGkkOalzq+Jr5+nYnD2MCmgY3a1dWLX036t 3B1gAuW/xhBelydx8O9Z/lfNtp4V5jKfzMPc/BK29SP+ZBRARS95Hq6HaPvqYK9BPdN9 S9Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778554745; x=1779159545; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i/R8nu4FmGtSchXT9i0AhYNs7M9dg3GLRopNafO7mLQ=; b=acb6xkDaLCCMy+ZfTINFHtdXnoctX6imUZ1ug4Ay2905loMeqT6PlAsn6GLyEOcJck sLgB0AJiePJBDeVyoHKHYssPliCr7mL78VzpJfyKrGUOK6yXL295zDuuOoC5jUXP4GhE Un3C0qwAbTmdx2nloM8rG7xShXeYqaTu8pqCxPFRMjttXVpNbTcaMhShPgXo2EkRJe5c CHhpLJ6tpOXRAsGuwX9XkaddGVuVJDwqdncMbHuJMSStv9FmcSb/QE84H3tNpWA4BctO js1giMLfgmuFTKGyoQiZeVBa0S8OrfsLWrecdFeybG+SRlnVdRw0wf4o2iTm2As1x6nO 4LYg== X-Forwarded-Encrypted: i=1; AFNElJ87uo3Kk/fHG08v9HyhUCZx65gMS2gyQhXhrCkHMTJ1tnuQ4Ma7qqE6MYqhDuJtR+LRLSQ5lQKaIo22qkY=@vger.kernel.org X-Gm-Message-State: AOJu0YwAF8/x6kNrNxySlr2JgK5Phda+Ihcwtun6jtELM1cYI/Ibb/1L vMZweHQrsY7lg1b9k7611jsMhVpB5gar1bQtCTrYogCS3iCGy3/GDCVj X-Gm-Gg: Acq92OFV9yWmsr8aZphdi8cVTK2CGTGt9Rj9X1OnVqyiOR5xws85k/UPh6hNzqfB7rD heNCSRTEEwlFtDZlnZA7FmAd+WhNSbbj3h+lF38nQzPN8FiZ6l63S37lH4dAIKlRj/VYpqIo6p+ K2DzXHFtde6wZvxGGe938+SoMWMZuybKwbsaaZQUNdR5kHD6Dk66v5S+G2hfsRGwLMVcSyAqzA8 4gj3TfrcI5lioxTUabDOVmOlb5rdFi73sGzcoHQ3OhxcR0ZbJ58SxKLLx5dmViUU0icbG/U/kfn BXVITcrwQNz5VN/W6B9QHICC4CbDiTkiQoE/A/ofoFPG+5S6vCXmtcTWdF9FENcLP7v9lSx9TX5 4qrvH2S77p3bGlV4a2x+ZPjGBAXmAIHyhdprL8EgWeVwHuAhtptE7b0hdJOIzCczVXXevhP8mPh A5epl8mgvwSFrzHUQP5ZB5K9Kof2pg X-Received: by 2002:a17:902:d50e:b0:2b7:a1ff:b239 with SMTP id d9443c01a7336-2baf0d27e04mr160602415ad.14.1778554744436; Mon, 11 May 2026 19:59:04 -0700 (PDT) Received: from fedora ([2001:ee0:4fc8:5b0:526c:3adf:8a0d:13a8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1d27242sm129460145ad.9.2026.05.11.19.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 19:59:03 -0700 (PDT) From: Minh Nguyen To: Bryan Tan , Vishnu Dasa , Stefano Garzarella Cc: "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: [PATCH net v2] vsock/vmci: fix UAF when peer resets connection during handshake Date: Tue, 12 May 2026 09:58:51 +0700 Message-ID: <20260512025851.189140-1-minhnguyen.080505@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D pkt->type =3D=3D 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 =3D=3D 0) the socket stays on the pending list, so when vsock_pending_work() fires it takes the is_pending=3Dtrue 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 =3D=3D 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 =3D=3D 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=3Dy, 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 Acked-by: Bryan Tan Acked-by: Stefano Garzarella --- 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(-) 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 =3D skerr; pending->sk_state =3D 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 =3D=3D 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); =20 return err; } base-commit: be48e5fe51a5864566307998286a699d6b986934 --=20 2.54.0