Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764069AbZDCLSW (ORCPT ); Fri, 3 Apr 2009 07:18:22 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1760357AbZDCLSI (ORCPT ); Fri, 3 Apr 2009 07:18:08 -0400 Received: from mx3.mail.elte.hu ([157.181.1.138]:50106 "EHLO mx3.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759962AbZDCLSH (ORCPT ); Fri, 3 Apr 2009 07:18:07 -0400 Date: Fri, 3 Apr 2009 13:17:41 +0200 From: Ingo Molnar To: Li Zefan Cc: Jens Axboe , Arnaldo Carvalho de Melo , "Alan D. Brunelle" , LKML , Steven Rostedt Subject: Re: [PATCH] blktrace: fix a bug in blk_msg_write() Message-ID: <20090403111741.GB31399@elte.hu> References: <49D5BB56.7000807@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <49D5BB56.7000807@cn.fujitsu.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-ELTE-VirusStatus: clean X-ELTE-SpamScore: -1.5 X-ELTE-SpamLevel: X-ELTE-SpamCheck: no X-ELTE-SpamVersion: ELTE 2.0 X-ELTE-SpamCheck-Details: score=-1.5 required=5.9 tests=BAYES_00 autolearn=no SpamAssassin version=3.2.3 -1.5 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1725 Lines: 62 * Li Zefan wrote: > 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 > --- > 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); Nice fix! Jens, do you ack this and should i add a Cc: backporting tag? This fix applies fine to v2.6.29 after: sed 's/kernel\/trace\/blktrace.c/block\/blktrace.c' Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/