From: Demi Marie Obenour <demiobenour@gmail.com>
To: Linux kernel mailing list <linux-kernel@vger.kernel.org>,
linux-mm@kvack.org
Cc: Bert Karwatzki <spasswolf@web.de>, Jeff Xu <jeffxu@chromium.org>,
Jiri Olsa <olsajiri@gmail.com>, Kees Cook <kees@kernel.org>,
Lorenzo Stoakes <lstoakes@gmail.com>,
Mark Brown <broonie@kernel.org>,
Matthew Wilcox <willy@infradead.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Paul Moore <paul@paul-moore.com>,
Sidhartha Kumar <sidhartha.kumar@oracle.com>,
Suren Baghdasaryan <surenb@google.com>,
Vlastimil Babka <vbabka@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>
Subject: MAP_FIXED leaving holes on failure is very difficult to recover from and can even be a security hole
Date: Wed, 4 Nov 2026 19:56:11 -0500 [thread overview]
Message-ID: <8b45a161-101f-4f28-9b7a-c7c8b8a29f90@gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1918 bytes --]
Right now, a failed MAP_FIXED mmap() can leave a hole in the address
space. Another mmap() can then enter this hole. This was fixed in
the past, but the fix was undone in
4f87153e82c4 ("mm: change failure of MAP_FIXED to restoring the gap on failure").
This is really nasty, and can create serious problems for userspace.
A simple example is MAP_FIXED over a part of a KVM memslot to expose
memory to a guest. If that leaves a hole, the result is catastrophic:
Subsequent mmap()s (perhaps by malloc()) can get put into that address
range. KVM will give the guest access to whatever happens to be put
there, and one must assume the guest can turn that into a VM escape.
Other situations don't result in immediate disaster, but are still
really hard to recover from. One can use MAP_FIXED_NOREPLACE to
refill the hole if nobody else has filled it, but if someone has,
there's no hope of making the original mapping (that the MAP_FIXED had
clobbered) contiguous again. One must either figure out how to handle
a non-contiguous mapping, rebuild the mapping elsewhere, or crash.
In my case, I can work around the problem by using a single memslot per
file descriptor, but I suspect there are other use-cases that aren't
so lucky. Yet others may simply not have realized this was possible;
there's even a Stack Overflow answer [1] that claims that the map is
replaced atomically. I only found out about it from Claude Opus 5.5.
I asked it to write a test suite, and it pointed out that a failed
MAP_FIXED mmap() can leave a hole. If I hadn't asked, I would have
shipped a security vulnerability.
Should the behavior be changed again, so that mmap() with MAP_FIXED
is atomic? That would provide a UAPI that actually makes sense and
can be used without horribly ugly workarounds.
[1]: https://stackoverflow.com/a/28576674
--
Sincerely,
Demi Marie Obenour (she/her/hers)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
reply other threads:[~2026-11-05 0:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=8b45a161-101f-4f28-9b7a-c7c8b8a29f90@gmail.com \
--to=demiobenour@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=broonie@kernel.org \
--cc=jeffxu@chromium.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=olsajiri@gmail.com \
--cc=paul@paul-moore.com \
--cc=paulmck@kernel.org \
--cc=sidhartha.kumar@oracle.com \
--cc=spasswolf@web.de \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--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
all inboxes | Powered by JetHome®