USB: gadget: u_f: add overflow checks to VLA macros
authorBrooke Basile <brookebasile@gmail.com>
Tue, 25 Aug 2020 13:05:08 +0000 (09:05 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Sep 2020 09:29:48 +0000 (11:29 +0200)
commit480e17846d321f922c22d1d6d418d270c3d89ba4
tree44e9237ba5c6fad718c249bc90d9bca0747b270b
parentec5c2663d533b583b31d2723ef87d70ab41494e9
USB: gadget: u_f: add overflow checks to VLA macros

commit b1cd1b65afba95971fa457dfdb2c941c60d38c5b upstream.

size can potentially hold an overflowed value if its assigned expression
is left unchecked, leading to a smaller than needed allocation when
vla_group_size() is used by callers to allocate memory.
To fix this, add a test for saturation before declaring variables and an
overflow check to (n) * sizeof(type).
If the expression results in overflow, vla_group_size() will return SIZE_MAX.

Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Brooke Basile <brookebasile@gmail.com>
Acked-by: Felipe Balbi <balbi@kernel.org>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/u_f.h