Skip to contentSkip to conversation

VSOCK: fix Information Leak in virtio_transport_shutdown()

PATCH In review [email protected] 4 participants 5 messages Aug 5, 2025

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VSOCK: fix Information Leak in virtio_transport_shutdown()

From: Henry Martin <[email protected]>

The struct virtio_vsock_pkt_info is declared on the stack but only partially initialized (only op, flags, and vsk are set)

The uninitialized fields (including pkt_len, remote_cid, remote_port, etc.) contain residual kernel stack data. This structure is passed to virtio_transport_send_pkt_info(), which uses the uninitialized fields.

Fixes 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")
---
 net/vmw_vsock/virtio_transport_common.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
net/vmw_vsock/virtio_transport_common.c +8 -8
index fe92e5fa95b4..cb391a98d025 100644
@@ -1073,14 +1073,14 @@ EXPORT_SYMBOL_GPL(virtio_transport_connect);
 
 int virtio_transport_shutdown(struct vsock_sock *vsk, int mode)
 {
-	struct virtio_vsock_pkt_info info = {
-		.op = VIRTIO_VSOCK_OP_SHUTDOWN,
-		.flags = (mode & RCV_SHUTDOWN ?
-			  VIRTIO_VSOCK_SHUTDOWN_RCV : 0) |
-			 (mode & SEND_SHUTDOWN ?
-			  VIRTIO_VSOCK_SHUTDOWN_SEND : 0),
-		.vsk = vsk,
-	};
+	struct virtio_vsock_pkt_info info = {0};
+
+	info.op = VIRTIO_VSOCK_OP_SHUTDOWN;
+	info.flags = (mode & RCV_SHUTDOWN ?
+			VIRTIO_VSOCK_SHUTDOWN_RCV : 0) |
+			(mode & SEND_SHUTDOWN ?
+			VIRTIO_VSOCK_SHUTDOWN_SEND : 0);
+	info.vsk = vsk;
 
 	return virtio_transport_send_pkt_info(vsk, &info);
 }
Signature · 1 line
2.41.3
#1 lore raw
Quoted 34 lines · 在 2025/8/5 13:10, [email protected] 写道:

From: Henry Martin <[email protected]>

The struct virtio_vsock_pkt_info is declared on the stack but only partially initialized (only op, flags, and vsk are set)

The uninitialized fields (including pkt_len, remote_cid, remote_port, etc.) contain residual kernel stack data. This structure is passed to virtio_transport_send_pkt_info(), which uses the uninitialized fields.

Fixes 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")
---
  net/vmw_vsock/virtio_transport_common.c | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
net/vmw_vsock/virtio_transport_common.c +1 -8
index fe92e5fa95b4..cb391a98d025 100644
@@ -1073,14 +1073,14 @@ EXPORT_SYMBOL_GPL(virtio_transport_connect);
 
  int virtio_transport_shutdown(struct vsock_sock *vsk, int mode)
  {
-	struct virtio_vsock_pkt_info info = {
-		.op = VIRTIO_VSOCK_OP_SHUTDOWN,
-		.flags = (mode & RCV_SHUTDOWN ?
-			  VIRTIO_VSOCK_SHUTDOWN_RCV : 0) |
-			 (mode & SEND_SHUTDOWN ?
-			  VIRTIO_VSOCK_SHUTDOWN_SEND : 0),
-		.vsk = vsk,
-	};
+	struct virtio_vsock_pkt_info info = {0};

net/vmw_vsock/virtio_transport_common.c EXPORT_SYMBOL_GPL(virtio_transport_connect); · line 1086

Quoted 10 lines
net/vmw_vsock/virtio_transport_common.c +7 -0
+
+	info.op = VIRTIO_VSOCK_OP_SHUTDOWN;
+	info.flags = (mode & RCV_SHUTDOWN ?
+			VIRTIO_VSOCK_SHUTDOWN_RCV : 0) |
+			(mode & SEND_SHUTDOWN ?
+			VIRTIO_VSOCK_SHUTDOWN_SEND : 0);
+	info.vsk = vsk;
 
  	return virtio_transport_send_pkt_info(vsk, &info);
  }

No. The unassigned members (including pkt_len, remote_cid, remote_port, etc.) will be automatically initialized to 0?

#2 lore raw
In reply to [email protected]
Quoted 23 lines · On Tue, Aug 05, 2025 at 01:10:09PM +0800, [email protected] wrote:

From: Henry Martin <[email protected]>

The struct virtio_vsock_pkt_info is declared on the stack but only partially initialized (only op, flags, and vsk are set)

The uninitialized fields (including pkt_len, remote_cid, remote_port, etc.) contain residual kernel stack data. This structure is passed to virtio_transport_send_pkt_info(), which uses the uninitialized fields.

Fixes 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")

---
net/vmw_vsock/virtio_transport_common.c | 15 +++++++--------

1 file changed, 7 insertions(+), 8 deletions(-)
net/vmw_vsock/virtio_transport_common.c +0 -0
index fe92e5fa95b4..cb391a98d025 100644
@@ -1073,14 +1073,14 @@ EXPORT_SYMBOL_GPL(virtio_transport_connect);
 

net/vmw_vsock/virtio_transport_common.c EXPORT_SYMBOL_GPL(virtio_transport_connect); · line 1083

Quoted 10 lines
net/vmw_vsock/virtio_transport_common.c +0 -8
 int virtio_transport_shutdown(struct vsock_sock *vsk, int mode)
 {
-	struct virtio_vsock_pkt_info info = {
-		.op = VIRTIO_VSOCK_OP_SHUTDOWN,
-		.flags = (mode & RCV_SHUTDOWN ?
-			  VIRTIO_VSOCK_SHUTDOWN_RCV : 0) |
-			 (mode & SEND_SHUTDOWN ?
-			  VIRTIO_VSOCK_SHUTDOWN_SEND : 0),
-		.vsk = vsk,
-	};

The compiler sets all other fields to 0, so I don't understand what this patch solves. Can you give an example of the problem you found?

Furthermore, even if this fix were valid, why do it for just one function?

Stefano

Quoted 14 lines
net/vmw_vsock/virtio_transport_common.c +8 -0
+	struct virtio_vsock_pkt_info info = {0};
+
+	info.op = VIRTIO_VSOCK_OP_SHUTDOWN;
+	info.flags = (mode & RCV_SHUTDOWN ?
+			VIRTIO_VSOCK_SHUTDOWN_RCV : 0) |
+			(mode & SEND_SHUTDOWN ?
+			VIRTIO_VSOCK_SHUTDOWN_SEND : 0);
+	info.vsk = vsk;
 
 	return virtio_transport_send_pkt_info(vsk, &info);
 }
Signature · 1 line
2.41.3
#3 lore raw

Thanks for the quick review. You're right—this patch is a false positive. Modern compilers zero out the remaining fields, so the fix isn't needed.

I'll be withdrawing all the patches and will ensure we more carefully evaluate our robot's findings before submitting in the future.

Thanks for your help!

Quoted 60 lines · Stefano Garzarella <[email protected]> 于2025年8月5日周二 15:01写道:
Quoted 23 lines · On Tue, Aug 05, 2025 at 01:10:09PM +0800, [email protected] wrote:

From: Henry Martin <[email protected]>

The struct virtio_vsock_pkt_info is declared on the stack but only partially initialized (only op, flags, and vsk are set)

The uninitialized fields (including pkt_len, remote_cid, remote_port, etc.) contain residual kernel stack data. This structure is passed to virtio_transport_send_pkt_info(), which uses the uninitialized fields.

Fixes 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")

---
net/vmw_vsock/virtio_transport_common.c | 15 +++++++--------

1 file changed, 7 insertions(+), 8 deletions(-)
net/vmw_vsock/virtio_transport_common.c +0 -0
index fe92e5fa95b4..cb391a98d025 100644
@@ -1073,14 +1073,14 @@ EXPORT_SYMBOL_GPL(virtio_transport_connect);
 

net/vmw_vsock/virtio_transport_common.c EXPORT_SYMBOL_GPL(virtio_transport_connect); · line 1083

Quoted 10 lines
net/vmw_vsock/virtio_transport_common.c +0 -8
 int virtio_transport_shutdown(struct vsock_sock *vsk, int mode)
 {
-      struct virtio_vsock_pkt_info info = {
-              .op = VIRTIO_VSOCK_OP_SHUTDOWN,
-              .flags = (mode & RCV_SHUTDOWN ?
-                        VIRTIO_VSOCK_SHUTDOWN_RCV : 0) |
-                       (mode & SEND_SHUTDOWN ?
-                        VIRTIO_VSOCK_SHUTDOWN_SEND : 0),
-              .vsk = vsk,
-      };

The compiler sets all other fields to 0, so I don't understand what this patch solves.
Can you give an example of the problem you found?

Furthermore, even if this fix were valid, why do it for just one function?

Stefano

Quoted 14 lines
net/vmw_vsock/virtio_transport_common.c +8 -1
+      struct virtio_vsock_pkt_info info = {0};
+
+      info.op = VIRTIO_VSOCK_OP_SHUTDOWN;
+      info.flags = (mode & RCV_SHUTDOWN ?
+                      VIRTIO_VSOCK_SHUTDOWN_RCV : 0) |
+                      (mode & SEND_SHUTDOWN ?
+                      VIRTIO_VSOCK_SHUTDOWN_SEND : 0);
+      info.vsk = vsk;
 
      return virtio_transport_send_pkt_info(vsk, &info);
 }
--

2.41.3