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

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 <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: NXP Linux Team <linux-imx@nxp.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Shawn Guo <shawnguo@kernel.org>

+6 -1
+6 -1
drivers/bus/imx-weim.c
··· 45 45 .cs_stride = 0x18, 46 46 }; 47 47 48 + #define MAX_CS_REGS_COUNT 6 49 + 48 50 static const struct of_device_id weim_id_table[] = { 49 51 /* i.MX1/21 */ 50 52 { .compatible = "fsl,imx1-weim", .data = &imx1_weim_devtype, }, ··· 114 112 static int __init weim_timing_setup(struct device_node *np, void __iomem *base, 115 113 const struct imx_weim_devtype *devtype) 116 114 { 117 - u32 cs_idx, value[devtype->cs_regs_count]; 115 + u32 cs_idx, value[MAX_CS_REGS_COUNT]; 118 116 int i, ret; 117 + 118 + if (WARN_ON(devtype->cs_regs_count > MAX_CS_REGS_COUNT)) 119 + return -EINVAL; 119 120 120 121 /* get the CS index from this child node's "reg" property. */ 121 122 ret = of_property_read_u32(np, "reg", &cs_idx);