From: Omar Sandoval <osandov@osandov.com>
To: Chris Mason <clm@fb.com>, Josef Bacik <jbacik@fb.com>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: orenl@cellrox.com
Subject: Re: [PATCH 1/2] btrfs: fix sparse address space warnings
Date: Sun, 28 Sep 2014 15:26:04 -0700 [thread overview]
Message-ID: <20140928222604.GA6328@molino.home.network> (raw)
In-Reply-To: <1411894092-28784-2-git-send-email-osandov@osandov.com>
On Sun, Sep 28, 2014 at 01:48:11AM -0700, Omar Sandoval wrote:
> diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
> index 6528aa6..e0be577 100644
> --- a/fs/btrfs/send.c
> +++ b/fs/btrfs/send.c
> @@ -515,7 +515,8 @@ static int write_buf(struct file *filp, const void *buf, u32 len, loff_t *off)
> set_fs(KERNEL_DS);
>
> while (pos < len) {
> - ret = vfs_write(filp, (char *)buf + pos, len - pos, off);
> + ret = vfs_write(filp, (__force const char __user *)buf + pos,
> + len - pos, off);
> /* TODO handle that correctly */
> /*if (ret == -ERESTARTSYS) {
> continue;
Actually, looking at this now, it looks like this is just an open-coded
kernel_write. I think this could be made a bit cleaner by using that instead;
the tradeoff is that each call to kernel_write will do the address space
flip-flop, so if the write gets split up into many calls, there'd be some
slight overhead. That's probably a microoptimization, but I think it's worth
looking into making kernel_read and kernel_write handle the retry logic.
It looks like Oren Laadan submitted a patch doing exactly that as part of the
checkpoint/restart patch series: https://lkml.org/lkml/2010/5/6/142. I've added
an email address that I found for him.
>From Josef's response way back in 2010:
> > +static ssize_t _kernel_write(struct file *file, loff_t offset,
> > + const char __user *ubuf, size_t count)
> > +{
> > + ssize_t nwrite;
> > + size_t nleft;
> > + loff_t pos = offset;
> > +
> > + for (nleft = count; nleft; nleft -= nwrite) {
> > + nwrite = vfs_write(file, ubuf, nleft, &pos);
> > + if (nwrite < 0) {
> > + if (nwrite == -EAGAIN) {
> > + nwrite = 0;
> > + continue;
> > + } else
> > + return nwrite;
> > + }
> > + ubuf += nwrite;
> > + }
> > + return count - nleft;
> > +}
>
> I'm not entirely sure if this can happen, but if vfs_write doesn't write
> anything, but doesn't have an error, we could end up in an infinite loop. Like
> I said I'm not sure if thats even possible, but its definitely one of those
> things that if it is possible some random security guy is going to figure out
> how to exploit it at some point down the line.
Did anyone ever come up with a good answer for this?
--
Omar
next prev parent reply other threads:[~2014-09-28 22:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-28 8:48 [PATCH 0/2] btrfs: fix several sparse warnings Omar Sandoval
2014-09-28 8:48 ` [PATCH 1/2] btrfs: fix sparse address space warnings Omar Sandoval
2014-09-28 22:26 ` Omar Sandoval [this message]
2014-09-30 19:27 ` Zach Brown
2014-09-30 20:32 ` Omar Sandoval
2014-09-29 16:07 ` David Sterba
2014-09-29 19:45 ` Omar Sandoval
2014-09-29 21:49 ` David Sterba
2014-09-28 8:48 ` [PATCH 2/2] btrfs: fix sparse lock context warnings Omar Sandoval
2014-09-29 16:10 ` David Sterba
2014-09-28 8:52 ` [PATCH 0/2] btrfs: fix several sparse warnings Omar Sandoval
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=20140928222604.GA6328@molino.home.network \
--to=osandov@osandov.com \
--cc=clm@fb.com \
--cc=jbacik@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=orenl@cellrox.com \
/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 NNTP newsgroup(s).