usb: musb: Fix musb_gadget.c rxstate overflow bug
authorRobin Guo <guoweibin@inspur.com>
Tue, 6 Sep 2022 02:21:19 +0000 (10:21 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 10:35:49 +0000 (12:35 +0200)
commit3c84c7f592c4ba38f54ddaddd0115acc443025db
treeb999e0953d12253476dc28c0473c5c5df559fa77
parentfcd594da0b5955119d9707e4e0a8d0fb1c969101
usb: musb: Fix musb_gadget.c rxstate overflow bug

[ Upstream commit eea4c860c3b366369eff0489d94ee4f0571d467d ]

The usb function device call musb_gadget_queue() adds the passed
request to musb_ep::req_list,If the (request->length > musb_ep->packet_sz)
and (is_buffer_mapped(req) return false),the rxstate() will copy all data
in fifo to request->buf which may cause request->buf out of bounds.

Fix it by add the length check :
fifocnt = min_t(unsigned, request->length - request->actual, fifocnt);

Signed-off-by: Robin Guo <guoweibin@inspur.com>
Link: https://lore.kernel.org/r/20220906102119.1b071d07a8391ff115e6d1ef@inspur.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/musb/musb_gadget.c