diff options
author | Gustavo A. R. Silva <gustavoars@kernel.org> | 2022-01-25 19:01:31 +0100 |
---|---|---|
committer | Wei Liu <wei.liu@kernel.org> | 2022-02-03 13:42:31 +0100 |
commit | a70d298c44592b95ae962e698c434f2b04e78805 (patch) | |
tree | dfd3bde551197392f32a9c887a693977f310cb34 /drivers/hv | |
parent | Linux 5.17-rc2 (diff) | |
download | linux-a70d298c44592b95ae962e698c434f2b04e78805.tar.xz linux-a70d298c44592b95ae962e698c434f2b04e78805.zip |
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>
Diffstat (limited to 'drivers/hv')
-rw-r--r-- | drivers/hv/vmbus_drv.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 17bf55fe3169..cd193456cd84 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -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; |