Skip to contentSkip to conversation

VSOCK: fix Integer Overflow in vmci_transport_recv_dgram_cb()

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

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

PATCH 1/1 VSOCK: fix Integer Overflow in vmci_transport_recv_dgram_cb()

From: Henry Martin <[email protected]>

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")
---
 net/vmw_vsock/vmci_transport.c | 4 ++++
 1 file changed, 4 insertions(+)
net/vmw_vsock/vmci_transport.c +4 -0
index 7eccd6708d66..07079669dd09 100644
@@ -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. */
Signature · 1 line
2.41.3
#1 lore raw
Quoted 26 lines · 在 2025/8/5 12:17, [email protected] 写道:

From: Henry Martin <[email protected]>

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")
---
  net/vmw_vsock/vmci_transport.c | 4 ++++
  1 file changed, 4 insertions(+)
net/vmw_vsock/vmci_transport.c +0 -0
index 7eccd6708d66..07079669dd09 100644

net/vmw_vsock/vmci_transport.c static int vmci_transport_recv_dgram_cb(void *data, struct vmci_datagram *dg) · line 636

Quoted 7 lines
net/vmw_vsock/vmci_transport.c +4 -0
@@ -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;
+

The struct vmci_datagram has no member 'payload'. Your patch may trigger compile error.

Quoted 3 lines
net/vmw_vsock/vmci_transport.c +0 -0
  	size = VMCI_DG_SIZE(dg);
 
  	/* Attach the packet to the socket's receive queue as an sk_buff. */
#2 lore raw
Quoted 23 lines · Wang Liang
Quoted 21 lines · 在 2025/8/5 12:17, [email protected] 写道:

From: Henry Martin <[email protected]>

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")
---
 net/vmw_vsock/vmci_transport.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 14 lines

net/vmw_vsock/vmci_transport.c static int vmci_transport_recv_dgram_cb(void *data, struct vmci_datagram *dg) · line 635

Quoted 11 lines
net/vmw_vsock/vmci_transport.c +4 -0
index 7eccd6708d66..07079669dd09 100644
@@ -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;
+

The struct vmci_datagram has no member 'payload'. Your patch may trigger compile error.

@Wang thanks for the highlight!

mmm, so this is the 3rd no-sense patch from the same author!

Last advice for the author, please fix your bot and try your patches before submitting it!

Stefano

Quoted 4 lines
Quoted 3 lines
net/vmw_vsock/vmci_transport.c +0 -0
 	size = VMCI_DG_SIZE(dg);
 	/* Attach the packet to the socket's receive queue as an sk_buff. */
#3 lore raw
In reply to [email protected]
kernel test robot noticed the following build errors:

Hi,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]
[also build test ERROR on net/main linus/master v6.16 next-20250806] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/bsdhenrymartin-gmail-com/VSOCK-fix-Integer-Overflow-in-vmci_transport_recv_dgram_cb/20250806-105210
base:   net-next/main
patch link:    https://lore.kernel.org/r/20250805041748.1728098-1-tcs_kernel%40tencent.com
patch subject: [PATCH] VSOCK: fix Integer Overflow in vmci_transport_recv_dgram_cb()
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20250807/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250807/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14,
from include/linux/types.h:6,
from net/vmw_vsock/vmci_transport.c:8:
net/vmw_vsock/vmci_transport.c: In function 'vmci_transport_recv_dgram_cb':

>> include/linux/stddef.h:16:33: error: 'struct vmci_datagram' has no member named 'payload'
      16 | #define offsetof(TYPE, MEMBER)  __builtin_offsetof(TYPE, MEMBER)
         |                                 ^~~~~~~~~~~~~~~~~~
   net/vmw_vsock/vmci_transport.c:634:43: note: in expansion of macro 'offsetof'
     634 |         if (dg->payload_size > SIZE_MAX - offsetof(struct vmci_datagram, payload))
         |                                           ^~~~~~~~

--
In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14, from include/linux/types.h:6,
from vmci_transport.c:8:
vmci_transport.c: In function 'vmci_transport_recv_dgram_cb':

>> include/linux/stddef.h:16:33: error: 'struct vmci_datagram' has no member named 'payload'
      16 | #define offsetof(TYPE, MEMBER)  __builtin_offsetof(TYPE, MEMBER)
         |                                 ^~~~~~~~~~~~~~~~~~
   vmci_transport.c:634:43: note: in expansion of macro 'offsetof'
     634 |         if (dg->payload_size > SIZE_MAX - offsetof(struct vmci_datagram, payload))
         |                                           ^~~~~~~~

vim +16 include/linux/stddef.h

6e218287432472 Richard Knutsson 2006-09-30 14
^1da177e4c3f41 Linus Torvalds 2005-04-16 15 #undef offsetof
14e83077d55ff4 Rasmus Villemoes 2022-03-23 @16 #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
3876488444e712 Denys Vlasenko 2015-03-09 17

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki