Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: host: ehci-sched: Use struct_size() in kzalloc()

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
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20220111075427.GA76390@embeddedor
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Gustavo A. R. Silva and committed by
Greg Kroah-Hartman
75c19f48 e783362e

+1 -3
+1 -3
drivers/usb/host/ehci-sched.c
··· 1165 1165 iso_sched_alloc(unsigned packets, gfp_t mem_flags) 1166 1166 { 1167 1167 struct ehci_iso_sched *iso_sched; 1168 - int size = sizeof(*iso_sched); 1169 1168 1170 - size += packets * sizeof(struct ehci_iso_packet); 1171 - iso_sched = kzalloc(size, mem_flags); 1169 + iso_sched = kzalloc(struct_size(iso_sched, packet, packets), mem_flags); 1172 1170 if (likely(iso_sched != NULL)) 1173 1171 INIT_LIST_HEAD(&iso_sched->td_list); 1174 1172