VSOCK: fix Integer Overflow in vmci_transport_recv_dgram_cb()
Subsystems (5)
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
--- net/vmw_vsock/vmci_transport.c | 4 ++++ 1 file changed, 4 insertions(+)
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 ; + size =VMCI_DG_SIZE (dg);/* Attach the packet to the socket's receive queue as an sk_buff. */
Signature · 1 line
2.41.3
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_sizevalue. The attack path is:1. Attacker crafts a malicious
vmci_datagramwithpayload_sizeset to a value nearSIZE_MAX(e.g.,SIZE_MAX - offsetof(struct vmci_datagram, payload) + 1)
2. The function calculates:size = VMCI_DG_SIZE(dg)WhereVMCI_DG_SIZE(dg)expands tooffsetof(struct vmci_datagram, payload) + dg->payload_size
3. Integer overflow occurs during this addition, makingsizesmaller than the actual datagram sizeFixes d021c344051a ("VSOCK: Introduce VM Sockets")Reported-by TCS Robot <[email protected]>Signed-off-by Henry Martin <[email protected]>--- net/vmw_vsock/vmci_transport.c | 4 ++++ 1 file changed, 4 insertions(+)net/vmw_vsock/vmci_transport.c +0
-0
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
-0size =VMCI_DG_SIZE (dg);/* Attach the packet to the socket's receive queue as an sk_buff. */
Stefano Garzarella
maintainerQuoted 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_sizevalue. The attack path is:1. Attacker crafts a malicious
vmci_datagramwithpayload_sizeset to a value nearSIZE_MAX(e.g.,SIZE_MAX - offsetof(struct vmci_datagram, payload) + 1)
2. The function calculates:size = VMCI_DG_SIZE(dg)WhereVMCI_DG_SIZE(dg)expands tooffsetof(struct vmci_datagram, payload) + dg->payload_size
3. Integer overflow occurs during this addition, makingsizesmaller than the actual datagram sizeFixes d021c344051a ("VSOCK: Introduce VM Sockets")Reported-by TCS Robot <[email protected]>Signed-off-by Henry Martin <[email protected]>--- 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@@ -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_datagramhas 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
-0size =VMCI_DG_SIZE (dg);/* Attach the packet to the socket's receive queue as an sk_buff. */
kernel test robot
build botkernel 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 offsetof14e83077d55ff4 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