SELinux Archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Axel Rasmussen <axelrasmussen@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Lokesh Gidra <lokeshgidra@google.com>,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, selinux@vger.kernel.org,
	surenb@google.com, kernel-team@android.com, aarcange@redhat.com,
	peterx@redhat.com, david@redhat.com, bgeffon@google.com,
	willy@infradead.org, jannh@google.com, kaleshsingh@google.com,
	ngeoffray@google.com
Subject: Re: [PATCH] userfaultfd: fix mmap_changing checking in mfill_atomic_hugetlb
Date: Thu, 25 Jan 2024 11:36:32 +0200	[thread overview]
Message-ID: <ZbIroGI1kADrOTUB@kernel.org> (raw)
In-Reply-To: <CAJHvVcgTk3Cf2i-ONx=jH_-dz9GktVMv1Sdqv3cCk6nP2k++iA@mail.gmail.com>

On Thu, Jan 18, 2024 at 03:17:14PM -0800, Axel Rasmussen wrote:
> 
> On Thu, Jan 18, 2024 at 1:59 PM Andrew Morton <akpm@linux-foundation.org>
> wrote:
> 
>     On Wed, 17 Jan 2024 14:37:29 -0800 Lokesh Gidra <lokeshgidra@google.com>
>     wrote:
> 
>     > In mfill_atomic_hugetlb(), mmap_changing isn't being checked
>     > again if we drop mmap_lock and reacquire it. When the lock is not held,
>     > mmap_changing could have been incremented. This is also inconsistent
>     > with the behavior in mfill_atomic().
> 
> 
> The change looks reasonable to me. I'm not sure I can conclusively say there
> isn't some other mechanism specific to hugetlbfs which means this isn't needed,
> though.
  
There's nothing specific to hugetlb, if a non-cooperative uffdio_copy races
with mremap/fork etc, the vma under it may change
 
>     Thanks. Could you and reviewers please consider
> 
>     - what might be the userspace-visible runtime effects?

For users of non-cooperative uffd with hugetlb, this would fix crashes
caused by races between uffd operations that update memory and the
operations that change the VM layout. Pretty much the same fix as
df2cc96e77011 ("userfaultfd: prevent non-cooperative events vs mcopy_atomic
races") for !hugetlb memory.

I doubt such users exist, though...
 
>     - Should the fix be backported into earlier kernels?
>     - A suitable Fixes: target?
> 
> Hmm, 60d4d2d2b40e4 added __mcopy_atomic_hugetlb without this. But, at that
> point in history, none of the other functions had mmap_changing either.
> 
> So, I think the right Fixes: target is df2cc96e77011 ("userfaultfd: prevent
> non-cooperative events vs mcopy_atomic races") ? It seems to have missed the
> hugetlb path. This was introduced in 4.18.
> 
> Based on that commit's message, essentially what can happen if the race
> "succeeds" is, memory can be accessed without userfaultfd being notified of
> this fact. Depending on what userfaultfd is being used for, from
> userspace's perspective this can appear like memory corruption for example. So,
> based on that it seems to me reasonable to backport this to stable kernels
> (4.19+).

I agree with Axel, 

Fixes: df2cc96e77011 ("userfaultfd: prevent non-cooperative events vs mcopy_atomic races")

seems appropriate.

-- 
Sincerely yours,
Mike.

      parent reply	other threads:[~2024-01-25  9:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-17 22:37 [PATCH] userfaultfd: fix mmap_changing checking in mfill_atomic_hugetlb Lokesh Gidra
2024-01-18 21:59 ` Andrew Morton
2024-01-18 23:29   ` Axel Rasmussen
     [not found]   ` <CAJHvVcgTk3Cf2i-ONx=jH_-dz9GktVMv1Sdqv3cCk6nP2k++iA@mail.gmail.com>
2024-01-25  9:36     ` Mike Rapoport [this message]

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=ZbIroGI1kADrOTUB@kernel.org \
    --to=rppt@kernel.org \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=bgeffon@google.com \
    --cc=david@redhat.com \
    --cc=jannh@google.com \
    --cc=kaleshsingh@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lokeshgidra@google.com \
    --cc=ngeoffray@google.com \
    --cc=peterx@redhat.com \
    --cc=selinux@vger.kernel.org \
    --cc=surenb@google.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 read-only IMAP folder(s) and NNTP newsgroup(s).