Skip to contentSkip to conversation

platform/olpc: Reserve space for a string terminator

PATCH New Jiale Yao 1 participant 1 message Oct 3 x86 platform drivers

lore
Share & tools
lore

Jiale Yao

author
#0 lore raw

PATCH 1/1 platform/olpc: Reserve space for a string terminator

ec_dbgfs_cmd_write() copies user input into a zero-initialized stack buffer and passes it to sscanf(). A write that fills the entire buffer overwrites its only terminator, so the subsequent parsing can read beyond the buffer.

Limit the copy to leave room for the trailing NUL.

Fixes 6cca83d498bd ("Platform: OLPC: move debugfs support from x86 EC driver")
---
 drivers/platform/olpc/olpc-ec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/olpc/olpc-ec.c +1 -1
index 4a2d36f7331e..063f7e55c421 100644
@@ -269,7 +269,7 @@ static ssize_t ec_dbgfs_cmd_write(struct file *file, const char __user *buf,
 
 	mutex_lock(&ec_dbgfs_lock);
 
-	size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size);
+	size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf) - 1, ppos, buf, size);
 
 	m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0],
 			&ec_dbgfs_resp_bytes, &ec_cmd_int[1], &ec_cmd_int[2],
Signature · 1 line
2.34.1