ntb.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Jon Mason <jdmason@kudzu.us>
To: Serge Semin <fancer.lancer@gmail.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	Allen Hubbe <allenbh@gmail.com>,
	Dave Jiang <dave.jiang@intel.com>,
	ntb@lists.linux.dev, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] NTB: ntb_tool: uninitialized heap data in tool_fn_write()
Date: Fri, 12 Aug 2022 10:15:06 -0400	[thread overview]
Message-ID: <YvZgajV4lDVUyh3f@kudzu.us> (raw)
In-Reply-To: <20220728114417.hkhnv4lkqy6uzqq3@mobilestation>

On Thu, Jul 28, 2022 at 02:44:17PM +0300, Serge Semin wrote:
> On Wed, Jul 20, 2022 at 09:28:18PM +0300, Dan Carpenter wrote:
> > The call to:
> > 
> > 	ret = simple_write_to_buffer(buf, size, offp, ubuf, size);
> > 
> > will return success if it is able to write even one byte to "buf".
> > The value of "*offp" controls which byte.  This could result in
> > reading uninitialized data when we do the sscanf() on the next line.
> > 
> > This code is not really desigined to handle partial writes where
> > *offp is non-zero and the "buf" is preserved and re-used between writes.
> > Just ban partial writes and replace the simple_write_to_buffer() with
> > copy_from_user().
> > 
> > Fixes: 578b881ba9c4 ("NTB: Add tool test client")
> 
> Looks good. Thanks.
> Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
> 
> -Sergey

Sorry for the extremely long delay in response.  This series is in my
ntb branch and will be in my pull request for v5.20 which should be
going out later today.

Thanks,
Jon

> 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> >  drivers/ntb/test/ntb_tool.c | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
> > index b7bf3f863d79..5ee0afa621a9 100644
> > --- a/drivers/ntb/test/ntb_tool.c
> > +++ b/drivers/ntb/test/ntb_tool.c
> > @@ -367,14 +367,16 @@ static ssize_t tool_fn_write(struct tool_ctx *tc,
> >  	u64 bits;
> >  	int n;
> >  
> > +	if (*offp)
> > +		return 0;
> > +
> >  	buf = kmalloc(size + 1, GFP_KERNEL);
> >  	if (!buf)
> >  		return -ENOMEM;
> >  
> > -	ret = simple_write_to_buffer(buf, size, offp, ubuf, size);
> > -	if (ret < 0) {
> > +	if (copy_from_user(buf, ubuf, size)) {
> >  		kfree(buf);
> > -		return ret;
> > +		return -EFAULT;
> >  	}
> >  
> >  	buf[size] = 0;
> > -- 
> > 2.35.1
> > 
> > 

      reply	other threads:[~2022-08-12 14:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-20 18:28 [PATCH] NTB: ntb_tool: uninitialized heap data in tool_fn_write() Dan Carpenter
2022-07-28 11:44 ` Serge Semin
2022-08-12 14:15   ` Jon Mason [this message]

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=YvZgajV4lDVUyh3f@kudzu.us \
    --to=jdmason@kudzu.us \
    --cc=allenbh@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dave.jiang@intel.com \
    --cc=fancer.lancer@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=ntb@lists.linux.dev \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).