[PATCH] blktrace: NUL-terminate user space messages

From: Carl Henrik Lunde
Date: Wed Mar 25 2009 - 09:23:16 EST


Make sure messages from user space are NUL-terminated strings,
otherwise we could dump random memory to the block trace file.
Additionally, I've limited the message to BLK_TN_MAX_MSG-1 characters,
because the last character would be stripped by vscnprintf anyway.

Signed-off-by: Carl Henrik Lunde <chlunde@xxxxxxxxxxx>
---
kernel/trace/blktrace.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index d43cdac..75eb345 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -311,10 +311,10 @@ static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,
char *msg;
struct blk_trace *bt;

- if (count > BLK_TN_MAX_MSG)
+ if (count > BLK_TN_MAX_MSG - 1)
return -EINVAL;

- msg = kmalloc(count, GFP_KERNEL);
+ msg = kmalloc(count + 1, GFP_KERNEL);
if (msg == NULL)
return -ENOMEM;

@@ -323,6 +323,7 @@ static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,
return -EFAULT;
}

+ msg[count] = '\0';
bt = filp->private_data;
__trace_note_message(bt, "%s", msg);
kfree(msg);
--
1.6.2.rc0.90.g0753

>
> Ingo

--
Jens Axboe

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/