From: Lorenzo Stoakes <lstoakes@gmail.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Christoph Hellwig <hch@infradead.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Jens Axboe <axboe@kernel.dk>,
Matthew Wilcox <willy@infradead.org>,
Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>,
Leon Romanovsky <leon@kernel.org>,
Christian Benvenuti <benve@cisco.com>,
Nelson Escobar <neescoba@cisco.com>,
Bernard Metzler <bmt@zurich.ibm.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Bjorn Topel <bjorn@kernel.org>,
Magnus Karlsson <magnus.karlsson@intel.com>,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
Jonathan Lemon <jonathan.lemon@gmail.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Christian Brauner <brauner@kernel.org>,
Richard Cochran <richardcochran@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org,
netdev@vger.kernel.org, bpf@vger.kernel.org,
Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH v2] mm/gup: disallow GUP writing to file-backed mappings by default
Date: Mon, 24 Apr 2023 20:18:33 +0100 [thread overview]
Message-ID: <f00058b8-0397-465f-9db5-ddd30a5efe8e@lucifer.local> (raw)
In-Reply-To: <ZEbQeImOiaXrydBE@nvidia.com>
On Mon, Apr 24, 2023 at 03:54:48PM -0300, Jason Gunthorpe wrote:
> On Mon, Apr 24, 2023 at 07:22:03PM +0100, Lorenzo Stoakes wrote:
>
> > OK I guess you mean the folio lock :) Well there is
> > unpin_user_pages_dirty_lock() and unpin_user_page_range_dirty_lock() and
> > also set_page_dirty_lock() (used by __access_remote_vm()) which should
> > avoid this.
>
> It has been a while, but IIRC, these are all basically racy, the
> comment in front of set_page_dirty_lock() even says it is racy..
>
> The race is that a FS cleans a page and thinks it cannot become dirty,
> and then it becomes dirty - and all variations of that..
>
> Looking around a bit, I suppose what I'd expect to see is a sequence
> sort of like what do_page_mkwrite() does:
>
> /* Synchronize with the FS and get the page locked */
> ret = vmf->vma->vm_ops->page_mkwrite(vmf);
> if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))
> return ret;
> if (unlikely(!(ret & VM_FAULT_LOCKED))) {
> lock_page(page);
> if (!page->mapping) {
> unlock_page(page);
> return 0; /* retry */
> }
> ret |= VM_FAULT_LOCKED;
> } else
> VM_BUG_ON_PAGE(!PageLocked(page), page);
>
> /* Write to the page with the CPU */
> va = kmap_local_atomic(page);
> memcpy(va, ....);
> kunmap_local_atomic(page);
>
> /* Tell the FS and unlock it. */
> set_page_dirty(page);
> unlock_page(page);
>
> I don't know if this is is exactly right, but it seems closerish
>
> So maybe some kind of GUP interfaces that returns single locked pages
> is the right direction? IDK
>
> Or maybe we just need to make a memcpy primitive that works while
> holding the PTLs?
>
I think this patch suggestion has scope crept from 'incremental
improvement' to 'major rework of GUP' at this point. Also surely you'd want
to obtain the PTL of all mappings to a file? This seems really unworkable
and I don't think holding a folio lock over a long period is sensible
either.
> > We definitely need to keep ptrace and /proc/$pid/mem functioning correctly,
> > and I given the privilege levels required I don't think there's a security
> > issue there?
>
> Even root is not allowed to trigger data corruption or oops inside the
> kernel.
>
> Jason
Of course, but isn't this supposed to be an incremental fix? It feels a
little contradictory to want to introduce a flag intentionally to try to
highlight brokenness then to not accept any solution that doesn't solve
that brokenness.
In any case, I feel that this patch isn't going to go anywhere as-is, it's
insufficiently large to solve the problem as a whole (I think that's a
bigger problem we can return to later), and there appears to be no taste
for an incremental improvement, even from the suggester :)
As a result, I suggest we take the cautious route in order to unstick the
vmas patch series - introduce an OPT-IN flag which allows the check to be
made, and update io_uring to use this.
That way it defers the larger discussion around this improvement, avoids
breaking anything, provides some basis in code for this check and is a net,
incremental small and digestible improvement.
next prev parent reply other threads:[~2023-04-24 19:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 7:43 [PATCH v2] mm/gup: disallow GUP writing to file-backed mappings by default Lorenzo Stoakes
2023-04-24 9:43 ` Christoph Hellwig
2023-04-24 10:17 ` Lorenzo Stoakes
2023-04-24 12:28 ` Jason Gunthorpe
2023-04-24 12:38 ` Christoph Hellwig
2023-04-24 13:26 ` Jason Gunthorpe
2023-04-24 12:38 ` Lorenzo Stoakes
2023-04-24 13:39 ` Jason Gunthorpe
2023-04-24 14:29 ` Lorenzo Stoakes
2023-04-24 17:36 ` Jason Gunthorpe
2023-04-24 18:22 ` Lorenzo Stoakes
2023-04-24 18:54 ` Jason Gunthorpe
2023-04-24 19:18 ` Lorenzo Stoakes [this message]
2023-04-24 22:53 ` Jason Gunthorpe
2023-04-24 23:03 ` Lorenzo Stoakes
2023-04-24 23:17 ` Jason Gunthorpe
2023-04-24 23:26 ` Lorenzo Stoakes
2023-04-24 23:30 ` Jason Gunthorpe
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=f00058b8-0397-465f-9db5-ddd30a5efe8e@lucifer.local \
--to=lstoakes@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=ast@kernel.org \
--cc=axboe@kernel.dk \
--cc=benve@cisco.com \
--cc=bjorn@kernel.org \
--cc=bmt@zurich.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dennis.dalessandro@cornelisnetworks.com \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=hch@infradead.org \
--cc=irogers@google.com \
--cc=jgg@nvidia.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=jonathan.lemon@gmail.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=neescoba@cisco.com \
--cc=netdev@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=pabeni@redhat.com \
--cc=peterz@infradead.org \
--cc=richardcochran@gmail.com \
--cc=willy@infradead.org \
/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).