mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] vsock: only deliver taps to namespaces that can reach the device
@ 2026-11-16 23:46 Bobby Eshleman
  2026-11-16 23:52 ` netdev-bot+sinfo
  0 siblings, 1 reply; 3+ messages in thread
From: Bobby Eshleman @ 2026-11-16 23:46 UTC (permalink / raw)
  To: Stefan Hajnoczi, Stefano Garzarella, Michael S. Tsirkin,
	Jason Wang, Eugenio Pérez, Xuan Zhuo, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman
  Cc: kvm, virtualization, netdev, linux-kernel, Bobby Eshleman

vsock_deliver_tap() clones every packet to every vsockmon device on the
system. Creating one needs only CAP_NET_ADMIN in the owning user
namespace, so an unprivileged user can capture the traffic of local mode
namespaces.

Pass the packet's netns to vsock_deliver_tap() and only deliver to
devices that pass vsock_net_check_mode(), the same rule socket lookups
use. vhost passes the vhost_vsock netns, loopback the sending socket's
netns, and virtio-vsock NULL (global mode).

Fixes: a69686327e42 ("vsock: add netns support to virtio transports")
Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>
---
 drivers/vhost/vsock.c                   |  4 ++--
 include/linux/virtio_vsock.h            |  2 +-
 include/net/af_vsock.h                  |  3 ++-
 net/vmw_vsock/af_vsock_tap.c            | 10 +++++++---
 net/vmw_vsock/virtio_transport.c        |  4 ++--
 net/vmw_vsock/virtio_transport_common.c |  4 ++--
 net/vmw_vsock/vsock_loopback.c          |  2 +-
 7 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 88a310390eb0..3de1f1920717 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -229,7 +229,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
 		/* Deliver to monitoring devices all packets that we
 		 * will transmit.
 		 */
-		virtio_transport_deliver_tap_pkt(skb);
+		virtio_transport_deliver_tap_pkt(skb, vsock->net);
 
 		vhost_add_used(vq, head, sizeof(*hdr) + payload_len);
 		added = true;
@@ -567,7 +567,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
 		total_len += sizeof(*hdr) + skb->len;
 
 		/* Deliver to monitoring devices all received packets */
-		virtio_transport_deliver_tap_pkt(skb);
+		virtio_transport_deliver_tap_pkt(skb, vsock->net);
 
 		hdr = virtio_vsock_hdr(skb);
 
diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
index f91704731057..46058d354940 100644
--- a/include/linux/virtio_vsock.h
+++ b/include/linux/virtio_vsock.h
@@ -285,7 +285,7 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
 void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct sk_buff *skb);
 u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 wanted);
 void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit);
-void virtio_transport_deliver_tap_pkt(struct sk_buff *skb);
+void virtio_transport_deliver_tap_pkt(struct sk_buff *skb, struct net *net);
 int virtio_transport_purge_skbs(void *vsk, struct sk_buff_head *list);
 int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t read_actor);
 int virtio_transport_notify_set_rcvlowat(struct vsock_sock *vsk, int val);
diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h
index e8481f12312e..3e28865578eb 100644
--- a/include/net/af_vsock.h
+++ b/include/net/af_vsock.h
@@ -250,7 +250,8 @@ struct vsock_tap {
 
 int vsock_add_tap(struct vsock_tap *vt);
 int vsock_remove_tap(struct vsock_tap *vt);
-void vsock_deliver_tap(struct sk_buff *build_skb(void *opaque), void *opaque);
+void vsock_deliver_tap(struct sk_buff *build_skb(void *opaque), void *opaque,
+		       struct net *net);
 int __vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 				int flags);
 int vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
diff --git a/net/vmw_vsock/af_vsock_tap.c b/net/vmw_vsock/af_vsock_tap.c
index 7c5cdceabb2a..4c8821835251 100644
--- a/net/vmw_vsock/af_vsock_tap.c
+++ b/net/vmw_vsock/af_vsock_tap.c
@@ -73,19 +73,23 @@ static int __vsock_deliver_tap_skb(struct sk_buff *skb,
 	return ret;
 }
 
-static void __vsock_deliver_tap(struct sk_buff *skb)
+static void __vsock_deliver_tap(struct sk_buff *skb, struct net *net)
 {
 	int ret;
 	struct vsock_tap *tmp;
 
 	list_for_each_entry_rcu(tmp, &vsock_tap_all, list) {
+		if (!vsock_net_check_mode(dev_net(tmp->dev), net))
+			continue;
+
 		ret = __vsock_deliver_tap_skb(skb, tmp->dev);
 		if (unlikely(ret))
 			break;
 	}
 }
 
-void vsock_deliver_tap(struct sk_buff *build_skb(void *opaque), void *opaque)
+void vsock_deliver_tap(struct sk_buff *build_skb(void *opaque), void *opaque,
+		       struct net *net)
 {
 	struct sk_buff *skb;
 
@@ -96,7 +100,7 @@ void vsock_deliver_tap(struct sk_buff *build_skb(void *opaque), void *opaque)
 
 	skb = build_skb(opaque);
 	if (skb) {
-		__vsock_deliver_tap(skb);
+		__vsock_deliver_tap(skb, net);
 		consume_skb(skb);
 	}
 
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index cf63bc99f3cc..b39c001260a9 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -150,7 +150,7 @@ static int virtio_transport_send_skb(struct sk_buff *skb, struct virtqueue *vq,
 	if (ret < 0)
 		return ret;
 
-	virtio_transport_deliver_tap_pkt(skb);
+	virtio_transport_deliver_tap_pkt(skb, NULL);
 	return 0;
 }
 
@@ -680,7 +680,7 @@ static void virtio_transport_rx_work(struct work_struct *work)
 			if (payload_len)
 				virtio_vsock_skb_put(skb, payload_len);
 
-			virtio_transport_deliver_tap_pkt(skb);
+			virtio_transport_deliver_tap_pkt(skb, NULL);
 
 			/* Force virtio-transport into global mode since it
 			 * does not yet support local-mode namespacing.
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 1e762a480df4..027fe41c676a 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -190,12 +190,12 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque)
 	return skb;
 }
 
-void virtio_transport_deliver_tap_pkt(struct sk_buff *skb)
+void virtio_transport_deliver_tap_pkt(struct sk_buff *skb, struct net *net)
 {
 	if (virtio_vsock_skb_tap_delivered(skb))
 		return;
 
-	vsock_deliver_tap(virtio_transport_build_skb, skb);
+	vsock_deliver_tap(virtio_transport_build_skb, skb, net);
 	virtio_vsock_skb_set_tap_delivered(skb);
 }
 EXPORT_SYMBOL_GPL(virtio_transport_deliver_tap_pkt);
diff --git a/net/vmw_vsock/vsock_loopback.c b/net/vmw_vsock/vsock_loopback.c
index 8068d1b6e851..cacd313a454b 100644
--- a/net/vmw_vsock/vsock_loopback.c
+++ b/net/vmw_vsock/vsock_loopback.c
@@ -138,7 +138,7 @@ static void vsock_loopback_work(struct work_struct *work)
 		 * It is freed by the receiver.
 		 */
 		virtio_transport_consume_skb_sent(skb, false);
-		virtio_transport_deliver_tap_pkt(skb);
+		virtio_transport_deliver_tap_pkt(skb, sock_net(skb->sk));
 		virtio_transport_recv_pkt(&loopback_transport, skb,
 					  sock_net(skb->sk));
 	}

---
base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4
change-id: 20261116-vsock-tap-net-1b09a0945779

Best regards,
-- 
Bobby Eshleman <bobbyeshleman@meta.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] vsock: only deliver taps to namespaces that can reach the device
  2026-11-16 23:46 [PATCH net] vsock: only deliver taps to namespaces that can reach the device Bobby Eshleman
@ 2026-11-16 23:52 ` netdev-bot+sinfo
  2026-11-17  1:20   ` Bobby Eshleman
  0 siblings, 1 reply; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-16 23:52 UTC (permalink / raw)
  To: Bobby Eshleman
  Cc: Stefan Hajnoczi, Stefano Garzarella, Michael S. Tsirkin,
	Jason Wang, Eugenio Pérez, Xuan Zhuo, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, kvm,
	virtualization, netdev, linux-kernel

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] vsock: only deliver taps to namespaces that can reach the device
  2026-11-16 23:52 ` netdev-bot+sinfo
@ 2026-11-17  1:20   ` Bobby Eshleman
  0 siblings, 0 replies; 3+ messages in thread
From: Bobby Eshleman @ 2026-11-17  1:20 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: Stefan Hajnoczi, Stefano Garzarella, Michael S. Tsirkin,
	Jason Wang, Eugenio Pérez, Xuan Zhuo, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, kvm,
	virtualization, netdev, linux-kernel

On Mon, Nov 16, 2026 at 11:52:38PM +0000, netdev-bot+sinfo@kernel.org wrote:
> Hi!
> 
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
> 
>  - How the issue was discovered, e.g. hit in production, hit during
>    development, syzbot report, manual code inspection, LLM or static
>    analysis tool scan.
> 
>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by LLM and not proven at runtime). If it was triggered
>    please include the symptoms, like the stack trace or kernel messages.
> 
> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account.
> 
> *IMPORTANT*: If you do repost (for other reasons) - please include
> the relevant info in the cover letter or commit messages.
> -- 
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.

This is a known issue and has come up in review of the guest netns
series (so via code inspection).

Best,
Bobby

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-17  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 23:46 [PATCH net] vsock: only deliver taps to namespaces that can reach the device Bobby Eshleman
2026-11-16 23:52 ` netdev-bot+sinfo
2026-11-17  1:20   ` Bobby Eshleman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®