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

* Re: [PATCH] VSOCK: fix Integer Overflow in vmci_transport_recv_dgram_cb()
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Wang Liang @ 2025-08-05  7:07 UTC (permalink / raw)
  To: bsdhenrymartin, 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


在 2025/8/5 12:17, bsdhenrymartin@gmail.com 写道:
> 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;
> +


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

>   	size = VMCI_DG_SIZE(dg);
>   
>   	/* Attach the packet to the socket's receive queue as an sk_buff. */

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

* Re: [PATCH] VSOCK: fix Integer Overflow in vmci_transport_recv_dgram_cb()
  2025-08-05  7:07 ` Wang Liang
@ 2025-08-05  7:22   ` Stefano Garzarella
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Garzarella @ 2025-08-05  7:22 UTC (permalink / raw)
  To: Wang Liang
  Cc: bsdhenrymartin, huntazhang, jitxie, landonsun, bryan-bt.tan,
	vishnu.dasa, bcm-kernel-feedback-list, davem, edumazet, kuba,
	pabeni, horms, linux-kernel, virtualization, netdev, Henry Martin,
	TCS Robot

On Tue, Aug 05, 2025 at 03:07:38PM +0800, Wang Liang wrote:
>
>在 2025/8/5 12:17, bsdhenrymartin@gmail.com 写道:
>>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;
>>+
>
>
>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

>
>>  	size = VMCI_DG_SIZE(dg);
>>  	/* Attach the packet to the socket's receive queue as an sk_buff. */
>


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

* Re: [PATCH] VSOCK: fix Integer Overflow in vmci_transport_recv_dgram_cb()
  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-06 21:03 ` kernel test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-08-06 21:03 UTC (permalink / raw)
  To: bsdhenrymartin, huntazhang, jitxie, landonsun, bryan-bt.tan,
	vishnu.dasa, bcm-kernel-feedback-list, sgarzare, davem, edumazet,
	kuba, pabeni, horms
  Cc: oe-kbuild-all, linux-kernel, virtualization, netdev, Henry Martin,
	TCS Robot

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/202508070446.83Vp7qaK-lkp@intel.com/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/202508070446.83Vp7qaK-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508070446.83Vp7qaK-lkp@intel.com/

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  

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

^ permalink raw reply	[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).