]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
usb: gadget: f_fs: stricter integer overflow checks
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 1 Sep 2022 14:59:42 +0000 (17:59 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Oct 2022 07:57:52 +0000 (09:57 +0200)
commit0cb8d0d420d464b8ad8685357e57784887243b35
tree5a231621e543fe8bf09146bd62fdcb1ad906ed78
parentd4a8ec5cc7ff5d442bd49a44f26d74b2021ba4c8
usb: gadget: f_fs: stricter integer overflow checks

[ Upstream commit f57004b9d96755cd6a243b51c267be4016b4563c ]

This from static analysis.  The vla_item() takes a size and adds it to
the total.  It has a built in integer overflow check so if it encounters
an integer overflow anywhere then it records the total as SIZE_MAX.

However there is an issue here because the "lang_count*(needed_count+1)"
multiplication can overflow.  Technically the "lang_count + 1" addition
could overflow too, but that would be detected and is harmless.  Fix
both using the new size_add() and size_mul() functions.

Fixes: e6f3862fa1ec ("usb: gadget: FunctionFS: Remove VLAIS usage from gadget code")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/YxDI3lMYomE7WCjn@kili
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/gadget/function/f_fs.c