[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YqS3LqioLdSYIWgS@zeniv-ca.linux.org.uk>
Date: Sat, 11 Jun 2022 15:39:26 +0000
From: Al Viro <viro@...iv.linux.org.uk>
To: Guenter Roeck <linux@...ck-us.net>
Cc: Sudip Mukherjee <sudipm.mukherjee@...il.com>,
David Howells <dhowells@...hat.com>,
Dominique Martinet <asmadeus@...ewreck.org>,
Mike Marshall <hubcap@...ibond.com>,
Gao Xiang <xiang@...nel.org>, linux-afs@...ts.infradead.org,
v9fs-developer@...ts.sourceforge.net, devel@...ts.orangefs.org,
linux-erofs@...ts.ozlabs.org, linux-cachefs@...hat.com,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
Linus Torvalds <torvalds@...ux-foundation.org>
Subject: Re: mainline build failure due to 6c77676645ad ("iov_iter: Fix
iter_xarray_get_pages{,_alloc}()")
On Sat, Jun 11, 2022 at 03:01:16PM +0000, Al Viro wrote:
> On Sat, Jun 11, 2022 at 07:00:52AM -0700, Guenter Roeck wrote:
> > On Sat, Jun 11, 2022 at 12:56:27PM +0000, Al Viro wrote:
> > > On Sat, Jun 11, 2022 at 12:37:44PM +0000, Al Viro wrote:
> > > > On Sat, Jun 11, 2022 at 12:12:47PM +0000, Al Viro wrote:
> > > >
> > > >
> > > > > At a guess, should be
> > > > > return min((size_t)nr * PAGE_SIZE - offset, maxsize);
> > > > >
> > > > > in both places. I'm more than half-asleep right now; could you verify that it
> > > > > (as the last lines of both iter_xarray_get_pages() and iter_xarray_get_pages_alloc())
> > > > > builds correctly?
> > > >
> > > > No, I'm misreading it - it's unsigned * unsigned long - unsigned vs. size_t.
> > > > On arm it ends up with unsigned long vs. unsigned int; functionally it *is*
> > > > OK (both have the same range there), but it triggers the tests. Try
> > > >
> > > > return min_t(size_t, nr * PAGE_SIZE - offset, maxsize);
> > > >
> > > > there (both places).
> > >
> > > The reason we can't overflow on multiplication there, BTW, is that we have
> > > nr <= count, and count has come from weirdly open-coded
> > > DIV_ROUND_UP(size + offset, PAGE_SIZE)
> >
> > That is often done to avoid possible overflows. Is size + offset
> > guaranteed to be smaller than ULONG_MAX ?
>
> You'd need iter->count and maxsize argument to be within PAGE_SIZE of
> ULONG_MAX. How would you populate that xarray, anyway?
FWIW, it probably would be a good idea to truncate maxsize to LONG_MAX
in iov_iter_get_pages()/iov_iter_get_pages_alloc(), just to avoid that kind
of crap in the future. Check that maxpages is not zero on the top level,
while we are at it...
Any caller of iov_iter_get_pages{,_alloc}() must be ready to handle
getting less than what they'd asked for - if nothing else, get_user_pages_fast()
might refuse to give you more than this many pages, etc. All in-tree callers
do, AFAICS. And if anyone comes with "pin me more than LONG_MAX bytes of RAM
in one call, I can't accept anything less than that", well... ISO9000-compliant
response per Dilbert would be called for.
Powered by blists - more mailing lists