From: Stefano Garzarella <sgarzare@redhat.com>
To: "Bartłomiej Dmitruk" <bartlomiej.dmitruk@isec.pl>
Cc: Bryan Tan <bryan-bt.tan@broadcom.com>,
Vishnu Dasa <vishnu.dasa@broadcom.com>,
pv-drivers.linux@broadcom.com, netdev@vger.kernel.org,
virtualization@lists.linux.dev,
"Michael S . Tsirkin" <mst@redhat.com>,
bobbyeshleman@meta.com
Subject: Re: [PATCH] vsock/vmci: harden datagram receive access check (netns bypass + cached_peer race)
Date: Fri, 18 Sep 2026 14:45:02 +0200 [thread overview]
Message-ID: <aq0xcAKg1snndtdX@sgarzare-redhat> (raw)
In-Reply-To: <20260917220225.56200-1-bartlomiej.dmitruk@isec.pl>
On Fri, Sep 18, 2026 at 12:02:24AM +0200, Bartłomiej Dmitruk wrote:
>vmci_transport_allow_dgram() gates delivery of incoming VMCI datagrams. It
>has two problems, both in this one function, fixed together here.
>
>1. Namespace bypass: the send hook vmci_transport_dgram_allow() refuses
> datagrams when the socket's netns is not in global mode
> (vsock_net_mode_global()), but the receive path never checks it. A socket
> bound in a non-global (local) netns therefore receives datagrams from
> peers it could never send to, defeating namespace isolation.
Is the VMCI transport supporting namespaces? (CCing Bobby)
>
>2. Data race / stale ACL: the decision was cached in vsock->cached_peer and
> vsock->cached_peer_allow_dgram with an unsynchronized check-then-set.
> The function is called both from the lockless receive tasklet
> (vmci_transport_recv_dgram_cb(), no socket lock) and from the lock_sock()
> send path; lock_sock() does not exclude bottom halves, so the two contexts
> race on those fields. An interleave can return a stale 'allow' for a
> VMCI_PRIVILEGE_FLAG_RESTRICTED peer (and it is a plain data race
> regardless). The in-code comment claiming the fields are never modified
> outside create/destruct is contradicted by the send path.
2 issues -> 2 fixes, no?
In this case mainly to backport them properly, since for example we
added namespace support only recently.
Please also add the right Fixes tag and all maintainers in CC.
Stefano
>
>Add the symmetric net-mode check and drop the cache, evaluating the decision
>on every datagram; there is no shared mutable state left to race. The now
>unused cached_peer{,_allow_dgram} members can be removed in a follow-up.
>
>Signed-off-by: Bartłomiej Dmitruk <bartlomiej.dmitruk@isec.pl>
>---
>diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c
>--- a/net/vmw_vsock/vmci_transport.c
>+++ b/net/vmw_vsock/vmci_transport.c
>@@ -529,18 +529,25 @@
> if (VMADDR_CID_HYPERVISOR == peer_cid)
> return true;
>
>- if (vsock->cached_peer != peer_cid) {
>- vsock->cached_peer = peer_cid;
>- if (!vmci_transport_is_trusted(vsock, peer_cid) &&
>- (vmci_context_get_priv_flags(peer_cid) &
>- VMCI_PRIVILEGE_FLAG_RESTRICTED)) {
>- vsock->cached_peer_allow_dgram = false;
>- } else {
>- vsock->cached_peer_allow_dgram = true;
>- }
>- }
>+ /* Enforce the per-netns mode on the receive path, symmetrically with
>+ * the send hook vmci_transport_dgram_allow(): a socket in a non-global
>+ * (local) netns must not receive datagrams it could never send.
>+ */
>+ if (!vsock_net_mode_global(vsock))
>+ return false;
>
>- return vsock->cached_peer_allow_dgram;
>+ /* Evaluate on every datagram instead of caching the decision in
>+ * vsock->cached_peer{,_allow_dgram}: those fields were an
>+ * unsynchronized check-then-set shared between the lockless receive
>+ * tasklet and the lock_sock() send path, which could return a stale
>+ * 'allow' for a restricted peer.
>+ */
>+ if (!vmci_transport_is_trusted(vsock, peer_cid) &&
>+ (vmci_context_get_priv_flags(peer_cid) &
>+ VMCI_PRIVILEGE_FLAG_RESTRICTED))
>+ return false;
>+
>+ return true;
> }
>
> static int
>
next prev parent reply other threads:[~2026-09-18 12:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 22:02 [PATCH] vsock/vmci: harden datagram receive access check (netns bypass + cached_peer race) Bartłomiej Dmitruk
2026-09-18 12:05 ` Vishnu Dasa
2026-09-18 12:45 ` Stefano Garzarella [this message]
2026-09-18 22:02 ` sashiko-bot
2026-09-21 23:30 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aq0xcAKg1snndtdX@sgarzare-redhat \
--to=sgarzare@redhat.com \
--cc=bartlomiej.dmitruk@isec.pl \
--cc=bobbyeshleman@meta.com \
--cc=bryan-bt.tan@broadcom.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pv-drivers.linux@broadcom.com \
--cc=virtualization@lists.linux.dev \
--cc=vishnu.dasa@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox