Re: Fixed buffers have out-dated content

Linus Torvalds
2021-01-16T23:36:20Z

[-- Attachment #1: Type: text/plain, Size: 819 bytes --]

On Sat, Jan 16, 2021 at 3:05 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> I'll go think about this.
>
> Martin, since you can apparently trigger the problem easily, hopefully
> you're willing to try a couple of patches?

Hmm. It might end up being as simple as the attached patch.

I'm not super-happy with this situation (that whole nasty security
issue had some horrible cascading problems), and this only really
fixes _pinned_ pages.

In particular, somebody doing a plain get_user_pages() for writing can
still hit issues (admittedly that's true in general, but the vm
changes made it much more obviously true).

But for the case of io_uring buffers, this looks like the obvious simple fix.

I don't have a load to test this with, so I'll come back to ask Martin
to do so...

Linus

[-- Attachment #2: patch --]
[-- Type: application/octet-stream, Size: 526 bytes --]

mm/vmscan.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 257cba79a96d..b1b574ad199d 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1238,6 +1238,8 @@ static unsigned int shrink_page_list(struct list_head *page_list,
if (!PageSwapCache(page)) {
if (!(sc->gfp_mask & __GFP_IO))
goto keep_locked;
+ if (page_maybe_dma_pinned(page))
+ goto keep_locked;
if (PageTransHuge(page)) {
/* cannot split THP, skip it */
if (!can_split_huge_page(page, NULL))