public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blktrace: fix a bug in blk_msg_write()
@ 2009-04-03  7:31 Li Zefan
  2009-04-03 11:17 ` Ingo Molnar
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Li Zefan @ 2009-04-03  7:31 UTC (permalink / raw)
  To: Ingo Molnar, Jens Axboe; +Cc: Arnaldo Carvalho de Melo, Alan D. Brunelle, LKML

This is another long-standing bug.


================


 (console 1)
 # echo -n 'a' > /sys/kernel/debug/block/sda/msg
 (console 2)
 # blktrace -d /dev/sda -a pc -o - | blkparse -i -
  8,0    0        0     0.000000000     0  m   N a������@��

We should terminate the msg buffer with '\0'.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
 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 c0ef70d..2bf341f 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -327,10 +327,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)
 		return -EINVAL;
 
-	msg = kmalloc(count, GFP_KERNEL);
+	msg = kmalloc(count + 1, GFP_KERNEL);
 	if (msg == NULL)
 		return -ENOMEM;
 
@@ -338,6 +338,7 @@ static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,
 		kfree(msg);
 		return -EFAULT;
 	}
+	msg[count] = '\0';
 
 	bt = filp->private_data;
 	__trace_note_message(bt, "%s", msg);
-- 
1.5.4.rc3



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-04-08  9:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-03  7:31 [PATCH] blktrace: fix a bug in blk_msg_write() Li Zefan
2009-04-03 11:17 ` Ingo Molnar
2009-04-03 12:27   ` Jens Axboe
2009-04-03 12:51     ` [tip:tracing/blktrace-v2] blktrace: NUL-terminate user space messages Carl Henrik Lunde
2009-04-03 12:52     ` [PATCH] blktrace: fix a bug in blk_msg_write() Ingo Molnar
2009-04-03 12:59       ` Ingo Molnar
2009-04-03 13:03         ` Jens Axboe
2009-04-03 12:51 ` [tip:tracing/blktrace-v2] blktrace: small cleanup " Li Zefan
     [not found] ` <tip-48cefde3c17bbf37fee99e2889bcc718e5805dfa@git.kernel.org>
2009-04-08  1:32   ` [tip:tracing/blktrace-v2] blktrace: fix a bug " Li Zefan
2009-04-08  9:04     ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox