platform/olpc: Reserve space for a string terminator
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")
Signed-off-by Jiale Yao <[email protected]>
--- drivers/platform/olpc/olpc-ec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/olpc/olpc-ec.c +1 -1
@@ -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