From: Alan Stern <stern@rowland.harvard.edu>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] usb: host: ehci-sched: Use struct_size() in kzalloc()
Date: Tue, 11 Jan 2022 13:19:04 -0500 [thread overview]
Message-ID: <Yd3KGMSb7vBIwH+j@rowland.harvard.edu> (raw)
In-Reply-To: <20220111075427.GA76390@embeddedor>
On Tue, Jan 11, 2022 at 01:54:27AM -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 worse scenario, could lead to heap overflows.
>
> Also, address the following sparse warning:
> drivers/usb/host/ehci-sched.c:1168:40: 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: Alan Stern <stern@rowland.harvard.edu>
> drivers/usb/host/ehci-sched.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
> index 0f85aa9b2fb1..bd542b6fc46b 100644
> --- a/drivers/usb/host/ehci-sched.c
> +++ b/drivers/usb/host/ehci-sched.c
> @@ -1165,10 +1165,8 @@ static struct ehci_iso_sched *
> iso_sched_alloc(unsigned packets, gfp_t mem_flags)
> {
> struct ehci_iso_sched *iso_sched;
> - int size = sizeof(*iso_sched);
>
> - size += packets * sizeof(struct ehci_iso_packet);
> - iso_sched = kzalloc(size, mem_flags);
> + iso_sched = kzalloc(struct_size(iso_sched, packet, packets), mem_flags);
> if (likely(iso_sched != NULL))
> INIT_LIST_HEAD(&iso_sched->td_list);
>
> --
> 2.27.0
>
prev parent reply other threads:[~2022-01-11 18:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-11 7:54 Gustavo A. R. Silva
2022-01-11 18:19 ` Alan Stern [this message]
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=Yd3KGMSb7vBIwH+j@rowland.harvard.edu \
--to=stern@rowland.harvard.edu \
--cc=gregkh@linuxfoundation.org \
--cc=gustavoars@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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®