Skip to contentSkip to conversation

mseal system mappings

PATCH Superseded [email protected] 5 participants 43 messages Feb 24, 2025 – Feb 26, 2025

Subsystems (12)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover mseal system mappings

From: Jeff Xu <[email protected]>

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

History:
-------
V6:
- mseal.rst: fix a typo (Randy Dunlap)
- security/Kconfig: add rr into note (Liam R. Howlett)
- remove mseal_system_mappings() and use macro instead (Liam R. Howlett)
- mseal.rst: add incompatible userland software (Lorenzo Stoakes)
- remove RFC from title (Kees Cook)

V5
https://lore.kernel.org/all/[email protected]/

V4:
https://lore.kernel.org/all/[email protected]/

V3:
https://lore.kernel.org/all/[email protected]/

V2:
https://lore.kernel.org/all/[email protected]/

V1:
https://lore.kernel.org/all/[email protected]/

------------------------------------------------------------------------
Provide infrastructure to mseal system mappings. Establish two kernel configs (CONFIG_MSEAL_SYSTEM_MAPPINGS, ARCH_HAS_MSEAL_SYSTEM_MAPPINGS) and MSEAL_SYSTEM_MAPPINGS_VM_FLAG macro for future patches.

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.

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  | 38 +++++++++++++++++++
 12 files changed, 127 insertions(+), 16 deletions(-)
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#1 lore raw

PATCH v6 1/7 mseal, system mappings: kernel config and header change

From: Jeff Xu <[email protected]>

Provide infrastructure to mseal system mappings. Establish two kernel configs (CONFIG_MSEAL_SYSTEM_MAPPINGS, ARCH_HAS_MSEAL_SYSTEM_MAPPINGS) and MSEAL_SYSTEM_MAPPINGS_VM_FLAG macro for future patches.

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.

---
 include/linux/mm.h | 10 ++++++++++
 init/Kconfig       | 18 ++++++++++++++++++
 security/Kconfig   | 18 ++++++++++++++++++
 3 files changed, 46 insertions(+)
include/linux/mm.h +10 -0
index 7b1068ddcbb7..0e2a4a45d245 100644
@@ -4155,4 +4155,14 @@ int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *st
 int arch_set_shadow_stack_status(struct task_struct *t, unsigned long status);
 int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);
 
+
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG	VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG	VM_NONE
+#endif
+
 #endif /* _LINUX_MM_H */
init/Kconfig +18 -0
index d0d021b3fa3b..07435e33f965 100644
@@ -1882,6 +1882,24 @@ config ARCH_HAS_MEMBARRIER_CALLBACKS
 config ARCH_HAS_MEMBARRIER_SYNC_CORE
 	bool
 
+config ARCH_HAS_MSEAL_SYSTEM_MAPPINGS
+	bool
+	help
+	  Control MSEAL_SYSTEM_MAPPINGS access based on architecture.
+
+	  A 64-bit kernel is required for the memory sealing feature.
+	  No specific hardware features from the CPU are needed.
+
+	  To enable this feature, the architecture needs to update their
+	  special mappings calls to include the sealing flag and confirm
+	  that it doesn't unmap/remap system mappings during the life
+	  time of the process. After the architecture enables this, a
+	  distribution can set CONFIG_MSEAL_SYSTEM_MAPPING to manage access
+	  to the feature.
+
+	  For complete descriptions of memory sealing, please see
+	  Documentation/userspace-api/mseal.rst
+
 config HAVE_PERF_EVENTS
 	bool
 	help
security/Kconfig +18 -0
index f10dbf15c294..15a86a952910 100644
@@ -51,6 +51,24 @@ config PROC_MEM_NO_FORCE
 
 endchoice
 
+config MSEAL_SYSTEM_MAPPINGS
+	bool "mseal system mappings"
+	depends on 64BIT
+	depends on ARCH_HAS_MSEAL_SYSTEM_MAPPINGS
+	depends on !CHECKPOINT_RESTORE
+	help
+	  Seal system mappings such as vdso, vvar, sigpage, uprobes, etc.
+
+	  A 64-bit kernel is required for the memory sealing feature.
+	  No specific hardware features from the CPU are needed.
+
+	  Note: CHECKPOINT_RESTORE, UML, gVisor, rr are known to relocate or
+	  unmap system mapping, therefore this config can't be enabled
+	  universally.
+
+	  For complete descriptions of memory sealing, please see
+	  Documentation/userspace-api/mseal.rst
+
 config SECURITY
 	bool "Enable different security models"
 	depends on SYSFS
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#2 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

include/linux/mm.h int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *st · line 4166

Quoted 8 lines · On 2/24/25 09:45, [email protected] wrote:
include/linux/mm.h +8 -0
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG	VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG	VM_NONE
+#endif

This ends up looking pretty wonky in practice:

Review

Quoted 2 lines
(quoted diff) +2 -0
+	vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;

because MSEAL_SYSTEM_MAPPINGS_VM_FLAG is so much different from the other ones.

Would it really hurt to have

#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)
+#else
+#define VM_SEALED VM_NONE
#endif

?

Then all the users could just do:

vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP|
VM_SEALED

That seems to be a the common way of doing things. Take a look at:

# define VM_GROWSUP     VM_NONE
...
# define VM_MTE         VM_NONE
# define VM_MTE_ALLOWED VM_NONE
...
# define VM_UFFD_MINOR          VM_NONE
...
#define VM_DROPPABLE            VM_NONE

... and more

author
#3 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 28 lines · Dave Hansen

include/linux/mm.h int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *st · line 4166

Quoted 8 lines · On 2/24/25 09:45, [email protected] wrote:
include/linux/mm.h +8 -0
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_NONE
+#endif

This ends up looking pretty wonky in practice:

Review

Quoted 2 lines
(quoted diff) +2 -0
+     vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+     vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;

because MSEAL_SYSTEM_MAPPINGS_VM_FLAG is so much different from the other ones.

Would it really hurt to have

#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)

(quoted diff) +2 -0
+#else
+#define VM_SEALED       VM_NONE
 #endif
Quoted 2 lines

?

VM_SEALED isn't defined in 32-bit systems, and mseal.c isn't part of the build. This is intentional. Any 32-bit code trying to use the sealing function or the VM_SEALED flag will immediately fail compilation. This makes it easier to identify incorrect usage.

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

Thanks
-Jeff

#4 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 7 lines · Jeff Xu

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Quoted 5 lines

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

That logic is reasonable. But it's different from the _vast_ majority of other flags.

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

#5 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 11 lines · Dave Hansen
Quoted 10 lines · Jeff Xu

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Quoted 8 lines
Quoted 2 lines

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

That logic is reasonable. But it's different from the _vast_ majority of other flags.

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

Note that VM_SEALED is the "is this VMA sealed?" bit itself. The define for "should we perform system mapping sealing?" is intentionally separate here, so that it can be Kconfig and per-arch toggled, etc.

As for the name, I have no strong opinion. Perhaps VM_SEALED_SYSTEM_MAPPING ?

-Kees

Signature · 1 line
Kees Cook
author
#6 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 19 lines · Kees Cook
Quoted 17 lines · Dave Hansen
Quoted 7 lines · Jeff Xu

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Quoted 5 lines

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

That logic is reasonable. But it's different from the _vast_ majority of other flags.

Quoted 7 lines
Quoted 2 lines

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

Note that VM_SEALED is the "is this VMA sealed?" bit itself. The define for "should we perform system mapping sealing?" is intentionally separate here, so that it can be Kconfig and per-arch toggled, etc.

Ya, it is a layer of separation also. Thanks for pointing it out.

Quoted 2 lines

As for the name, I have no strong opinion. Perhaps VM_SEALED_SYSTEM_MAPPING ?

OK.

Thanks
-Jeff

Quoted 4 lines

-Kees

--
Kees Cook

#7 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

In reply to Kees Cook
Quoted 8 lines · Kees Cook
Quoted 5 lines

That logic is reasonable. But it's different from the _vast_ majority of other flags.

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

Note that VM_SEALED is the "is this VMA sealed?" bit itself. The define for "should we perform system mapping sealing?" is intentionally separate here, so that it can be Kconfig and per-arch toggled, etc.

Ahh, makes sense.

Quoted 1 line

As for the name, I have no strong opinion. Perhaps VM_SEALED_SYSTEM_MAPPING ?

Yeah, that'd work. Just something more consistent with the existing naming and more compact. I think:

VM_SEALED_SYS

would fit in nicely.

#8 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

In reply to Kees Cook
Quoted 18 lines · Kees Cook
Quoted 17 lines · Dave Hansen
Quoted 7 lines · Jeff Xu

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Quoted 5 lines

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

That logic is reasonable. But it's different from the _vast_ majority of other flags.

Quoted 7 lines
Quoted 2 lines

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

Note that VM_SEALED is the "is this VMA sealed?" bit itself. The define for "should we perform system mapping sealing?" is intentionally separate here, so that it can be Kconfig and per-arch toggled, etc.

Considering Dave is the second person that did not find the huge commit message helpful, can we please limit the commit message to be about the actual code and not the entire series?

I thought we said that it was worth while making this change in v5?

Thanks,
Liam

author
#9 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 28 lines · Liam R. Howlett
Quoted 18 lines · Kees Cook
Quoted 17 lines · Dave Hansen
Quoted 7 lines · Jeff Xu

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Quoted 5 lines

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

That logic is reasonable. But it's different from the _vast_ majority of other flags.

Quoted 7 lines
Quoted 2 lines

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

Note that VM_SEALED is the "is this VMA sealed?" bit itself. The define for "should we perform system mapping sealing?" is intentionally separate here, so that it can be Kconfig and per-arch toggled, etc.

Quoted 6 lines

Considering Dave is the second person that did not find the huge commit message helpful, can we please limit the commit message to be about the actual code and not the entire series?

I thought we said that it was worth while making this change in v5?

I include the cover letter's content in the first commit message to clearly communicate the purpose of the entire patch series, saving maintainers' time when accepting the patch.

Should I still include that, and add what the first patch does, and separate it from the cover letter with "----"? What do you think?

-Jeff

Quoted 2 lines

Thanks,
Liam

#10 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 34 lines · Jeff Xu
Quoted 32 lines · Liam R. Howlett
Quoted 18 lines · Kees Cook
Quoted 17 lines · Dave Hansen
Quoted 7 lines · Jeff Xu

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Quoted 5 lines

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

That logic is reasonable. But it's different from the _vast_ majority of other flags.

Quoted 7 lines
Quoted 2 lines

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

Note that VM_SEALED is the "is this VMA sealed?" bit itself. The define for "should we perform system mapping sealing?" is intentionally separate here, so that it can be Kconfig and per-arch toggled, etc.

Considering Dave is the second person that did not find the huge commit message helpful, can we please limit the commit message to be about the actual code and not the entire series?

Quoted 5 lines
Quoted 2 lines

I thought we said that it was worth while making this change in v5?

I include the cover letter's content in the first commit message to clearly communicate the purpose of the entire patch series, saving maintainers' time when accepting the patch.

Having more text than patch for such a patch seems unreasonable. I'd find it more acceptable if it were a complicated race condition, but everyone is getting lost in the summary.

Quoted 3 lines

Should I still include that, and add what the first patch does, and separate it from the cover letter with "----"? What do you think?

Here is my v5 answer, I think it was clear about not putting the entire summary into the first patch.

[1]. https://lore.kernel.org/all/ml3x5qchmnehdzz2rxsdcdghivaqffojiweuhvpvzw45u3l5bh@23sblrom3m36/

Thanks,
Liam

author
#11 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 38 lines · Liam R. Howlett
Quoted 36 lines · Jeff Xu
Quoted 34 lines · Liam R. Howlett
Quoted 18 lines · Kees Cook
Quoted 17 lines · Dave Hansen
Quoted 7 lines · Jeff Xu

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Quoted 5 lines

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

That logic is reasonable. But it's different from the _vast_ majority of other flags.

Quoted 7 lines
Quoted 2 lines

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

Note that VM_SEALED is the "is this VMA sealed?" bit itself. The define for "should we perform system mapping sealing?" is intentionally separate here, so that it can be Kconfig and per-arch toggled, etc.

Considering Dave is the second person that did not find the huge commit message helpful, can we please limit the commit message to be about the actual code and not the entire series?

I thought we said that it was worth while making this change in v5?

Quoted 8 lines
Quoted 3 lines

I include the cover letter's content in the first commit message to clearly communicate the purpose of the entire patch series, saving maintainers' time when accepting the patch.

Having more text than patch for such a patch seems unreasonable. I'd find it more acceptable if it were a complicated race condition, but everyone is getting lost in the summary.

I will remove the cover letter from the first patch then.

Quoted 7 lines
Quoted 3 lines

Should I still include that, and add what the first patch does, and separate it from the cover letter with "----"? What do you think?

Here is my v5 answer, I think it was clear about not putting the entire summary into the first patch.

Thanks.

Quoted 4 lines

[1]. https://lore.kernel.org/all/ml3x5qchmnehdzz2rxsdcdghivaqffojiweuhvpvzw45u3l5bh@23sblrom3m36/

Thanks,
Liam

#12 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

In reply to Liam R. Howlett
Quoted 27 lines · Liam R. Howlett
Quoted 18 lines · Kees Cook
Quoted 17 lines · Dave Hansen
Quoted 7 lines · Jeff Xu

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Quoted 5 lines

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

That logic is reasonable. But it's different from the _vast_ majority of other flags.

Quoted 7 lines
Quoted 2 lines

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

Note that VM_SEALED is the "is this VMA sealed?" bit itself. The define for "should we perform system mapping sealing?" is intentionally separate here, so that it can be Kconfig and per-arch toggled, etc.

Quoted 5 lines

Considering Dave is the second person that did not find the huge commit message helpful, can we please limit the commit message to be about the actual code and not the entire series?

I thought we said that it was worth while making this change in v5?

Right, please minimize patch #1's commit log to just what it is doing, etc, and leave the rest of the rationale in the 0/N cover letter.

Signature · 1 line
Kees Cook
author
#13 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 29 lines · Kees Cook
Quoted 27 lines · Liam R. Howlett
Quoted 25 lines · Kees Cook
Quoted 11 lines · Dave Hansen
Quoted 10 lines · Jeff Xu

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Quoted 8 lines
Quoted 2 lines

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

That logic is reasonable. But it's different from the _vast_ majority of other flags.

So what justifies VM_SEALED being so different? It's leading to pretty objectively ugly code in this series.

Note that VM_SEALED is the "is this VMA sealed?" bit itself. The define for "should we perform system mapping sealing?" is intentionally separate here, so that it can be Kconfig and per-arch toggled, etc.

Quoted 9 lines
Quoted 5 lines

Considering Dave is the second person that did not find the huge commit message helpful, can we please limit the commit message to be about the actual code and not the entire series?

I thought we said that it was worth while making this change in v5?

Right, please minimize patch #1's commit log to just what it is doing, etc, and leave the rest of the rationale in the 0/N cover letter.

Sure.

Quoted 2 lines

--
Kees Cook

#14 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

In reply to Jeff Xu
Quoted 29 lines · Jeff Xu
Quoted 28 lines · Dave Hansen

include/linux/mm.h int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *st · line 4166

Quoted 8 lines · On 2/24/25 09:45, [email protected] wrote:
include/linux/mm.h +8 -0
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_NONE
+#endif

This ends up looking pretty wonky in practice:

Review

Quoted 2 lines
(quoted diff) +2 -0
+     vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+     vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;

because MSEAL_SYSTEM_MAPPINGS_VM_FLAG is so much different from the other ones.

Would it really hurt to have

#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)

(quoted diff) +2 -0
+#else
+#define VM_SEALED       VM_NONE
 #endif
Quoted 7 lines
Quoted 2 lines

?

VM_SEALED isn't defined in 32-bit systems, and mseal.c isn't part of the build. This is intentional. Any 32-bit code trying to use the sealing function or the VM_SEALED flag will immediately fail compilation. This makes it easier to identify incorrect usage.

The reason that two #defines are needed is because you can have mseal enabled while not sealing system mappings, so for this to be clean we need two defines.

However MSEAL_SYSTEM_MAPPINGS_VM_FLAG, is _way_ too long, in my opinion. Keeping with "VM_SEALED" I'd suggest "VM_SYSTEM_SEALED".

Quoted 2 lines

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

third_party?

Quoted 7 lines

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

I don't think it is reasonable to insist on doing things differently in the kernel because you have external tests that would need updating. These things can change independently, so I don't think this is a valid argument.

If these are upstream tests, and we need these tests to work then they can be fixed.

Quoted 3 lines

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

Thanks,
Liam

author
#15 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 43 lines · Liam R. Howlett
Quoted 29 lines · Jeff Xu
Quoted 28 lines · Dave Hansen

include/linux/mm.h int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *st · line 4166

Quoted 8 lines · On 2/24/25 09:45, [email protected] wrote:
include/linux/mm.h +8 -0
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_NONE
+#endif

This ends up looking pretty wonky in practice:

Review

Quoted 2 lines
(quoted diff) +2 -0
+     vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+     vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;

because MSEAL_SYSTEM_MAPPINGS_VM_FLAG is so much different from the other ones.

Would it really hurt to have

#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)

(quoted diff) +2 -0
+#else
+#define VM_SEALED       VM_NONE
 #endif
Quoted 7 lines
Quoted 2 lines

?

VM_SEALED isn't defined in 32-bit systems, and mseal.c isn't part of the build. This is intentional. Any 32-bit code trying to use the sealing function or the VM_SEALED flag will immediately fail compilation. This makes it easier to identify incorrect usage.

The reason that two #defines are needed is because you can have mseal enabled while not sealing system mappings, so for this to be clean we need two defines.

Quoted 8 lines

However MSEAL_SYSTEM_MAPPINGS_VM_FLAG, is _way_ too long, in my opinion. Keeping with "VM_SEALED" I'd suggest "VM_SYSTEM_SEALED".

Quoted 2 lines

For example:
Consider the case below in src/third_party/kernel/v6.6/fs/proc/task_mmu.c,

third_party?

Sorry, I pasted the code path from ChromeOS code base, it is actually in the kernel itself.

fs/proc/task_mmu.c

Quoted 8 lines
Quoted 7 lines

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

Quoted 8 lines

I don't think it is reasonable to insist on doing things differently in the kernel because you have external tests that would need updating. These things can change independently, so I don't think this is a valid argument.

If these are upstream tests, and we need these tests to work then they can be fixed.

As above, this is actually kernel code, not test.

-Jeff

Quoted 6 lines
Quoted 3 lines

Please note, this has been like this since the first version of mseal() RFC patch, and I prefer to keep it this way.

Thanks,
Liam

#16 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

* Jeff Xu <[email protected]> [250224 14:07]:
...

Quoted 13 lines
Quoted 13 lines
Quoted 7 lines

#ifdef CONFIG_64BIT
[ilog2(VM_SEALED)] = "sl",
#endif

Redefining VM_SEALED to VM_NONE for 32 bit won't detect the problem in case that "#ifdef CONFIG_64BIT" line is missing.

I don't think it is reasonable to insist on doing things differently in the kernel because you have external tests that would need updating. These things can change independently, so I don't think this is a valid argument.

Quoted 4 lines
Quoted 3 lines

If these are upstream tests, and we need these tests to work then they can be fixed.

As above, this is actually kernel code, not test.

Okay, so then they could be easily fixed to work with changing the flags and it would transparently function in your ChromeOS code base. That's a good way of doing things.

It doesn't make sense here since, as stated in this thread, we need two defines. But it does mean we are less locked into how this functions and it could change later, if needed.

Also, do we need something like the above test for VM_SEALED_SYS?

Thanks,
Liam

author
#17 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 3 lines · Liam R. Howlett

Also, do we need something like the above test for VM_SEALED_SYS?

Do you mean adding selftest for sealing vdso ? or test the VM_SEALED_SYS macro in 32 bit vs 64 bits ?

CONFIG_MSEAL_SYSTEM_MAPPINGS is by default disabled. I'm not sure about the common practice here.

I also don't know how to detect CONFIG_MSEAL_SYSTEM_MAPPINGS from selftest, that is needed for the selftest.

-Jeff

Quoted 3 lines

Thanks,
Liam

#18 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 5 lines · Jeff Xu
Quoted 3 lines · Liam R. Howlett

Also, do we need something like the above test for VM_SEALED_SYS?

Quoted 8 lines

Do you mean adding selftest for sealing vdso ? or test the VM_SEALED_SYS macro in 32 bit vs 64 bits ?

CONFIG_MSEAL_SYSTEM_MAPPINGS is by default disabled. I'm not sure about the common practice here.

I also don't know how to detect CONFIG_MSEAL_SYSTEM_MAPPINGS from selftest, that is needed for the selftest.

Looking more into this, I think it's fine without anything in there changing.

Thanks,
Liam

author
#19 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

In reply to Liam R. Howlett
Quoted 39 lines · Liam R. Howlett
Quoted 29 lines · Jeff Xu
Quoted 28 lines · Dave Hansen

include/linux/mm.h int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *st · line 4166

Quoted 8 lines · On 2/24/25 09:45, [email protected] wrote:
include/linux/mm.h +8 -0
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_NONE
+#endif

This ends up looking pretty wonky in practice:

Review

Quoted 2 lines
(quoted diff) +2 -0
+     vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+     vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;

because MSEAL_SYSTEM_MAPPINGS_VM_FLAG is so much different from the other ones.

Would it really hurt to have

#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)

(quoted diff) +2 -0
+#else
+#define VM_SEALED       VM_NONE
 #endif
Quoted 7 lines
Quoted 2 lines

?

VM_SEALED isn't defined in 32-bit systems, and mseal.c isn't part of the build. This is intentional. Any 32-bit code trying to use the sealing function or the VM_SEALED flag will immediately fail compilation. This makes it easier to identify incorrect usage.

Quoted 7 lines

The reason that two #defines are needed is because you can have mseal enabled while not sealing system mappings, so for this to be clean we need two defines.

However MSEAL_SYSTEM_MAPPINGS_VM_FLAG, is _way_ too long, in my opinion. Keeping with "VM_SEALED" I'd suggest "VM_SYSTEM_SEALED".

How about MSEAL_SYSTME_MAPPINGS as Kees suggested ?

The VM_SYSTEM_SEALED doesn't have the MSEAL key or the MAPPING, so it might take longer for the new reader to understand what it is.

-Jeff

#20 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 45 lines · Jeff Xu
Quoted 43 lines · Liam R. Howlett
Quoted 29 lines · Jeff Xu
Quoted 28 lines · Dave Hansen

include/linux/mm.h int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *st · line 4166

Quoted 8 lines · On 2/24/25 09:45, [email protected] wrote:
include/linux/mm.h +8 -0
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_NONE
+#endif

This ends up looking pretty wonky in practice:

Review

Quoted 2 lines
(quoted diff) +2 -0
+     vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+     vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;

because MSEAL_SYSTEM_MAPPINGS_VM_FLAG is so much different from the other ones.

Would it really hurt to have

#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)

(quoted diff) +2 -0
+#else
+#define VM_SEALED       VM_NONE
 #endif
Quoted 7 lines
Quoted 2 lines

?

VM_SEALED isn't defined in 32-bit systems, and mseal.c isn't part of the build. This is intentional. Any 32-bit code trying to use the sealing function or the VM_SEALED flag will immediately fail compilation. This makes it easier to identify incorrect usage.

The reason that two #defines are needed is because you can have mseal enabled while not sealing system mappings, so for this to be clean we need two defines.

Quoted 7 lines
Quoted 3 lines

However MSEAL_SYSTEM_MAPPINGS_VM_FLAG, is _way_ too long, in my opinion. Keeping with "VM_SEALED" I'd suggest "VM_SYSTEM_SEALED".

How about MSEAL_SYSTME_MAPPINGS as Kees suggested ?

The VM_SYSTEM_SEALED doesn't have the MSEAL key or the MAPPING, so it might take longer for the new reader to understand what it is.

I think to address Dave's concern, it should start with "VM_". We use "SEAL" already with VM_SEALED, so the "M" in "MSEAL" may be redundant, and to clarify the system mapping, how avout VM_SEAL_SYSMAP ? That capture's, hopefully, Dave, Liam, and your thoughts about the naming?

Signature · 1 line
Kees Cook
author
#21 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 52 lines · Kees Cook
Quoted 50 lines · Jeff Xu
Quoted 39 lines · Liam R. Howlett
Quoted 29 lines · Jeff Xu
Quoted 28 lines · Dave Hansen

include/linux/mm.h int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *st · line 4166

Quoted 8 lines · On 2/24/25 09:45, [email protected] wrote:
include/linux/mm.h +8 -0
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_NONE
+#endif

This ends up looking pretty wonky in practice:

Review

Quoted 2 lines
(quoted diff) +2 -0
+     vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+     vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;

because MSEAL_SYSTEM_MAPPINGS_VM_FLAG is so much different from the other ones.

Would it really hurt to have

#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)

(quoted diff) +2 -0
+#else
+#define VM_SEALED       VM_NONE
 #endif
Quoted 7 lines
Quoted 2 lines

?

VM_SEALED isn't defined in 32-bit systems, and mseal.c isn't part of the build. This is intentional. Any 32-bit code trying to use the sealing function or the VM_SEALED flag will immediately fail compilation. This makes it easier to identify incorrect usage.

Quoted 7 lines

The reason that two #defines are needed is because you can have mseal enabled while not sealing system mappings, so for this to be clean we need two defines.

However MSEAL_SYSTEM_MAPPINGS_VM_FLAG, is _way_ too long, in my opinion. Keeping with "VM_SEALED" I'd suggest "VM_SYSTEM_SEALED".

How about MSEAL_SYSTME_MAPPINGS as Kees suggested ?

Quoted 8 lines
Quoted 2 lines

The VM_SYSTEM_SEALED doesn't have the MSEAL key or the MAPPING, so it might take longer for the new reader to understand what it is.

I think to address Dave's concern, it should start with "VM_". We use "SEAL" already with VM_SEALED, so the "M" in "MSEAL" may be redundant, and to clarify the system mapping, how avout VM_SEAL_SYSMAP ? That capture's, hopefully, Dave, Liam, and your thoughts about the naming?

Liam had a comment in the previous version, asking everything related with mseal() to have the MSEAL keyword, that is why KCONFIG change has MSEAL.

How about VM_MSEAL_SYSMAP ?

-Jeff

Quoted 2 lines

--
Kees Cook

#22 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 61 lines · Jeff Xu
Quoted 52 lines · Kees Cook
Quoted 50 lines · Jeff Xu
Quoted 39 lines · Liam R. Howlett
Quoted 29 lines · Jeff Xu
Quoted 28 lines · Dave Hansen

Review

Quoted 8 lines · On 2/24/25 09:45, [email protected] wrote:
(quoted diff) +8 -0
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_NONE
+#endif

This ends up looking pretty wonky in practice:

Review

Quoted 2 lines
(quoted diff) +2 -0
+     vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+     vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;

because MSEAL_SYSTEM_MAPPINGS_VM_FLAG is so much different from the other ones.

Would it really hurt to have

#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)

(quoted diff) +2 -0
+#else
+#define VM_SEALED       VM_NONE
 #endif
Quoted 7 lines
Quoted 2 lines

?

VM_SEALED isn't defined in 32-bit systems, and mseal.c isn't part of the build. This is intentional. Any 32-bit code trying to use the sealing function or the VM_SEALED flag will immediately fail compilation. This makes it easier to identify incorrect usage.

Quoted 7 lines

The reason that two #defines are needed is because you can have mseal enabled while not sealing system mappings, so for this to be clean we need two defines.

However MSEAL_SYSTEM_MAPPINGS_VM_FLAG, is _way_ too long, in my opinion. Keeping with "VM_SEALED" I'd suggest "VM_SYSTEM_SEALED".

How about MSEAL_SYSTME_MAPPINGS as Kees suggested ?

Quoted 8 lines
Quoted 2 lines

The VM_SYSTEM_SEALED doesn't have the MSEAL key or the MAPPING, so it might take longer for the new reader to understand what it is.

I think to address Dave's concern, it should start with "VM_". We use "SEAL" already with VM_SEALED, so the "M" in "MSEAL" may be redundant, and to clarify the system mapping, how avout VM_SEAL_SYSMAP ? That capture's, hopefully, Dave, Liam, and your thoughts about the naming?

Quoted 5 lines

Liam had a comment in the previous version, asking everything related with mseal() to have the MSEAL keyword, that is why KCONFIG change has MSEAL.

How about VM_MSEAL_SYSMAP ?

I don't recall if it was this set or previous ones, but seal is becoming overloaded and having mseal would have been good for this one.

VM_MSEAL does gain more greping, but since we have VM_SEALED, VM_SEAL_SYSMAP is going to show up on VM_SEAL grep, but not VM_SEALED greps. Maybe VM_SEALED_SYSMAP would be better for searching.

Thanks,
Liam

author
#23 lore raw

Re: [PATCH v6 1/7] mseal, system mappings: kernel config and header change

Quoted 67 lines · Liam R. Howlett
Quoted 65 lines · Jeff Xu
Quoted 52 lines · Kees Cook
Quoted 50 lines · Jeff Xu
Quoted 39 lines · Liam R. Howlett
Quoted 29 lines · Jeff Xu
Quoted 28 lines · Dave Hansen

Review

Quoted 8 lines · On 2/24/25 09:45, [email protected] wrote:
(quoted diff) +8 -0
+/*
+ * mseal of userspace process's system mappings.
+ */
+#ifdef CONFIG_MSEAL_SYSTEM_MAPPINGS
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_SEALED
+#else
+#define MSEAL_SYSTEM_MAPPINGS_VM_FLAG        VM_NONE
+#endif

This ends up looking pretty wonky in practice:

Review

Quoted 2 lines
(quoted diff) +2 -0
+     vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+     vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;

because MSEAL_SYSTEM_MAPPINGS_VM_FLAG is so much different from the other ones.

Would it really hurt to have

#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
#define VM_SEALED _BITUL(63)

(quoted diff) +2 -0
+#else
+#define VM_SEALED       VM_NONE
 #endif
Quoted 7 lines
Quoted 2 lines

?

VM_SEALED isn't defined in 32-bit systems, and mseal.c isn't part of the build. This is intentional. Any 32-bit code trying to use the sealing function or the VM_SEALED flag will immediately fail compilation. This makes it easier to identify incorrect usage.

Quoted 7 lines

The reason that two #defines are needed is because you can have mseal enabled while not sealing system mappings, so for this to be clean we need two defines.

However MSEAL_SYSTEM_MAPPINGS_VM_FLAG, is _way_ too long, in my opinion. Keeping with "VM_SEALED" I'd suggest "VM_SYSTEM_SEALED".

How about MSEAL_SYSTME_MAPPINGS as Kees suggested ?

Quoted 8 lines
Quoted 2 lines

The VM_SYSTEM_SEALED doesn't have the MSEAL key or the MAPPING, so it might take longer for the new reader to understand what it is.

I think to address Dave's concern, it should start with "VM_". We use "SEAL" already with VM_SEALED, so the "M" in "MSEAL" may be redundant, and to clarify the system mapping, how avout VM_SEAL_SYSMAP ? That capture's, hopefully, Dave, Liam, and your thoughts about the naming?

Liam had a comment in the previous version, asking everything related with mseal() to have the MSEAL keyword, that is why KCONFIG change has MSEAL.

Quoted 9 lines
Quoted 1 line

How about VM_MSEAL_SYSMAP ?

I don't recall if it was this set or previous ones, but seal is becoming overloaded and having mseal would have been good for this one.

VM_MSEAL does gain more greping, but since we have VM_SEALED, VM_SEAL_SYSMAP is going to show up on VM_SEAL grep, but not VM_SEALED greps. Maybe VM_SEALED_SYSMAP would be better for searching.

OK, I will change to VM_SEALED_SYSMAP

-Jeff

Quoted 4 lines

Thanks,
Liam

#24 lore raw

PATCH v6 2/7 selftests: x86: test_mremap_vdso: skip if vdso is msealed

In reply to [email protected]

From: Jeff Xu <[email protected]>

Add code to detect if the vdso is memory sealed, skip the test if it is.

---
 .../testing/selftests/x86/test_mremap_vdso.c  | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/testing/selftests/x86/test_mremap_vdso.c +38 -0
index d53959e03593..c68077c56b22 100644
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
+#include <stdbool.h>
 
 #include <sys/mman.h>
 #include <sys/auxv.h>
@@ -55,13 +56,50 @@ static int try_to_remap(void *vdso_addr, unsigned long size)
 
 }
 
+#define VDSO_NAME "[vdso]"
+#define VMFLAGS "VmFlags:"
+#define MSEAL_FLAGS "sl"
+#define MAX_LINE_LEN 512
+
+bool vdso_sealed(FILE *maps)
+{
+	char line[MAX_LINE_LEN];
+	bool has_vdso = false;
+
+	while (fgets(line, sizeof(line), maps)) {
+		if (strstr(line, VDSO_NAME))
+			has_vdso = true;
+
+		if (has_vdso && !strncmp(line, VMFLAGS, strlen(VMFLAGS))) {
+			if (strstr(line, MSEAL_FLAGS))
+				return true;
+
+			return false;
+		}
+	}
+
+	return false;
+}
+
 int main(int argc, char **argv, char **envp)
 {
 	pid_t child;
+	FILE *maps;
 
 	ksft_print_header();
 	ksft_set_plan(1);
 
+	maps = fopen("/proc/self/smaps", "r");
+	if (!maps) {
+		ksft_test_result_skip("Could not open /proc/self/smaps\n");
+		return 0;
+	}
+
+	if (vdso_sealed(maps)) {
+		ksft_test_result_skip("vdso is sealed\n");
+		return 0;
+	}
+
 	child = fork();
 	if (child == -1)
 		ksft_exit_fail_msg("failed to fork (%d): %m\n", errno);
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
Reviewed-by on v6 2/7
#25 lore raw

Re: [PATCH v6 2/7] selftests: x86: test_mremap_vdso: skip if vdso is msealed

Quoted 6 lines · On Mon, Feb 24, 2025 at 05:45:08PM +0000, [email protected] wrote:

From: Jeff Xu <[email protected]>

Add code to detect if the vdso is memory sealed, skip the test if it is.

Thanks, after my full 360 on reading this code, I'm back to where I was
originally: it looks good to me. :)

Signature · 1 line
Kees Cook
#26 lore raw

Re: [PATCH v6 2/7] selftests: x86: test_mremap_vdso: skip if vdso is msealed

In reply to [email protected]
Quoted 4 lines · * [email protected] <[email protected]> [250224 12:45]:

From: Jeff Xu <[email protected]>

Add code to detect if the vdso is memory sealed, skip the test if it is.

It also skips the test if fopen fails on smaps, but maybe that's super rare?

Quoted 48 lines
---
 .../testing/selftests/x86/test_mremap_vdso.c  | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/testing/selftests/x86/test_mremap_vdso.c +26 -0
index d53959e03593..c68077c56b22 100644
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
+#include <stdbool.h>
 
 #include <sys/mman.h>
 #include <sys/auxv.h>
@@ -55,13 +56,50 @@ static int try_to_remap(void *vdso_addr, unsigned long size)
 
 }
 
+#define VDSO_NAME "[vdso]"
+#define VMFLAGS "VmFlags:"
+#define MSEAL_FLAGS "sl"
+#define MAX_LINE_LEN 512
+
+bool vdso_sealed(FILE *maps)
+{
+	char line[MAX_LINE_LEN];
+	bool has_vdso = false;
+
+	while (fgets(line, sizeof(line), maps)) {
+		if (strstr(line, VDSO_NAME))
+			has_vdso = true;
+
+		if (has_vdso && !strncmp(line, VMFLAGS, strlen(VMFLAGS))) {
+			if (strstr(line, MSEAL_FLAGS))
+				return true;
+
+			return false;
+		}
+	}
+
+	return false;
+}
+
 int main(int argc, char **argv, char **envp)

tools/testing/selftests/x86/test_mremap_vdso.c static int try_to_remap(void *vdso_addr, unsigned long size) · line 94

Quoted 10 lines
tools/testing/selftests/x86/test_mremap_vdso.c +4 -0
 {
 	pid_t child;
+	FILE *maps;
 
 	ksft_print_header();
 	ksft_set_plan(1);
 
+	maps = fopen("/proc/self/smaps", "r");
+	if (!maps) {
+		ksft_test_result_skip("Could not open /proc/self/smaps\n");

fork() below prints errno, should this also print errno?

tools/testing/selftests/x86/test_mremap_vdso.c static int try_to_remap(void *vdso_addr, unsigned long size) · line 95

Quoted 1 line
tools/testing/selftests/x86/test_mremap_vdso.c +1 -0
+		return 0;

I guess the logic here is that you might fail later because it's sealed but you don't know? Is this rare enough not to matter?

tools/testing/selftests/x86/test_mremap_vdso.c static int try_to_remap(void *vdso_addr, unsigned long size) · line 102

Quoted 7 lines
tools/testing/selftests/x86/test_mremap_vdso.c +7 -0
+	}
+
+	if (vdso_sealed(maps)) {
+		ksft_test_result_skip("vdso is sealed\n");
+		return 0;
+	}
+

This file also has an #ifdef __i386__ later, Using it here would prevent unnecessary scanning of the maps file. Probably not a big deal?

Do you need to close the maps file?

Quoted 6 lines
tools/testing/selftests/x86/test_mremap_vdso.c +0 -0
 	child = fork();
 	if (child == -1)
 		ksft_exit_fail_msg("failed to fork (%d): %m\n", errno);
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
author
#27 lore raw

Re: [PATCH v6 2/7] selftests: x86: test_mremap_vdso: skip if vdso is msealed

Quoted 10 lines · Liam R. Howlett
Quoted 4 lines · * [email protected] <[email protected]> [250224 12:45]:

From: Jeff Xu <[email protected]>

Add code to detect if the vdso is memory sealed, skip the test if it is.

It also skips the test if fopen fails on smaps, but maybe that's super rare?

If we can't access /proc/pid/smaps, that's an "environment" issue unrelated to this test, therefore skip().

Quoted 52 lines
Quoted 52 lines
---
 .../testing/selftests/x86/test_mremap_vdso.c  | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/testing/selftests/x86/test_mremap_vdso.c +27 -0
index d53959e03593..c68077c56b22 100644
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
+#include <stdbool.h>
 
 #include <sys/mman.h>
 #include <sys/auxv.h>
@@ -55,13 +56,50 @@ static int try_to_remap(void *vdso_addr, unsigned long size)
 
 }
 
+#define VDSO_NAME "[vdso]"
+#define VMFLAGS "VmFlags:"
+#define MSEAL_FLAGS "sl"
+#define MAX_LINE_LEN 512
+
+bool vdso_sealed(FILE *maps)
+{
+     char line[MAX_LINE_LEN];
+     bool has_vdso = false;
+
+     while (fgets(line, sizeof(line), maps)) {
+             if (strstr(line, VDSO_NAME))
+                     has_vdso = true;
+
+             if (has_vdso && !strncmp(line, VMFLAGS, strlen(VMFLAGS))) {
+                     if (strstr(line, MSEAL_FLAGS))
+                             return true;
+
+                     return false;
+             }
+     }
+
+     return false;
+}
+
 int main(int argc, char **argv, char **envp)
 {
      pid_t child;
+     FILE *maps;
 
Quoted 9 lines

tools/testing/selftests/x86/test_mremap_vdso.c static int try_to_remap(void *vdso_addr, unsigned long size) · line 94

Quoted 6 lines
tools/testing/selftests/x86/test_mremap_vdso.c +3 -0
      ksft_print_header();
      ksft_set_plan(1);
 
+     maps = fopen("/proc/self/smaps", "r");
+     if (!maps) {
+             ksft_test_result_skip("Could not open /proc/self/smaps\n");

fork() below prints errno, should this also print errno?

Sure.

Quoted 5 lines

tools/testing/selftests/x86/test_mremap_vdso.c static int try_to_remap(void *vdso_addr, unsigned long size) · line 95

Quoted 1 line
tools/testing/selftests/x86/test_mremap_vdso.c +1 -0
+             return 0;

I guess the logic here is that you might fail later because it's sealed but you don't know? Is this rare enough not to matter?

yes. We should check the "sl" flag of vdso before continuing, or the results will be unpredictable.

Android currently includes this selftest. In addition, you or someone commented that the selftest framework can randomly turn on kernel config and run selftest, so it is necessary to add this check to skip.

Quoted 11 lines

tools/testing/selftests/x86/test_mremap_vdso.c static int try_to_remap(void *vdso_addr, unsigned long size) · line 102

Quoted 7 lines
tools/testing/selftests/x86/test_mremap_vdso.c +7 -0
+     }
+
+     if (vdso_sealed(maps)) {
+             ksft_test_result_skip("vdso is sealed\n");
+             return 0;
+     }
+

This file also has an #ifdef __i386__ later, Using it here would prevent unnecessary scanning of the maps file. Probably not a big deal?

Quoted 2 lines

Do you need to close the maps file?

OK, I will add close for good coding practice.

Thanks
-Jeff

#28 lore raw

PATCH v6 3/7 mseal, system mappings: enable x86-64

In reply to [email protected]

From: Jeff Xu <[email protected]>

Provide support for CONFIG_MSEAL_SYSTEM_MAPPINGS on x86-64, covering the vdso, vvar, vvar_vclock.

Production release testing passes on Android and Chrome OS.

---
 arch/x86/Kconfig          |  1 +
 arch/x86/entry/vdso/vma.c | 16 ++++++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)
arch/x86/Kconfig +1 -0
index 87198d957e2f..8fa17032ca46 100644
@@ -26,6 +26,7 @@ config X86_64
 	depends on 64BIT
 	# Options that are inherently 64-bit kernel only:
 	select ARCH_HAS_GIGANTIC_PAGE
+	select ARCH_HAS_MSEAL_SYSTEM_MAPPINGS
 	select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
 	select ARCH_SUPPORTS_PER_VMA_LOCK
 	select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE
arch/x86/entry/vdso/vma.c +10 -6
index 39e6efc1a9ca..54677964d0b5 100644
@@ -247,6 +247,7 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *vma;
 	unsigned long text_start;
+	unsigned long vm_flags;
 	int ret = 0;
 
 	if (mmap_write_lock_killable(mm))
@@ -264,11 +265,12 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
 	/*
 	 * MAYWRITE to allow gdb to COW and set breakpoints
 	 */
+	vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	vma = _install_special_mapping(mm,
 				       text_start,
 				       image->size,
-				       VM_READ|VM_EXEC|
-				       VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
+				       vm_flags,
 				       &vdso_mapping);
 
 	if (IS_ERR(vma)) {
@@ -276,11 +278,12 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
 		goto up_fail;
 	}
 
+	vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	vma = _install_special_mapping(mm,
 				       addr,
 				       (__VVAR_PAGES - VDSO_NR_VCLOCK_PAGES) * PAGE_SIZE,
-				       VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|
-				       VM_PFNMAP,
+				       vm_flags,
 				       &vvar_mapping);
 
 	if (IS_ERR(vma)) {
@@ -289,11 +292,12 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
 		goto up_fail;
 	}
 
+	vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	vma = _install_special_mapping(mm,
 				       addr + (__VVAR_PAGES - VDSO_NR_VCLOCK_PAGES) * PAGE_SIZE,
 				       VDSO_NR_VCLOCK_PAGES * PAGE_SIZE,
-				       VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|
-				       VM_PFNMAP,
+				       vm_flags,
 				       &vvar_vclock_mapping);
 
 	if (IS_ERR(vma)) {
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#29 lore raw

Re: [PATCH v6 3/7] mseal, system mappings: enable x86-64

Quoted 39 lines · * [email protected] <[email protected]> [250224 12:45]:

From: Jeff Xu <[email protected]>

Provide support for CONFIG_MSEAL_SYSTEM_MAPPINGS on x86-64, covering the vdso, vvar, vvar_vclock.

Production release testing passes on Android and Chrome OS.

---
 arch/x86/Kconfig          |  1 +
 arch/x86/entry/vdso/vma.c | 16 ++++++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)
arch/x86/Kconfig +1 -0
index 87198d957e2f..8fa17032ca46 100644
@@ -26,6 +26,7 @@ config X86_64
 	depends on 64BIT
 	# Options that are inherently 64-bit kernel only:
 	select ARCH_HAS_GIGANTIC_PAGE
+	select ARCH_HAS_MSEAL_SYSTEM_MAPPINGS
 	select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
 	select ARCH_SUPPORTS_PER_VMA_LOCK
 	select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE
arch/x86/entry/vdso/vma.c +1 -0
index 39e6efc1a9ca..54677964d0b5 100644
@@ -247,6 +247,7 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *vma;
 	unsigned long text_start;
+	unsigned long vm_flags;
 	int ret = 0;
 
 	if (mmap_write_lock_killable(mm))
@@ -264,11 +265,12 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
 	/*

arch/x86/entry/vdso/vma.c static int map_vdso(const struct vdso_image *image, unsigned long addr) · line 273

Quoted 10 lines
arch/x86/entry/vdso/vma.c +3 -2
 	 * MAYWRITE to allow gdb to COW and set breakpoints
 	 */
+	vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	vma = _install_special_mapping(mm,
 				       text_start,
 				       image->size,
-				       VM_READ|VM_EXEC|
-				       VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
+				       vm_flags,

Why not just | VM_SEALED_SYSMAP here, and everywhere else?

Quoted 36 lines
arch/x86/entry/vdso/vma.c +6 -4
 				       &vdso_mapping);
 
 	if (IS_ERR(vma)) {
@@ -276,11 +278,12 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
 		goto up_fail;
 	}
 
+	vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	vma = _install_special_mapping(mm,
 				       addr,
 				       (__VVAR_PAGES - VDSO_NR_VCLOCK_PAGES) * PAGE_SIZE,
-				       VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|
-				       VM_PFNMAP,
+				       vm_flags,
 				       &vvar_mapping);
 
 	if (IS_ERR(vma)) {
@@ -289,11 +292,12 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
 		goto up_fail;
 	}
 
+	vm_flags = VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|VM_PFNMAP;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	vma = _install_special_mapping(mm,
 				       addr + (__VVAR_PAGES - VDSO_NR_VCLOCK_PAGES) * PAGE_SIZE,
 				       VDSO_NR_VCLOCK_PAGES * PAGE_SIZE,
-				       VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|
-				       VM_PFNMAP,
+				       vm_flags,
 				       &vvar_vclock_mapping);
 
 	if (IS_ERR(vma)) {
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#30 lore raw

PATCH v6 4/7 mseal, system mappings: enable arm64

In reply to [email protected]

From: Jeff Xu <[email protected]>

Provide support for CONFIG_MSEAL_SYSTEM_MAPPINGS on arm64, covering the vdso, vvar, and compat-mode vectors and sigpage mappings.

Production release testing passes on Android and Chrome OS.

---
 arch/arm64/Kconfig       |  1 +
 arch/arm64/kernel/vdso.c | 22 +++++++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)
arch/arm64/Kconfig +1 -0
index fcdd0ed3eca8..39202aa9a5af 100644
@@ -38,6 +38,7 @@ config ARM64
 	select ARCH_HAS_KEEPINITRD
 	select ARCH_HAS_MEMBARRIER_SYNC_CORE
 	select ARCH_HAS_MEM_ENCRYPT
+	select ARCH_HAS_MSEAL_SYSTEM_MAPPINGS
 	select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS
 	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
 	select ARCH_HAS_NONLEAF_PMD_YOUNG if ARM64_HAFT
arch/arm64/kernel/vdso.c +15 -7
index e8ed8e5b713b..fa3b85b7ff01 100644
@@ -183,6 +183,7 @@ static int __setup_additional_pages(enum vdso_abi abi,
 {
 	unsigned long vdso_base, vdso_text_len, vdso_mapping_len;
 	unsigned long gp_flags = 0;
+	unsigned long vm_flags;
 	void *ret;
 
 	BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES);
@@ -197,8 +198,10 @@ static int __setup_additional_pages(enum vdso_abi abi,
 		goto up_fail;
 	}
 
+	vm_flags = VM_READ|VM_MAYREAD|VM_PFNMAP;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	ret = _install_special_mapping(mm, vdso_base, VVAR_NR_PAGES * PAGE_SIZE,
-				       VM_READ|VM_MAYREAD|VM_PFNMAP,
+				       vm_flags,
 				       &vvar_map);
 	if (IS_ERR(ret))
 		goto up_fail;
@@ -208,9 +211,10 @@ static int __setup_additional_pages(enum vdso_abi abi,
 
 	vdso_base += VVAR_NR_PAGES * PAGE_SIZE;
 	mm->context.vdso = (void *)vdso_base;
+	vm_flags = VM_READ|VM_EXEC|gp_flags|VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	ret = _install_special_mapping(mm, vdso_base, vdso_text_len,
-				       VM_READ|VM_EXEC|gp_flags|
-				       VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
+				       vm_flags,
 				       vdso_info[abi].cm);
 	if (IS_ERR(ret))
 		goto up_fail;
@@ -326,6 +330,7 @@ arch_initcall(aarch32_alloc_vdso_pages);
 static int aarch32_kuser_helpers_setup(struct mm_struct *mm)
 {
 	void *ret;
+	unsigned long vm_flags;
 
 	if (!IS_ENABLED(CONFIG_KUSER_HELPERS))
 		return 0;
@@ -334,9 +339,10 @@ static int aarch32_kuser_helpers_setup(struct mm_struct *mm)
 	 * Avoid VM_MAYWRITE for compatibility with arch/arm/, where it's
 	 * not safe to CoW the page containing the CPU exception vectors.
 	 */
+	vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	ret = _install_special_mapping(mm, AARCH32_VECTORS_BASE, PAGE_SIZE,
-				       VM_READ | VM_EXEC |
-				       VM_MAYREAD | VM_MAYEXEC,
+				       vm_flags,
 				       &aarch32_vdso_maps[AA32_MAP_VECTORS]);
 
 	return PTR_ERR_OR_ZERO(ret);
@@ -345,6 +351,7 @@ static int aarch32_kuser_helpers_setup(struct mm_struct *mm)
 static int aarch32_sigreturn_setup(struct mm_struct *mm)
 {
 	unsigned long addr;
+	unsigned long vm_flags;
 	void *ret;
 
 	addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
@@ -357,9 +364,10 @@ static int aarch32_sigreturn_setup(struct mm_struct *mm)
 	 * VM_MAYWRITE is required to allow gdb to Copy-on-Write and
 	 * set breakpoints.
 	 */
+	vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	ret = _install_special_mapping(mm, addr, PAGE_SIZE,
-				       VM_READ | VM_EXEC | VM_MAYREAD |
-				       VM_MAYWRITE | VM_MAYEXEC,
+				       vm_flags,
 				       &aarch32_vdso_maps[AA32_MAP_SIGPAGE]);
 	if (IS_ERR(ret))
 		goto out;
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#31 lore raw

PATCH v6 5/7 mseal, system mappings: enable uml architecture

In reply to [email protected]

From: Jeff Xu <[email protected]>

Provide support for CONFIG_MSEAL_SYSTEM_MAPPINGS on UML, covering the vdso.

Testing passes on UML.

---
 arch/um/Kconfig        | 1 +
 arch/x86/um/vdso/vma.c | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/um/Kconfig +1 -0
index 18051b1cfce0..eb2d439a5334 100644
@@ -10,6 +10,7 @@ config UML
 	select ARCH_HAS_FORTIFY_SOURCE
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_HAS_KCOV
+	select ARCH_HAS_MSEAL_SYSTEM_MAPPINGS
 	select ARCH_HAS_STRNCPY_FROM_USER
 	select ARCH_HAS_STRNLEN_USER
 	select HAVE_ARCH_AUDITSYSCALL
arch/x86/um/vdso/vma.c +4 -2
index f238f7b33cdd..ee6d8a58f9f6 100644
@@ -54,6 +54,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 {
 	struct vm_area_struct *vma;
 	struct mm_struct *mm = current->mm;
+	unsigned long vm_flags;
 	static struct vm_special_mapping vdso_mapping = {
 		.name = "[vdso]",
 	};
@@ -65,9 +66,10 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 		return -EINTR;
 
 	vdso_mapping.pages = vdsop;
+	vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	vma = _install_special_mapping(mm, um_vdso_addr, PAGE_SIZE,
-		VM_READ|VM_EXEC|
-		VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
+		vm_flags,
 		&vdso_mapping);
 
 	mmap_write_unlock(mm);
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#32 lore raw

PATCH v6 6/7 mseal, system mappings: uprobe mapping

In reply to [email protected]

From: Jeff Xu <[email protected]>

Provide support to mseal the uprobe mapping.

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

---
 kernel/events/uprobes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/events/uprobes.c +4 -1
index 2ca797cbe465..c23ca39b81ac 100644
@@ -1662,6 +1662,7 @@ static const struct vm_special_mapping xol_mapping = {
 static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
 {
 	struct vm_area_struct *vma;
+	unsigned long vm_flags;
 	int ret;
 
 	if (mmap_write_lock_killable(mm))
@@ -1682,8 +1683,10 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
 		}
 	}
 
+	vm_flags = VM_EXEC|VM_MAYEXEC|VM_DONTCOPY|VM_IO;
+	vm_flags |= MSEAL_SYSTEM_MAPPINGS_VM_FLAG;
 	vma = _install_special_mapping(mm, area->vaddr, PAGE_SIZE,
-				VM_EXEC|VM_MAYEXEC|VM_DONTCOPY|VM_IO,
+				vm_flags,
 				&xol_mapping);
 	if (IS_ERR(vma)) {
 		ret = PTR_ERR(vma);
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#33 lore raw

PATCH v6 7/7 mseal, system mappings: update mseal.rst

In reply to [email protected]

From: Jeff Xu <[email protected]>

Update memory sealing documentation to include details about system mappings.

---
 Documentation/userspace-api/mseal.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/userspace-api/mseal.rst +7 -0
index 41102f74c5e2..10147281bf2d 100644
@@ -130,6 +130,13 @@ Use cases
 
 - Chrome browser: protect some security sensitive data structures.
 
+- System mappings:
+  If supported by an architecture (via CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS),
+  the CONFIG_MSEAL_SYSTEM_MAPPINGS seals system mappings, e.g. vdso, vvar,
+  uprobes, sigpage, vectors, etc. CHECKPOINT_RESTORE, UML, gVisor, rr are
+  known to relocate or unmap system mapping, therefore this config can't be
+  enabled universally.
+
 When not to use mseal
 =====================
 Applications can apply sealing to any virtual memory region from userspace,
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#35 lore raw

Re: [PATCH v6 7/7] mseal, system mappings: update mseal.rst

In reply to [email protected]
Quoted 15 lines · * [email protected] <[email protected]> [250224 12:45]:

From: Jeff Xu <[email protected]>

Update memory sealing documentation to include details about system mappings.

---
 Documentation/userspace-api/mseal.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/userspace-api/mseal.rst +0 -0
index 41102f74c5e2..10147281bf2d 100644

Documentation/userspace-api/mseal.rst Use cases · line 131

Quoted 2 lines
Documentation/userspace-api/mseal.rst +0 -0
@@ -130,6 +130,13 @@ Use cases
 
 - Chrome browser: protect some security sensitive data structures.

Did you mean to drop this line?

Quoted 14 lines
Documentation/userspace-api/mseal.rst +7 -0
+- System mappings:
+  If supported by an architecture (via CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS),
+  the CONFIG_MSEAL_SYSTEM_MAPPINGS seals system mappings, e.g. vdso, vvar,
+  uprobes, sigpage, vectors, etc. CHECKPOINT_RESTORE, UML, gVisor, rr are
+  known to relocate or unmap system mapping, therefore this config can't be
+  enabled universally.
+
 When not to use mseal
 =====================
 Applications can apply sealing to any virtual memory region from userspace,
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
author
#36 lore raw

Re: [PATCH v6 7/7] mseal, system mappings: update mseal.rst

Quoted 18 lines · Liam R. Howlett
Quoted 16 lines · * [email protected] <[email protected]> [250224 12:45]:

From: Jeff Xu <[email protected]>

Update memory sealing documentation to include details about system mappings.

---
 Documentation/userspace-api/mseal.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/userspace-api/mseal.rst +0 -0
index 41102f74c5e2..10147281bf2d 100644
@@ -130,6 +130,13 @@ Use cases
 
Quoted 4 lines

Documentation/userspace-api/mseal.rst Use cases · line 131

Quoted 1 line
Documentation/userspace-api/mseal.rst +0 -0
 - Chrome browser: protect some security sensitive data structures.

Did you mean to drop this line?

Ah, thank you for catching that.

-Jeff

Quoted 14 lines
Quoted 14 lines
Documentation/userspace-api/mseal.rst +7 -1
+- System mappings:
+  If supported by an architecture (via CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS),
+  the CONFIG_MSEAL_SYSTEM_MAPPINGS seals system mappings, e.g. vdso, vvar,
+  uprobes, sigpage, vectors, etc. CHECKPOINT_RESTORE, UML, gVisor, rr are
+  known to relocate or unmap system mapping, therefore this config can't be
+  enabled universally.
+
 When not to use mseal
 =====================
 Applications can apply sealing to any virtual memory region from userspace,
--

2.48.1.601.g30ceb7b040-goog

author
#37 lore raw

Re: [PATCH v6 7/7] mseal, system mappings: update mseal.rst

Quoted 21 lines · Jeff Xu
Quoted 18 lines · Liam R. Howlett
Quoted 16 lines · * [email protected] <[email protected]> [250224 12:45]:

From: Jeff Xu <[email protected]>

Update memory sealing documentation to include details about system mappings.

---
 Documentation/userspace-api/mseal.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/userspace-api/mseal.rst +0 -0
index 41102f74c5e2..10147281bf2d 100644
@@ -130,6 +130,13 @@ Use cases
 
Quoted 6 lines
Quoted 4 lines

Documentation/userspace-api/mseal.rst Use cases · line 131

Quoted 1 line
Documentation/userspace-api/mseal.rst +0 -0
 - Chrome browser: protect some security sensitive data structures.

Did you mean to drop this line?

Ah, thank you for catching that.

Actually, this isn't a problem here.
The "-" here is part of the text, for list, so that line is not dropped).

-Jeff

Quoted 17 lines

-Jeff

Quoted 14 lines
Quoted 14 lines
Documentation/userspace-api/mseal.rst +7 -1
+- System mappings:
+  If supported by an architecture (via CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS),
+  the CONFIG_MSEAL_SYSTEM_MAPPINGS seals system mappings, e.g. vdso, vvar,
+  uprobes, sigpage, vectors, etc. CHECKPOINT_RESTORE, UML, gVisor, rr are
+  known to relocate or unmap system mapping, therefore this config can't be
+  enabled universally.
+
 When not to use mseal
 =====================
 Applications can apply sealing to any virtual memory region from userspace,
--

2.48.1.601.g30ceb7b040-goog

#38 lore raw

Re: [PATCH v6 7/7] mseal, system mappings: update mseal.rst

In reply to [email protected]
Quoted 15 lines · On Mon, Feb 24, 2025 at 05:45:13PM +0000, [email protected] wrote:

From: Jeff Xu <[email protected]>

Update memory sealing documentation to include details about system mappings.

---
 Documentation/userspace-api/mseal.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/userspace-api/mseal.rst +0 -0
index 41102f74c5e2..10147281bf2d 100644

Documentation/userspace-api/mseal.rst Use cases · line 138

Quoted 9 lines
Documentation/userspace-api/mseal.rst +6 -0
@@ -130,6 +130,13 @@ Use cases
 
 - Chrome browser: protect some security sensitive data structures.
 
+- System mappings:
+  If supported by an architecture (via CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS),
+  the CONFIG_MSEAL_SYSTEM_MAPPINGS seals system mappings, e.g. vdso, vvar,
+  uprobes, sigpage, vectors, etc. CHECKPOINT_RESTORE, UML, gVisor, rr are
+  known to relocate or unmap system mapping, therefore this config can't be
+  enabled universally.

Thanks for adding this.

Similar comments to the Kconfig update - you are listing features that do not exist yet, please just list what you're doing, specifically, and avoid the vague 'etc.', we don't need to be vague.

As per the Kconfig comment - you need to be a lot more clear, I think you're duplicating the text from there to here, so again I suggest something like:

WARNING: This feature breaks programs which rely on relocating or
unmapping system mappings.

Known broken software at the time of writing includes CHECKPOINT_RESTORE, UML, gVisor and rr.

You also seem to be writing very little here, it's a documentation page, you can be as verbose as you like :)

You really need to add some more detail here in general - you aren't explaining why people would want to enable this, what you're mitigating, etc. from that you explain _why_ it doesn't work for some things.

You're also not mentioning architectural limitations here, for instance that you can only do this on arches that don't require VDSO relocation and listing known-good arches.

This is a documentation file, you can go wild :) the more information here the better.

WARNING
=======

Quoted 7 lines
Documentation/userspace-api/mseal.rst +1 -1
+
 When not to use mseal
 =====================
 Applications can apply sealing to any virtual memory region from userspace,
--

2.48.1.601.g30ceb7b040-goog

author
#39 lore raw

Re: [PATCH v6 7/7] mseal, system mappings: update mseal.rst

Quoted 29 lines · Lorenzo Stoakes
Quoted 15 lines · On Mon, Feb 24, 2025 at 05:45:13PM +0000, [email protected] wrote:

From: Jeff Xu <[email protected]>

Update memory sealing documentation to include details about system mappings.

---
 Documentation/userspace-api/mseal.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/userspace-api/mseal.rst +0 -0
index 41102f74c5e2..10147281bf2d 100644

Documentation/userspace-api/mseal.rst Use cases · line 138

Quoted 9 lines
Documentation/userspace-api/mseal.rst +6 -0
@@ -130,6 +130,13 @@ Use cases
 
 - Chrome browser: protect some security sensitive data structures.
 
+- System mappings:
+  If supported by an architecture (via CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS),
+  the CONFIG_MSEAL_SYSTEM_MAPPINGS seals system mappings, e.g. vdso, vvar,
+  uprobes, sigpage, vectors, etc. CHECKPOINT_RESTORE, UML, gVisor, rr are
+  known to relocate or unmap system mapping, therefore this config can't be
+  enabled universally.

Thanks for adding this.

Quoted 4 lines

Similar comments to the Kconfig update - you are listing features that do not exist yet, please just list what you're doing, specifically, and avoid the vague 'etc.', we don't need to be vague.

OK, I will remove etc and list the known mappings here.

Quoted 9 lines

As per the Kconfig comment - you need to be a lot more clear, I think you're duplicating the text from there to here, so again I suggest something like:

WARNING: This feature breaks programs which rely on relocating or
unmapping system mappings.

Known broken software at the time of writing includes CHECKPOINT_RESTORE, UML, gVisor and rr.

Sure.

Quoted 7 lines

You also seem to be writing very little here, it's a documentation page, you can be as verbose as you like :)

You really need to add some more detail here in general - you aren't explaining why people would want to enable this, what you're mitigating, etc. from that you explain _why_ it doesn't work for some things.

The mseal.rst already includes below regarding the protection/mitigation.

Quoted 17 lines

You're also not mentioning architectural limitations here, for instance that you can only do this on arches that don't require VDSO relocation and listing known-good arches.

This is a documentation file, you can go wild :) the more information here the better.

WARNING
=======

Quoted 7 lines
Documentation/userspace-api/mseal.rst +1 -1
+
 When not to use mseal
 =====================
 Applications can apply sealing to any virtual memory region from userspace,
--

2.48.1.601.g30ceb7b040-goog

author
#40 lore raw

Re: [PATCH v6 7/7] mseal, system mappings: update mseal.rst

Quoted 41 lines · Jeff Xu
Quoted 29 lines · Lorenzo Stoakes
Quoted 15 lines · On Mon, Feb 24, 2025 at 05:45:13PM +0000, [email protected] wrote:

From: Jeff Xu <[email protected]>

Update memory sealing documentation to include details about system mappings.

---
 Documentation/userspace-api/mseal.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/userspace-api/mseal.rst +0 -0
index 41102f74c5e2..10147281bf2d 100644

Documentation/userspace-api/mseal.rst Use cases · line 138

Quoted 9 lines
Documentation/userspace-api/mseal.rst +6 -0
@@ -130,6 +130,13 @@ Use cases
 
 - Chrome browser: protect some security sensitive data structures.
 
+- System mappings:
+  If supported by an architecture (via CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS),
+  the CONFIG_MSEAL_SYSTEM_MAPPINGS seals system mappings, e.g. vdso, vvar,
+  uprobes, sigpage, vectors, etc. CHECKPOINT_RESTORE, UML, gVisor, rr are
+  known to relocate or unmap system mapping, therefore this config can't be
+  enabled universally.

Thanks for adding this.

Quoted 4 lines

Similar comments to the Kconfig update - you are listing features that do not exist yet, please just list what you're doing, specifically, and avoid the vague 'etc.', we don't need to be vague.

OK, I will remove etc and list the known mappings here.

Quoted 3 lines

As per the Kconfig comment - you need to be a lot more clear, I think you're duplicating the text from there to here, so again I suggest something like:

Quoted 15 lines
Quoted 6 lines

WARNING: This feature breaks programs which rely on relocating or
unmapping system mappings.

Known broken software at the time of writing includes CHECKPOINT_RESTORE, UML, gVisor and rr.

Sure.

Quoted 7 lines

You also seem to be writing very little here, it's a documentation page, you can be as verbose as you like :)

You really need to add some more detail here in general - you aren't explaining why people would want to enable this, what you're mitigating, etc. from that you explain _why_ it doesn't work for some things.

The mseal.rst already includes below regarding the protection/mitigation.

Memory sealing additionally protects the mapping itself against modifications. This 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. Memory sealing can automatically be applied by the runtime loader to seal .text and .rodata pages and applications can additionally seal security critical data at runtime.

I could copy some sections from cover-letter to here, specifically for special mappings.

Quoted 9 lines
Quoted 9 lines

You're also not mentioning architectural limitations here, for instance that you can only do this on arches that don't require VDSO relocation and listing known-good arches.

Sure, I will mention the architecture that has this enabled (x86,arm,uml) -- I don't think there is an architecture limitation though. mseal is a software feature. The reason why other architectures don't have it is due to the fact that I don't have the HW for testing

Quoted 13 lines
Quoted 13 lines

This is a documentation file, you can go wild :) the more information here the better.

WARNING
=======

Quoted 7 lines
Documentation/userspace-api/mseal.rst +1 -1
+
 When not to use mseal
 =====================
 Applications can apply sealing to any virtual memory region from userspace,
--

2.48.1.601.g30ceb7b040-goog

#41 lore raw

Re: [PATCH v6 7/7] mseal, system mappings: update mseal.rst

Quoted 53 lines · Jeff Xu
Quoted 52 lines · Jeff Xu
Quoted 29 lines · Lorenzo Stoakes
Quoted 15 lines · On Mon, Feb 24, 2025 at 05:45:13PM +0000, [email protected] wrote:

From: Jeff Xu <[email protected]>

Update memory sealing documentation to include details about system mappings.

---
 Documentation/userspace-api/mseal.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/userspace-api/mseal.rst +0 -0
index 41102f74c5e2..10147281bf2d 100644

Documentation/userspace-api/mseal.rst Use cases · line 138

Quoted 9 lines
Documentation/userspace-api/mseal.rst +6 -0
@@ -130,6 +130,13 @@ Use cases
 
 - Chrome browser: protect some security sensitive data structures.
 
+- System mappings:
+  If supported by an architecture (via CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS),
+  the CONFIG_MSEAL_SYSTEM_MAPPINGS seals system mappings, e.g. vdso, vvar,
+  uprobes, sigpage, vectors, etc. CHECKPOINT_RESTORE, UML, gVisor, rr are
+  known to relocate or unmap system mapping, therefore this config can't be
+  enabled universally.

Thanks for adding this.

Quoted 4 lines

Similar comments to the Kconfig update - you are listing features that do not exist yet, please just list what you're doing, specifically, and avoid the vague 'etc.', we don't need to be vague.

OK, I will remove etc and list the known mappings here.

Quoted 9 lines

As per the Kconfig comment - you need to be a lot more clear, I think you're duplicating the text from there to here, so again I suggest something like:

WARNING: This feature breaks programs which rely on relocating or
unmapping system mappings.

Known broken software at the time of writing includes CHECKPOINT_RESTORE, UML, gVisor and rr.

Sure.

Quoted 3 lines

You also seem to be writing very little here, it's a documentation page, you can be as verbose as you like :)

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

You really need to add some more detail here in general - you aren't explaining why people would want to enable this, what you're mitigating, etc. from that you explain _why_ it doesn't work for some things.

The mseal.rst already includes below regarding the protection/mitigation.

But not specifically why you'd want to do that for system mappings.

I guess you mean it's _implied_ that it would be sensible to do this for system mappings and I suppose again I'm asking for emphasis on this

Quoted 9 lines

Memory sealing additionally protects the mapping itself against modifications. This 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. Memory sealing can automatically be applied by the runtime loader to seal .text and .rodata pages and applications can additionally seal security critical data at runtime.

Right, this is exactly the kind of thing you need but obviously adjusted to mention system mappings, and why they are especially problematic (again -at risk of sounding like a security idiot here :) - I'm guessing sand box breakout, rop, syscall, find a way to write, and un-sandboxed code now does unexpected stuff).

Quoted 3 lines

I could copy some sections from cover-letter to here, specifically for special mappings.

yeah that'd be good, while the cover letter will be copied in automatically by Andrew to the series, it's really nice to have it at a glance in docs for users who go to docs.kernel.org etc.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

You're also not mentioning architectural limitations here, for instance that you can only do this on arches that don't require VDSO relocation and listing known-good arches.

Quoted 5 lines

Sure, I will mention the architecture that has this enabled (x86,arm,uml) -- I don't think there is an architecture limitation though. mseal is a software feature. The reason why other architectures don't have it is due to the fact that I don't have the HW for testing

Yeah I mean just list the arches that you've tested, more or less.

Thanks!

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

This is a documentation file, you can go wild :) the more information here the better.

WARNING
=======

Quoted 7 lines
Documentation/userspace-api/mseal.rst +1 -1
+
 When not to use mseal
 =====================
 Applications can apply sealing to any virtual memory region from userspace,
--

2.48.1.601.g30ceb7b040-goog

#42 lore raw

Re: [PATCH v6 7/7] mseal, system mappings: update mseal.rst

In reply to Jeff Xu
Quoted 48 lines · Jeff Xu
Quoted 29 lines · Lorenzo Stoakes
Quoted 15 lines · On Mon, Feb 24, 2025 at 05:45:13PM +0000, [email protected] wrote:

From: Jeff Xu <[email protected]>

Update memory sealing documentation to include details about system mappings.

---
 Documentation/userspace-api/mseal.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/userspace-api/mseal.rst +0 -0
index 41102f74c5e2..10147281bf2d 100644

Documentation/userspace-api/mseal.rst Use cases · line 138

Quoted 9 lines
Documentation/userspace-api/mseal.rst +6 -0
@@ -130,6 +130,13 @@ Use cases
 
 - Chrome browser: protect some security sensitive data structures.
 
+- System mappings:
+  If supported by an architecture (via CONFIG_ARCH_HAS_MSEAL_SYSTEM_MAPPINGS),
+  the CONFIG_MSEAL_SYSTEM_MAPPINGS seals system mappings, e.g. vdso, vvar,
+  uprobes, sigpage, vectors, etc. CHECKPOINT_RESTORE, UML, gVisor, rr are
+  known to relocate or unmap system mapping, therefore this config can't be
+  enabled universally.

Thanks for adding this.

Quoted 4 lines

Similar comments to the Kconfig update - you are listing features that do not exist yet, please just list what you're doing, specifically, and avoid the vague 'etc.', we don't need to be vague.

OK, I will remove etc and list the known mappings here.

Quoted 9 lines

As per the Kconfig comment - you need to be a lot more clear, I think you're duplicating the text from there to here, so again I suggest something like:

WARNING: This feature breaks programs which rely on relocating or
unmapping system mappings.

Known broken software at the time of writing includes CHECKPOINT_RESTORE, UML, gVisor and rr.

Sure.

Quoted 8 lines
Quoted 7 lines

You also seem to be writing very little here, it's a documentation page, you can be as verbose as you like :)

You really need to add some more detail here in general - you aren't explaining why people would want to enable this, what you're mitigating, etc. from that you explain _why_ it doesn't work for some things.

The mseal.rst already includes below regarding the protection/mitigation.

Not for system sealing. Please add it even if you think it'd be duplicative. Thanks.

Quoted 22 lines
Quoted 22 lines

You're also not mentioning architectural limitations here, for instance that you can only do this on arches that don't require VDSO relocation and listing known-good arches.

This is a documentation file, you can go wild :) the more information here the better.

WARNING
=======

Quoted 7 lines
Documentation/userspace-api/mseal.rst +1 -1
+
 When not to use mseal
 =====================
 Applications can apply sealing to any virtual memory region from userspace,
--

2.48.1.601.g30ceb7b040-goog