From: Chunfeng Yun <chunfeng.yun@mediatek.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
Mathias Nyman <mathias.nyman@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Matthias Brugger <matthias.bgg@gmail.com>
Cc: <linux-usb@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <linux-hardening@vger.kernel.org>
Subject: Re: [PATCH][next] usb: xhci-mtk: Use struct_size() helper in create_sch_ep()
Date: Thu, 20 Jan 2022 14:31:55 +0800 [thread overview]
Message-ID: <b7d0e7572ce7f7958f579ac564d25cbfee497cdc.camel@mediatek.com> (raw)
In-Reply-To: <20220120015546.GA75917@embeddedor>
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
>
next prev parent reply other threads:[~2022-01-20 6:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-20 1:55 Gustavo A. R. Silva
2022-01-20 6:31 ` Chunfeng Yun [this message]
2022-01-24 9:26 ` AngeloGioacchino Del Regno
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b7d0e7572ce7f7958f579ac564d25cbfee497cdc.camel@mediatek.com \
--to=chunfeng.yun@mediatek.com \
--cc=gregkh@linuxfoundation.org \
--cc=gustavoars@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=matthias.bgg@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®