public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <jens.axboe@oracle.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Li Zefan <lizf@cn.fujitsu.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	"Alan D. Brunelle" <alan.brunelle@hp.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Carl Henrik Lunde <chlunde@ping.uio.no>
Subject: Re: [PATCH] blktrace: fix a bug in blk_msg_write()
Date: Fri, 3 Apr 2009 15:03:16 +0200	[thread overview]
Message-ID: <20090403130316.GU5178@kernel.dk> (raw)
In-Reply-To: <20090403125956.GA25027@elte.hu>

On Fri, Apr 03 2009, Ingo Molnar wrote:
> 
> * Ingo Molnar <mingo@elte.hu> wrote:
> 
> > 
> > * Jens Axboe <jens.axboe@oracle.com> wrote:
> > 
> > > On Fri, Apr 03 2009, Ingo Molnar wrote:
> > > > 
> > > > * Li Zefan <lizf@cn.fujitsu.com> 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 <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);
> > > > 
> > > > Nice fix!
> > > > 
> > > > Jens, do you ack this and should i add a Cc: <stable@kernel.org>
> > > > backporting tag?
> > > > 
> > > > This fix applies fine to v2.6.29 after:
> > > > 
> > > >    sed 's/kernel\/trace\/blktrace.c/block\/blktrace.c'
> > > 
> > > This is identical to the following patch from Carl Henrik Lunde, which
> > > he just ported to -tip. It has existed before, as a patch to 2.6.29-git,
> > > but was unfortunately dropped.
> > > 
> > > So is this a coincidence? If not, Carl Henrik Lunde should be credited.
> > > 
> > > >From f116bce73e04d01614fd28ea678e0953cc321155 Mon Sep 17 00:00:00 2001
> > > From: Carl Henrik Lunde <chlunde@ping.uio.no>
> > > Date: Wed, 25 Mar 2009 14:23:16 +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 <chlunde@ping.uio.no>
> > 
> > Sure, i've picked up Carl's version of the fix instead, it dates 
> > back to early February!
> 
> I've also checked the linux-btrace archives a few months back and 
> nothing else seems to be missing - are you aware of any other 
> missing items?

Nope, I think Carls patch was the only pending thing I had from the
archives.

-- 
Jens Axboe


  reply	other threads:[~2009-04-03 13:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090403130316.GU5178@kernel.dk \
    --to=jens.axboe@oracle.com \
    --cc=acme@redhat.com \
    --cc=alan.brunelle@hp.com \
    --cc=chlunde@ping.uio.no \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox