linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: "Denis M. Karpov" <komlomal@gmail.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Mike Rapoport <rppt@kernel.org>,
	Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [BUG] userfaultfd: UFFDIO_REGISTER fails on low addresses despite CAP_SYS_RAWIO
Date: Fri, 3 Apr 2026 14:41:18 -0400	[thread overview]
Message-ID: <adAJznD2zpA1brmz@x1.local> (raw)
In-Reply-To: <CADtiZd0tWysx5HMCUnOXfSHB7PXAuXg1Mh4eY_hUmH29S=sejg@mail.gmail.com>

On Fri, Apr 03, 2026 at 02:24:05PM +0300, Denis M. Karpov wrote:
> Hello,

Hello, Denis,

> I am seeing an inconsistency between mmap() and userfaultfd's UFFDIO_REGISTER
> logic regarding low memory addresses.
> Kernel: 6.12.63+deb13-amd64 (Debian 6.12.63-1)
> Description:
> As root (or with CAP_SYS_RAWIO), it is possible to mmap() the low-address area
> (below mmap_min_addr). However, UFFDIO_REGISTER fails with -EINVAL for these
> same ranges. The issue appears to be in fs/userfaultfd.c:validate_range():
>     if (start < mmap_min_addr)
>         return -EINVAL;
> 
> While mmap() uses cap_mmap_addr() to allow privileged access to these areas,
> userfaultfd performs a hard check against mmap_min_addr without considering
> capabilities. This prevents binary translators/compilers from using UFFD on
> valid memory areas mapped by the application.

Indeed.  I believe the current behavior existed since Andrea introduced
userfaultfd, and it makes a lot of sense when starting from a stricter
semantics with a new system call like it.

When there's an explicit demand of using it under mmap_min_addr, I don't
see an issue why we can't consider enabling that, as long as we do at least
the same level of security check similarly to mmap() here.  So to me, it
looks all reasonable to replace that check with cap_mmap_addr().  I can't
think of any bad side effect except starting to enable your use case which
seems a valid one.

IMHO you prepare an RFC patch and copy some more people to collect
feedbacks.  I would suggest at least the ones listed in MEMORY MAPPING
section of the maintainers file.  Btw, Mike Rapoport is now the official
maintainer for userfaultfd, please remember to copy him too when sending.

PS: it's holiday window (Good Friday) so please expect delays for replies.

Thanks,

-- 
Peter Xu



      reply	other threads:[~2026-04-03 18:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-03 11:24 Denis M. Karpov
2026-04-03 18:41 ` Peter Xu [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=adAJznD2zpA1brmz@x1.local \
    --to=peterx@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=komlomal@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.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