Skip to content

Commit a70d298

Browse files
GustavoARSilvaliuw
authored andcommitted
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: KSPP#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>
1 parent 26291c5 commit a70d298

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/hv/vmbus_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ void vmbus_on_msg_dpc(unsigned long data)
11291129
}
11301130

11311131
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);
11331133
if (ctx == NULL)
11341134
return;
11351135

0 commit comments

Comments
 (0)