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

usb: typec: tps6598x: Remove VLA usage

In the quest to remove all stack VLA usage from the kernel[1], this
uses the maximum buffer size and adds a sanity check. While 25 bytes
is the size of the largest current things coming through, Heikki
Krogerus pointed out that the actual max in 64 bytes, as per ch 1.3.2
http://www.ti.com/lit/ug/slvuan1a/slvuan1a.pdf

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com

Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kees Cook and committed by
Greg Kroah-Hartman
8d361fa2 579b9cca

+10 -1
+10 -1
drivers/usb/typec/tps6598x.c
··· 81 81 struct typec_capability typec_cap; 82 82 }; 83 83 84 + /* 85 + * Max data bytes for Data1, Data2, and other registers. See ch 1.3.2: 86 + * http://www.ti.com/lit/ug/slvuan1a/slvuan1a.pdf 87 + */ 88 + #define TPS_MAX_LEN 64 89 + 84 90 static int 85 91 tps6598x_block_read(struct tps6598x *tps, u8 reg, void *val, size_t len) 86 92 { 87 - u8 data[len + 1]; 93 + u8 data[TPS_MAX_LEN + 1]; 88 94 int ret; 95 + 96 + if (WARN_ON(len + 1 > sizeof(data))) 97 + return -EINVAL; 89 98 90 99 if (!tps->i2c_protocol) 91 100 return regmap_raw_read(tps->regmap, reg, val, len);