* [PATCH][next] Drivers: hv: vmbus: Use struct_size() helper in kmalloc()
@ 2022-01-25 18:01 Gustavo A. R. Silva
2022-01-27 16:01 ` Michael Kelley (LINUX)
0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2022-01-25 18:01 UTC (permalink / raw)
To: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu, Dexuan Cui
Cc: linux-hyperv, linux-kernel, Gustavo A. R. Silva, linux-hardening
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>
---
drivers/hv/vmbus_drv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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;
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH][next] Drivers: hv: vmbus: Use struct_size() helper in kmalloc()
2022-01-25 18:01 [PATCH][next] Drivers: hv: vmbus: Use struct_size() helper in kmalloc() Gustavo A. R. Silva
@ 2022-01-27 16:01 ` Michael Kelley (LINUX)
2022-02-03 12:42 ` Wei Liu
0 siblings, 1 reply; 3+ messages in thread
From: Michael Kelley (LINUX) @ 2022-01-27 16:01 UTC (permalink / raw)
To: Gustavo A. R. Silva, KY Srinivasan, Haiyang Zhang,
Stephen Hemminger, Wei Liu, Dexuan Cui
Cc: linux-hyperv, linux-kernel, linux-hardening
From: Gustavo A. R. Silva <gustavoars@kernel.org> Sent: Tuesday, January 25, 2022 10:02 AM
>
> 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
> ---
> drivers/hv/vmbus_drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> 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;
>
> --
> 2.27.0
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] Drivers: hv: vmbus: Use struct_size() helper in kmalloc()
2022-01-27 16:01 ` Michael Kelley (LINUX)
@ 2022-02-03 12:42 ` Wei Liu
0 siblings, 0 replies; 3+ messages in thread
From: Wei Liu @ 2022-02-03 12:42 UTC (permalink / raw)
To: Michael Kelley (LINUX)
Cc: Gustavo A. R. Silva, KY Srinivasan, Haiyang Zhang,
Stephen Hemminger, Wei Liu, Dexuan Cui, linux-hyperv,
linux-kernel, linux-hardening
On Thu, Jan 27, 2022 at 04:01:28PM +0000, Michael Kelley (LINUX) wrote:
> From: Gustavo A. R. Silva <gustavoars@kernel.org> Sent: Tuesday, January 25, 2022 10:02 AM
> >
> > 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
> > ---
> > drivers/hv/vmbus_drv.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > 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;
> >
> > --
> > 2.27.0
>
> Reviewed-by: Michael Kelley <mikelley@microsoft.com>
>
Applied to hyperv-next. Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-03 12:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-25 18:01 [PATCH][next] Drivers: hv: vmbus: Use struct_size() helper in kmalloc() Gustavo A. R. Silva
2022-01-27 16:01 ` Michael Kelley (LINUX)
2022-02-03 12:42 ` Wei Liu
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).