From 699112f5e831c088ff6aeea594d23ebecf6bd806 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 19 Jun 2018 21:38:31 -0700 Subject: drm/i2c: tda9950: Remove VLA usage In the quest to remove all stack VLA usage from the kernel[1], this sets the buffer to maximum size and adds a sanity check. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Cc: David Airlie Cc: Hans Verkuil Cc: Russell King Cc: dri-devel@lists.freedesktop.org Signed-off-by: Kees Cook --- drivers/gpu/drm/i2c/tda9950.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/gpu/drm/i2c/tda9950.c b/drivers/gpu/drm/i2c/tda9950.c index 3f7396caad48..5d2f0d548469 100644 --- a/drivers/gpu/drm/i2c/tda9950.c +++ b/drivers/gpu/drm/i2c/tda9950.c @@ -76,9 +76,12 @@ struct tda9950_priv { static int tda9950_write_range(struct i2c_client *client, u8 addr, u8 *p, int cnt) { struct i2c_msg msg; - u8 buf[cnt + 1]; + u8 buf[CEC_MAX_MSG_SIZE + 3]; int ret; + if (WARN_ON(cnt > sizeof(buf) - 1)) + return -EINVAL; + buf[0] = addr; memcpy(buf + 1, p, cnt); -- cgit v1.2.3 From d8dfa59f5a512a536b80a4a8f12fa993683f48df Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Thu, 28 Jun 2018 17:04:21 -0700 Subject: bus: imx-weim: Remove VLA usage In the quest to remove all stack VLA usage from the kernel[1], this switches to using a maximum size and adds a sanity check. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Cc: Shawn Guo Cc: Sascha Hauer Cc: Pengutronix Kernel Team Cc: Fabio Estevam Cc: NXP Linux Team Signed-off-by: Kees Cook Reviewed-by: Arnd Bergmann Acked-by: Shawn Guo --- drivers/bus/imx-weim.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c index 3d56ebcda720..6a94aa6a22c2 100644 --- a/drivers/bus/imx-weim.c +++ b/drivers/bus/imx-weim.c @@ -45,6 +45,8 @@ static const struct imx_weim_devtype imx51_weim_devtype = { .cs_stride = 0x18, }; +#define MAX_CS_REGS_COUNT 6 + static const struct of_device_id weim_id_table[] = { /* i.MX1/21 */ { .compatible = "fsl,imx1-weim", .data = &imx1_weim_devtype, }, @@ -112,9 +114,12 @@ err: static int __init weim_timing_setup(struct device_node *np, void __iomem *base, const struct imx_weim_devtype *devtype) { - u32 cs_idx, value[devtype->cs_regs_count]; + u32 cs_idx, value[MAX_CS_REGS_COUNT]; int i, ret; + if (WARN_ON(devtype->cs_regs_count > MAX_CS_REGS_COUNT)) + return -EINVAL; + /* get the CS index from this child node's "reg" property. */ ret = of_property_read_u32(np, "reg", &cs_idx); if (ret) -- cgit v1.2.3