NUL-terminate user space messages
PATCH 1/1 NUL-terminate user space messages
Could you consider something like this for inclusion?
Current behavior:
echo -n "test" > /sys/.../msg
result:
testnux
echo -n "111....111!" [128 characters, the last one !]:
result, "!" chopped of but no error message:
"111....111"
Signature · 2 lines
mvh Carl Henrik
From 1efe0c8202b808167fa4f701ac18cf4d6c799af9 Mon Sep 17 00:00:00 2001
From: Carl Henrik Lunde <[email protected]>
Date: Wed, 4 Feb 2009 14:28:53 +0100
Subject: [PATCH] blktrace: NUL-terminate user space messages
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 <[email protected]>
--- block/blktrace.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
block/blktrace.c +3 -2
@@ -255,10 +255,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 ;
@@ -267,6 +267,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);
Signature · 1 line
1.5.6.rc0.46.gd2b3