* [PATCH][next] usb: xhci-mtk: Use struct_size() helper in create_sch_ep()
@ 2022-01-20 1:55 Gustavo A. R. Silva
2022-01-20 6:31 ` Chunfeng Yun
2022-01-24 9:26 ` AngeloGioacchino Del Regno
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2022-01-20 1:55 UTC (permalink / raw)
To: Mathias Nyman, Chunfeng Yun, Greg Kroah-Hartman, Matthias Brugger
Cc: linux-usb, linux-arm-kernel, linux-mediatek, 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/usb/host/xhci-mtk-sch.c:265:20: warning: using sizeof on a flexible structure
Link: https://github.com/KSPP/linux/issues/160
Link: https://github.com/KSPP/linux/issues/174
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/usb/host/xhci-mtk-sch.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
index edbfa82c6565..f3139ce7b0a9 100644
--- a/drivers/usb/host/xhci-mtk-sch.c
+++ b/drivers/usb/host/xhci-mtk-sch.c
@@ -248,7 +248,6 @@ create_sch_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev,
struct mu3h_sch_bw_info *bw_info;
struct mu3h_sch_tt *tt = NULL;
u32 len_bw_budget_table;
- size_t mem_size;
bw_info = get_bw_info(mtk, udev, ep);
if (!bw_info)
@@ -262,9 +261,9 @@ create_sch_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev,
else
len_bw_budget_table = 1;
- mem_size = sizeof(struct mu3h_sch_ep_info) +
- len_bw_budget_table * sizeof(u32);
- sch_ep = kzalloc(mem_size, GFP_KERNEL);
+ sch_ep = kzalloc(struct_size(sch_ep, bw_budget_table,
+ len_bw_budget_table),
+ GFP_KERNEL);
if (!sch_ep)
return ERR_PTR(-ENOMEM);
--
2.27.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] usb: xhci-mtk: Use struct_size() helper in create_sch_ep()
2022-01-20 1:55 [PATCH][next] usb: xhci-mtk: Use struct_size() helper in create_sch_ep() Gustavo A. R. Silva
@ 2022-01-20 6:31 ` Chunfeng Yun
2022-01-24 9:26 ` AngeloGioacchino Del Regno
1 sibling, 0 replies; 3+ messages in thread
From: Chunfeng Yun @ 2022-01-20 6:31 UTC (permalink / raw)
To: Gustavo A. R. Silva, Mathias Nyman, Greg Kroah-Hartman, Matthias Brugger
Cc: linux-usb, linux-arm-kernel, linux-mediatek, linux-kernel,
linux-hardening
On Wed, 2022-01-19 at 19:55 -0600, Gustavo A. R. Silva wrote:
> 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/usb/host/xhci-mtk-sch.c:265:20: warning: using sizeof on a
> flexible structure
>
> Link: https://github.com/KSPP/linux/issues/160
> Link: https://github.com/KSPP/linux/issues/174
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> drivers/usb/host/xhci-mtk-sch.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-
> mtk-sch.c
> index edbfa82c6565..f3139ce7b0a9 100644
> --- a/drivers/usb/host/xhci-mtk-sch.c
> +++ b/drivers/usb/host/xhci-mtk-sch.c
> @@ -248,7 +248,6 @@ create_sch_ep(struct xhci_hcd_mtk *mtk, struct
> usb_device *udev,
> struct mu3h_sch_bw_info *bw_info;
> struct mu3h_sch_tt *tt = NULL;
> u32 len_bw_budget_table;
> - size_t mem_size;
>
> bw_info = get_bw_info(mtk, udev, ep);
> if (!bw_info)
> @@ -262,9 +261,9 @@ create_sch_ep(struct xhci_hcd_mtk *mtk, struct
> usb_device *udev,
> else
> len_bw_budget_table = 1;
>
> - mem_size = sizeof(struct mu3h_sch_ep_info) +
> - len_bw_budget_table * sizeof(u32);
> - sch_ep = kzalloc(mem_size, GFP_KERNEL);
> + sch_ep = kzalloc(struct_size(sch_ep, bw_budget_table,
> + len_bw_budget_table),
> + GFP_KERNEL);
> if (!sch_ep)
> return ERR_PTR(-ENOMEM);
Acked-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Thanks a lot
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] usb: xhci-mtk: Use struct_size() helper in create_sch_ep()
2022-01-20 1:55 [PATCH][next] usb: xhci-mtk: Use struct_size() helper in create_sch_ep() Gustavo A. R. Silva
2022-01-20 6:31 ` Chunfeng Yun
@ 2022-01-24 9:26 ` AngeloGioacchino Del Regno
1 sibling, 0 replies; 3+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-01-24 9:26 UTC (permalink / raw)
To: Gustavo A. R. Silva, Mathias Nyman, Chunfeng Yun,
Greg Kroah-Hartman, Matthias Brugger
Cc: linux-usb, linux-arm-kernel, linux-mediatek, linux-kernel,
linux-hardening
Il 20/01/22 02:55, Gustavo A. R. Silva ha scritto:
> 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/usb/host/xhci-mtk-sch.c:265:20: warning: using sizeof on a flexible structure
>
> Link: https://github.com/KSPP/linux/issues/160
> Link: https://github.com/KSPP/linux/issues/174
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> Acked-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-24 9:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20 1:55 [PATCH][next] usb: xhci-mtk: Use struct_size() helper in create_sch_ep() Gustavo A. R. Silva
2022-01-20 6:31 ` Chunfeng Yun
2022-01-24 9:26 ` AngeloGioacchino Del Regno
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).