Skip to content

Commit

Permalink
Drivers: hv: vmbus: Use struct_size() helper in kmalloc()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Michael Kelley <[email protected]>
Link: https://lore.kernel.org/r/20220125180131.GA67746@embeddedor
Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
GustavoARSilva authored and liuw committed Feb 3, 2022
1 parent 26291c5 commit a70d298
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/hv/vmbus_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ void vmbus_on_msg_dpc(unsigned long data)
}

if (entry->handler_type == VMHT_BLOCKING) {
ctx = kmalloc(sizeof(*ctx) + payload_size, GFP_ATOMIC);
ctx = kmalloc(struct_size(ctx, msg.payload, payload_size), GFP_ATOMIC);
if (ctx == NULL)
return;

Expand Down

0 comments on commit a70d298

Please sign in to comment.