From: Al Viro <viro@ZenIV.linux.org.uk>
To: Sasha Levin <sasha.levin@oracle.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>,
willy@linux.intel.com, Chuck Ebbert <cebbert.lkml@gmail.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: fs: out of bounds on stack in iov_iter_advance
Date: Fri, 6 Nov 2015 01:34:02 +0000 [thread overview]
Message-ID: <20151106013402.GT22011@ZenIV.linux.org.uk> (raw)
In-Reply-To: <560C5469.5010704@oracle.com>
On Wed, Sep 30, 2015 at 05:30:17PM -0400, Sasha Levin wrote:
> > So I've traced this all the way back to dax_io(). I can trigger this with:
> >
> > diff --git a/fs/dax.c b/fs/dax.c
> > index 93bf2f9..2cdb8a5 100644
> > --- a/fs/dax.c
> > +++ b/fs/dax.c
> > @@ -178,6 +178,7 @@ static ssize_t dax_io(struct inode *inode, struct iov_iter *iter,
> > if (need_wmb)
> > wmb_pmem();
> >
> > + WARN_ON((pos == start) && (pos - start > iov_iter_count(iter)));
> > return (pos == start) ? retval : pos - start;
> > }
> >
> > So it seems that iter gets moved twice here: once in dax_io(), and once again
> > back at generic_file_read_iter().
> >
> > I don't see how it ever worked. Am I missing something?
This:
struct iov_iter data = *iter;
retval = mapping->a_ops->direct_IO(iocb, &data, pos);
}
if (retval > 0) {
*ppos = pos + retval;
iov_iter_advance(iter, retval);
The iterator advanced in ->direct_IO() is a _copy_, not the original.
The contents of *iter as seen by generic_file_read_iter() is not
modifiable by ->direct_IO(), simply because its address is nowhere to
be found. And checking iov_iter_count(iter) at the end of dax_io() is
pointless - from the POV of generic_file_read_iter() it's data.count,
and while it used to be equal to iter->count, it's already been modified.
By the time we call iov_iter_advance() in generic_file_read_iter() that
value will be already discarded, along with rest of struct iov_iter data.
Wait a minute - you are triggering _what_???
> > + WARN_ON((pos == start) && (pos - start > iov_iter_count(iter)));
With '&&'? iov_iter_count() is size_t, while pos and start are loff_t,
so you are seeing equal values in pos and start (as integers) *and*
(loff_t)0 > (size_t)something. loff_t is a signed type, size_t - unsigned.
6.3.1.8[1] says that
* if rank of size_t is greater or equal to rank of loff_t, the
latter gets converted to size_t. And conversion of zero should be zero,
i.e. (size_t) 0 > (size_t)something, which is impossible (we compare them
as non-negative integers).
* if loff_t can represent all values of size_t, size_t value gets
converted to loff_t. Result of conversion should have the same (in particular,
non-negative) value. Again, comparison can't be true.
* otherwise both values are converted to unsigned counterpart of
loff_t. Again, zero converts to 0 and in any unsigned type 0 > x is
impossible.
I don't see any way for that condition to evaluate true.
Assuming that it's a misquoted ||... I don't see any way for pos to
get greater than start + original iov_iter_count(). However, I *do*
see a way for bad things to happen in a different way. Look:
// first pass through the loop, pos == start (and so's max)
retval = dax_get_addr(bh, &addr, blkbits);
// got a positive value
if (retval < 0)
break;
// nope, keep going
if (buffer_unwritten(bh) || buffer_new(bh)) {
dax_new_buf(addr, retval, first, pos,
end);
need_wmb = true;
}
addr += first;
size = retval - first;
// OK...
}
max = min(pos + size, end);
// OK...
}
if (iov_iter_rw(iter) == WRITE) {
len = copy_from_iter_pmem(addr, max - pos, iter);
need_wmb = true;
} else if (!hole)
len = copy_to_iter((void __force *)addr, max - pos,
iter);
else
len = iov_iter_zero(max - pos, iter);
// too bad - we'd hit an unmapped memory area. len is 0...
// and retval is fucking positive.
if (!len)
break;
return (pos == start) ? retval : pos - start;
// will return a bloody big positive value
Could you try to reproduce it with this:
dax_io(): don't let non-error value escape via retval instead of EFAULT
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
diff --git a/fs/dax.c b/fs/dax.c
index a86d3cc..7b653e9 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -169,8 +169,10 @@ static ssize_t dax_io(struct inode *inode, struct iov_iter *iter,
else
len = iov_iter_zero(max - pos, iter);
- if (!len)
+ if (!len) {
+ retval = -EFAULT;
break;
+ }
pos += len;
addr += len;
next prev parent reply other threads:[~2015-11-06 1:34 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-12 14:13 Sasha Levin
2015-08-15 20:13 ` Chuck Ebbert
2015-08-17 9:18 ` Andrey Ryabinin
2015-08-19 5:46 ` Al Viro
2015-09-02 20:00 ` Sasha Levin
2015-09-18 2:24 ` Sasha Levin
2015-09-30 21:30 ` Sasha Levin
2015-10-17 19:22 ` Sasha Levin
2015-10-18 4:17 ` Ross Zwisler
2015-10-19 23:34 ` Sasha Levin
2015-11-06 1:34 ` Al Viro [this message]
2015-11-06 2:19 ` Al Viro
2015-11-06 3:38 ` Linus Torvalds
2015-11-06 16:06 ` Jens Axboe
2015-11-11 2:21 ` Linus Torvalds
2015-11-11 2:25 ` Jens Axboe
2015-11-11 2:31 ` Linus Torvalds
2015-11-11 2:40 ` Jens Axboe
2015-11-11 2:41 ` Jens Axboe
2015-11-11 2:44 ` Jens Axboe
2015-11-11 3:06 ` Al Viro
2015-11-11 3:07 ` Jens Axboe
2015-11-11 3:20 ` Sasha Levin
2015-11-11 2:56 ` Al Viro
2015-11-11 3:30 ` Al Viro
2015-11-11 4:36 ` Linus Torvalds
2015-11-11 7:43 ` Al Viro
2015-11-11 8:16 ` Stephen Rothwell
2015-11-11 10:19 ` Al Viro
2015-11-11 10:28 ` Stephen Rothwell
2015-11-11 16:25 ` Mike Marshall
2015-11-11 16:36 ` Al Viro
2015-11-11 16:56 ` Mike Marshall
2015-11-11 16:33 ` Al Viro
2015-11-11 21:47 ` Stephen Rothwell
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=20151106013402.GT22011@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=cebbert.lkml@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=sasha.levin@oracle.com \
--cc=willy@linux.intel.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
Powered by JetHome