Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Drivers: hv: vmbus: Use struct_size() helper in kmalloc()

Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.

Also, address the following sparse warnings:
drivers/hv/vmbus_drv.c:1132:31: warning: using sizeof on a flexible structure

Link: https://github.com/KSPP/linux/issues/174
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20220125180131.GA67746@embeddedor
Signed-off-by: Wei Liu <wei.liu@kernel.org>

authored by

Gustavo A. R. Silva and committed by
Wei Liu
a70d298c 26291c54

+1 -1
+1 -1
drivers/hv/vmbus_drv.c
··· 1129 1129 } 1130 1130 1131 1131 if (entry->handler_type == VMHT_BLOCKING) { 1132 - ctx = kmalloc(sizeof(*ctx) + payload_size, GFP_ATOMIC); 1132 + ctx = kmalloc(struct_size(ctx, msg.payload, payload_size), GFP_ATOMIC); 1133 1133 if (ctx == NULL) 1134 1134 return; 1135 1135