lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 22 Jun 2021 23:04:15 +0100
From:   Matthew Wilcox <willy@...radead.org>
To:     David Laight <David.Laight@...lab.com>
Cc:     'David Howells' <dhowells@...hat.com>,
        Al Viro <viro@...iv.linux.org.uk>,
        "torvalds@...ux-foundation.org" <torvalds@...ux-foundation.org>,
        Ted Ts'o <tytso@....edu>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        "linux-mm@...ck.org" <linux-mm@...ck.org>,
        "linux-ext4@...r.kernel.org" <linux-ext4@...r.kernel.org>,
        "linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: Do we need to unrevert "fs: do not prefault sys_write() user
 buffer pages"?

On Tue, Jun 22, 2021 at 09:55:09PM +0000, David Laight wrote:
> From: David Howells
> > Sent: 22 June 2021 17:27
> > 
> > Al Viro <viro@...iv.linux.org.uk> wrote:
> > 
> > > On Tue, Jun 22, 2021 at 04:20:40PM +0100, David Howells wrote:
> > >
> > > > and wondering if the iov_iter_fault_in_readable() is actually effective.
> > > > Yes, it can make sure that the page we're intending to modify is dragged
> > > > into the pagecache and marked uptodate so that it can be read from, but is
> > > > it possible for the page to then get reclaimed before we get to
> > > > iov_iter_copy_from_user_atomic()?  a_ops->write_begin() could potentially
> > > > take a long time, say if it has to go and get a lock/lease from a server.
> > >
> > > Yes, it is.  So what?  We'll just retry.  You *can't* take faults while
> > > holding some pages locked; not without shitloads of deadlocks.
> > 
> > In that case, can we amend the comment immediately above
> > iov_iter_fault_in_readable()?
> > 
> > 	/*
> > 	 * Bring in the user page that we will copy from _first_.
> > 	 * Otherwise there's a nasty deadlock on copying from the
> > 	 * same page as we're writing to, without it being marked
> > 	 * up-to-date.
> > 	 *
> > 	 * Not only is this an optimisation, but it is also required
> > 	 * to check that the address is actually valid, when atomic
> > 	 * usercopies are used, below.
> > 	 */
> > 	if (unlikely(iov_iter_fault_in_readable(i, bytes))) {
> > 
> > The first part suggests this is for deadlock avoidance.  If that's not true,
> > then this should perhaps be changed.
> 
> I'd say something like:
> 	/*
> 	 * The actual copy_from_user() is done with a lock held
> 	 * so cannot fault in missing pages.
> 	 * So fault in the pages first.
> 	 * If they get paged out the inatomic usercopy will fail
> 	 * and the whole operation is retried.
> 	 *
> 	 * Hopefully there are enough memory pages available to
> 	 * stop this looping forever.
> 	 */
> 
> It is perfectly possible for another application thread to
> invalidate one of the buffer fragments after iov_iter_fault_in_readable()
> return success - so it will then fail on the second pass.
> 
> The maximum number of pages required is twice the maximum number
> of iov fragments.
> If the system is crawling along with no available memory pages
> the same physical page could get used for two user pages.

I would suggest reading the function before you suggest modifications
to it.

                offset = (pos & (PAGE_SIZE - 1));
                bytes = min_t(unsigned long, PAGE_SIZE - offset,
                                                iov_iter_count(i));

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ