linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] VSOCK: fix Integer Overflow in vmci_transport_recv_dgram_cb()
@ 2025-08-05  4:17 bsdhenrymartin
  2025-08-05  7:07 ` Wang Liang
  2025-08-06 21:03 ` kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: bsdhenrymartin @ 2025-08-05  4:17 UTC (permalink / raw)
  To: huntazhang, jitxie, landonsun, bryan-bt.tan, vishnu.dasa,
	bcm-kernel-feedback-list, sgarzare, davem, edumazet, kuba, pabeni,
	horms
  Cc: linux-kernel, virtualization, netdev, Henry Martin, TCS Robot

From: Henry Martin <bsdhenryma@tencent.com>

The vulnerability is triggered when processing a malicious VMCI datagram
with an extremely large `payload_size` value. The attack path is:

1. Attacker crafts a malicious `vmci_datagram` with `payload_size` set
   to a value near `SIZE_MAX` (e.g., `SIZE_MAX - offsetof(struct
   vmci_datagram, payload) + 1`)
2. The function calculates: `size = VMCI_DG_SIZE(dg)` Where
   `VMCI_DG_SIZE(dg)` expands to `offsetof(struct vmci_datagram,
   payload) + dg->payload_size`
3. Integer overflow occurs during this addition, making `size` smaller
   than the actual datagram size

Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
Reported-by: TCS Robot <tcs_robot@tencent.com>
Signed-off-by: Henry Martin <bsdhenryma@tencent.com>
---
 net/vmw_vsock/vmci_transport.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c
index 7eccd6708d66..07079669dd09 100644
--- a/net/vmw_vsock/vmci_transport.c
+++ b/net/vmw_vsock/vmci_transport.c
@@ -630,6 +630,10 @@ static int vmci_transport_recv_dgram_cb(void *data, struct vmci_datagram *dg)
 	if (!vmci_transport_allow_dgram(vsk, dg->src.context))
 		return VMCI_ERROR_NO_ACCESS;
 
+	/* Validate payload size to prevent integer overflow */
+	if (dg->payload_size > SIZE_MAX - offsetof(struct vmci_datagram, payload))
+		return VMCI_ERROR_INVALID_ARGS;
+
 	size = VMCI_DG_SIZE(dg);
 
 	/* Attach the packet to the socket's receive queue as an sk_buff. */
-- 
2.41.3


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

end of thread, other threads:[~2025-08-06 21:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-05  4:17 [PATCH] VSOCK: fix Integer Overflow in vmci_transport_recv_dgram_cb() bsdhenrymartin
2025-08-05  7:07 ` Wang Liang
2025-08-05  7:22   ` Stefano Garzarella
2025-08-06 21:03 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).