linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7 0/7]  mseal system mappings
@ 2025-02-24 22:52 jeffxu
  2025-02-24 22:52 ` [PATCH v7 1/7] mseal, system mappings: kernel config and header change jeffxu
                   ` (9 more replies)
  0 siblings, 10 replies; 73+ messages in thread
From: jeffxu @ 2025-02-24 22:52 UTC (permalink / raw)
  To: akpm, keescook, jannh, torvalds, vbabka, lorenzo.stoakes,
	Liam.Howlett, adhemerval.zanella, oleg, avagin, benjamin
  Cc: linux-kernel, linux-hardening, linux-mm, jorgelo, sroettger, hch,
	ojeda, thomas.weissschuh, adobriyan, johannes, pedro.falcato, hca,
	willy, anna-maria, mark.rutland, linus.walleij, Jason, deller,
	rdunlap, davem, peterx, f.fainelli, gerg, dave.hansen, mingo,
	ardb, mhocko, 42.hyeyoo, peterz, ardb, enh, rientjes, groeck, mpe,
	aleksandr.mikhalitsyn, mike.rapoport, Jeff Xu

From: Jeff Xu <jeffxu@chromium.org>

This is V7 version, addressing comments from V6, without code logic
change.

--------------------------------------------------

History:
V7:
 - Remove cover letter from the first patch (Liam R. Howlett)
 - Change macro name to VM_SEALED_SYSMAP (Liam R. Howlett)
 - logging and fclose() in selftest (Liam R. Howlett)

V6:
  https://lore.kernel.org/all/20250224174513.3600914-1-jeffxu@google.com/

V5
  https://lore.kernel.org/all/20250212032155.1276806-1-jeffxu@google.com/

V4:
  https://lore.kernel.org/all/20241125202021.3684919-1-jeffxu@google.com/

V3:
  https://lore.kernel.org/all/20241113191602.3541870-1-jeffxu@google.com/

V2:
  https://lore.kernel.org/all/20241014215022.68530-1-jeffxu@google.com/

V1:
  https://lore.kernel.org/all/20241004163155.3493183-1-jeffxu@google.com/

--------------------------------------------------
As discussed during mseal() upstream process [1], mseal() protects
the VMAs of a given virtual memory range against modifications, such
as the read/write (RW) and no-execute (NX) bits. For complete
descriptions of memory sealing, please see mseal.rst [2].

The mseal() is useful to mitigate memory corruption issues where a
corrupted pointer is passed to a memory management system. For
example, such an attacker primitive can break control-flow integrity
guarantees since read-only memory that is supposed to be trusted can
become writable or .text pages can get remapped.

The system mappings are readonly only, memory sealing can protect
them from ever changing to writable or unmmap/remapped as different
attributes.

System mappings such as vdso, vvar, and sigpage (arm), vectors (arm)
are created by the kernel during program initialization, and could
be sealed after creation.

Unlike the aforementioned mappings, the uprobe mapping is not
established during program startup. However, its lifetime is the same
as the process's lifetime [3]. It could be sealed from creation.

The vsyscall on x86-64 uses a special address (0xffffffffff600000),
which is outside the mm managed range. This means mprotect, munmap, and
mremap won't work on the vsyscall. Since sealing doesn't enhance
the vsyscall's security, it is skipped in this patch. If we ever seal
the vsyscall, it is probably only for decorative purpose, i.e. showing
the 'sl' flag in the /proc/pid/smaps. For this patch, it is ignored.

It is important to note that the CHECKPOINT_RESTORE feature (CRIU) may
alter the system mappings during restore operations. UML(User Mode Linux)
and gVisor, rr are also known to change the vdso/vvar mappings.
Consequently, this feature cannot be universally enabled across all
systems. As such, CONFIG_MSEAL_SYSTEM_MAPPINGS is disabled by default.

To support mseal of system mappings, architectures must define
CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS and update their special mappings
calls to pass mseal flag. Additionally, architectures must confirm they
do not unmap/remap system mappings during the process lifetime.

In this version, we've improved the handling of system mapping sealing from
previous versions, instead of modifying the _install_special_mapping
function itself, which would affect all architectures, we now call
_install_special_mapping with a sealing flag only within the specific
architecture that requires it. This targeted approach offers two key
advantages: 1) It limits the code change's impact to the necessary
architectures, and 2) It aligns with the software architecture by keeping
the core memory management within the mm layer, while delegating the
decision of sealing system mappings to the individual architecture, which
is particularly relevant since 32-bit architectures never require sealing.

Prior to this patch series, we explored sealing special mappings from
userspace using glibc's dynamic linker. This approach revealed several
issues:
- The PT_LOAD header may report an incorrect length for vdso, (smaller
  than its actual size). The dynamic linker, which relies on PT_LOAD
  information to determine mapping size, would then split and partially
  seal the vdso mapping. Since each architecture has its own vdso/vvar
  code, fixing this in the kernel would require going through each
  archiecture. Our initial goal was to enable sealing readonly mappings,
  e.g. .text, across all architectures, sealing vdso from kernel since
  creation appears to be simpler than sealing vdso at glibc.
- The [vvar] mapping header only contains address information, not length
  information. Similar issues might exist for other special mappings.
- Mappings like uprobe are not covered by the dynamic linker,
  and there is no effective solution for them.

This feature's security enhancements will benefit ChromeOS, Android,
and other high security systems.

Testing:
This feature was tested on ChromeOS and Android for both x86-64 and ARM64.
- Enable sealing and verify vdso/vvar, sigpage, vector are sealed properly,
  i.e. "sl" shown in the smaps for those mappings, and mremap is blocked.
- Passing various automation tests (e.g. pre-checkin) on ChromeOS and
  Android to ensure the sealing doesn't affect the functionality of
  Chromebook and Android phone.

I also tested the feature on Ubuntu on x86-64:
- With config disabled, vdso/vvar is not sealed,
- with config enabled, vdso/vvar is sealed, and booting up Ubuntu is OK,
  normal operations such as browsing the web, open/edit doc are OK.

In addition, Benjamin Berg tested this on UML.

Link: https://lore.kernel.org/all/20240415163527.626541-1-jeffxu@chromium.org/ [1]
Link: Documentation/userspace-api/mseal.rst [2]
Link: https://lore.kernel.org/all/CABi2SkU9BRUnqf70-nksuMCQ+yyiWjo3fM4XkRkL-NrCZxYAyg@mail.gmail.com/ [3]




Jeff Xu (7):
  mseal, system mappings: kernel config and header change
  selftests: x86: test_mremap_vdso: skip if vdso is msealed
  mseal, system mappings: enable x86-64
  mseal, system mappings: enable arm64
  mseal, system mappings: enable uml architecture
  mseal, system mappings: uprobe mapping
  mseal, system mappings: update mseal.rst

 Documentation/userspace-api/mseal.rst         |  7 +++
 arch/arm64/Kconfig                            |  1 +
 arch/arm64/kernel/vdso.c                      | 22 +++++++---
 arch/um/Kconfig                               |  1 +
 arch/x86/Kconfig                              |  1 +
 arch/x86/entry/vdso/vma.c                     | 16 ++++---
 arch/x86/um/vdso/vma.c                        |  6 ++-
 include/linux/mm.h                            | 10 +++++
 init/Kconfig                                  | 18 ++++++++
 kernel/events/uprobes.c                       |  5 ++-
 security/Kconfig                              | 18 ++++++++
 .../testing/selftests/x86/test_mremap_vdso.c  | 43 +++++++++++++++++++
 12 files changed, 132 insertions(+), 16 deletions(-)

-- 
2.48.1.658.g4767266eb4-goog



^ permalink raw reply	[flat|nested] 73+ messages in thread

end of thread, other threads:[~2025-02-28 17:30 UTC | newest]

Thread overview: 73+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-24 22:52 [PATCH v7 0/7] mseal system mappings jeffxu
2025-02-24 22:52 ` [PATCH v7 1/7] mseal, system mappings: kernel config and header change jeffxu
2025-02-25  6:05   ` Lorenzo Stoakes
2025-02-26  1:33     ` Jeff Xu
2025-02-26  6:04       ` Lorenzo Stoakes
2025-02-28  0:04         ` Jeff Xu
2025-02-28 10:32           ` Lorenzo Stoakes
2025-02-25 15:22   ` Liam R. Howlett
2025-02-25 15:37     ` Lorenzo Stoakes
2025-02-26  0:04     ` Jeff Xu
2025-02-24 22:52 ` [PATCH v7 2/7] selftests: x86: test_mremap_vdso: skip if vdso is msealed jeffxu
2025-02-25  6:15   ` Lorenzo Stoakes
2025-02-25 22:37     ` Jeff Xu
2025-02-26  5:58       ` Lorenzo Stoakes
2025-02-24 22:52 ` [PATCH v7 3/7] mseal, system mappings: enable x86-64 jeffxu
2025-02-25  1:03   ` Kees Cook
2025-02-26  0:21     ` Jeff Xu
2025-02-25  8:08   ` Thomas Weißschuh
2025-02-26  0:48     ` Jeff Xu
2025-02-26  7:35       ` Thomas Weißschuh
2025-02-27 21:44         ` Jeff Xu
2025-02-24 22:52 ` [PATCH v7 4/7] mseal, system mappings: enable arm64 jeffxu
2025-02-25  6:20   ` Lorenzo Stoakes
2025-02-25 22:26     ` Jeff Xu
2025-02-26  5:25       ` Lorenzo Stoakes
2025-02-26 17:11         ` Liam R. Howlett
2025-02-26 17:17           ` Jeff Xu
2025-02-26 17:43             ` Lorenzo Stoakes
2025-02-26 18:14               ` Lorenzo Stoakes
2025-02-28  0:48               ` Jeff Xu
2025-02-28 10:31                 ` Lorenzo Stoakes
2025-02-24 22:52 ` [PATCH v7 5/7] mseal, system mappings: enable uml architecture jeffxu
2025-02-25  6:22   ` Lorenzo Stoakes
2025-02-25  8:45     ` Berg, Benjamin
2025-02-25 10:37       ` Lorenzo Stoakes
2025-02-25 12:24         ` Benjamin Berg
2025-02-25 13:41           ` Lorenzo Stoakes
2025-02-25 13:59             ` Johannes Berg
2025-02-25 15:06         ` Kees Cook
2025-02-25 15:31           ` Lorenzo Stoakes
2025-02-25 18:38             ` Kees Cook
2025-02-26  0:00               ` Jeff Xu
2025-02-24 22:52 ` [PATCH v7 6/7] mseal, system mappings: uprobe mapping jeffxu
2025-02-25  6:24   ` Lorenzo Stoakes
2025-02-26  0:06     ` Jeff Xu
2025-02-26  5:57       ` Lorenzo Stoakes
2025-02-26 16:26   ` Oleg Nesterov
2025-02-26 16:33     ` Oleg Nesterov
2025-02-26 16:45     ` Lorenzo Stoakes
2025-02-26 18:01       ` Oleg Nesterov
2025-02-26 18:06         ` Lorenzo Stoakes
2025-02-26 18:19           ` Liam R. Howlett
2025-02-26 18:20           ` Oleg Nesterov
2025-02-26 18:25             ` Lorenzo Stoakes
2025-02-27 23:38               ` Jeff Xu
2025-02-28 10:39                 ` Lorenzo Stoakes
2025-02-27 21:48             ` Jeff Xu
2025-02-24 22:52 ` [PATCH v7 7/7] mseal, system mappings: update mseal.rst jeffxu
2025-02-24 23:03 ` [PATCH v7 0/7] mseal system mappings Pedro Falcato
2025-02-24 23:07   ` Jeff Xu
2025-02-25  6:09     ` Lorenzo Stoakes
2025-02-25 10:32 ` Lorenzo Stoakes
2025-02-26  0:17   ` Jeff Xu
2025-02-26  6:00     ` Lorenzo Stoakes
2025-02-27 23:43       ` Jeff Xu
2025-02-28 10:32         ` Lorenzo Stoakes
2025-02-25 15:18 ` Lorenzo Stoakes
2025-02-26  0:12   ` Jeff Xu
2025-02-26  5:42     ` your mail Lorenzo Stoakes
2025-02-28  0:55       ` Jeff Xu
2025-02-28  9:35         ` Lorenzo Stoakes
2025-02-28 17:24           ` Jeff Xu
2025-02-28 17:30             ` Lorenzo Stoakes

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).