Skip to contentSkip to conversation

drm/i2c: tda9950: Remove VLA usage

PATCH In review Kees Cook 1 participant 2 messages Jun 20, 2018 – Jul 17, 2018

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 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

---
 drivers/gpu/drm/i2c/tda9950.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i2c/tda9950.c +4 -1
index 3f7396caad48..28314433c351 100644
@@ -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)))
+		return -EINVAL;
+
 	buf[0] = addr;
 	memcpy(buf + 1, p, cnt);
 
Signature · 6 lines
2.17.1


-- 
Kees Cook
Pixel Security
author
#1 lore raw
Quoted 6 lines · Kees Cook

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

Friendly ping! Who's tree should this go through?

Thanks!

-Kees

Quoted 29 lines
---
 drivers/gpu/drm/i2c/tda9950.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i2c/tda9950.c +4 -2
index 3f7396caad48..28314433c351 100644
@@ -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)))
+               return -EINVAL;
+
        buf[0] = addr;
        memcpy(buf + 1, p, cnt);
 
--

2.17.1

--
Kees Cook
Pixel Security

Signature · 2 lines
Kees Cook
Pixel Security