Skip to contentSkip to conversation

seal system mappings

RFC PATCH Superseded [email protected] 4 participants 12 messages Oct 4, 2024 – Oct 11, 2024

Subsystems (11)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover seal system mappings

From: Jeff Xu <[email protected]>

Seal vdso, vvar, sigpage, uprobes and vsyscall.

Those mappings are readonly or executable only, sealing can protect them from ever changing during the life time of the process.

System mappings such as vdso, vvar, and sigpage (for arm) are generated by the kernel during program initialization. These mappings are designated as non-writable, and sealing them will prevent them from ever becoming writeable.

Unlike the aforementioned mappings, the uprobe mapping is not established during program startup. However, its lifetime is the same as the process's lifetime [1], thus sealable.

The vdso, vvar, sigpage, and uprobe mappings all invoke the _install_special_mapping() function. As no other mappings utilize this function, it is logical to incorporate sealing logic within _install_special_mapping(). This approach avoids the necessity of modifying code across various architecture-specific implementations.

The vsyscall mapping, which has its own initialization function, is sealed in the XONLY case, it seems to be the most common and secure case of using vsyscall.

It is important to note that the CHECKPOINT_RESTORE feature (CRIU) may alter the mapping of vdso, vvar, and sigpage during restore operations. Consequently, this feature cannot be universally enabled across all systems. To address this, a kernel configuration option has been introduced to enable or disable this functionality. I tested CONFIG_SEAL_SYSTEM_MAPPINGS_ALWAYS with ChromeOS, which doesn’t use CHECKPOINT_RESTORE, to verify the sealing works.

[1] https://lore.kernel.org/all/CABi2SkU9BRUnqf70-nksuMCQ+yyiWjo3fM4XkRkL-NrCZxYAyg@mail.gmail.com/

Jeff Xu (1):
exec: seal system mappings

 .../admin-guide/kernel-parameters.txt         |  9 ++++
 arch/x86/entry/vsyscall/vsyscall_64.c         |  9 +++-
 fs/exec.c                                     | 53 +++++++++++++++++++
 include/linux/fs.h                            |  1 +
 mm/mmap.c                                     |  1 +
 security/Kconfig                              | 26 +++++++++
 6 files changed, 97 insertions(+), 2 deletions(-)
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
#1 lore raw

RFC PATCH 1/1 exec: seal system mappings

From: Jeff Xu <[email protected]>

Seal vdso, vvar, sigpage, uprobes and vsyscall.

Those mappings are readonly or executable only, sealing can protect them from ever changing during the life time of the process.

System mappings such as vdso, vvar, and sigpage (for arm) are generated by the kernel during program initialization. These mappings are designated as non-writable, and sealing them will prevent them from ever becoming writeable.

Unlike the aforementioned mappings, the uprobe mapping is not established during program startup. However, its lifetime is the same as the process's lifetime [1], thus sealable.

The vdso, vvar, sigpage, and uprobe mappings all invoke the _install_special_mapping() function. As no other mappings utilize this function, it is logical to incorporate sealing logic within _install_special_mapping(). This approach avoids the necessity of modifying code across various architecture-specific implementations.

The vsyscall mapping, which has its own initialization function, is sealed in the XONLY case, it seems to be the most common and secure case of using vsyscall.

It is important to note that the CHECKPOINT_RESTORE feature (CRIU) may alter the mapping of vdso, vvar, and sigpage during restore operations. Consequently, this feature cannot be universally enabled across all systems. To address this, a kernel configuration option has been introduced to enable or disable this functionality. I tested CONFIG_SEAL_SYSTEM_MAPPINGS_ALWAYS with ChromeOS, which doesn’t use CHECKPOINT_RESTORE, to verify the sealing works.

[1] https://lore.kernel.org/all/CABi2SkU9BRUnqf70-nksuMCQ+yyiWjo3fM4XkRkL-NrCZxYAyg@mail.gmail.com/

---
 .../admin-guide/kernel-parameters.txt         |  9 ++++
 arch/x86/entry/vsyscall/vsyscall_64.c         |  9 +++-
 fs/exec.c                                     | 53 +++++++++++++++++++
 include/linux/fs.h                            |  1 +
 mm/mmap.c                                     |  1 +
 security/Kconfig                              | 26 +++++++++
 6 files changed, 97 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +9 -0
index 8dcec6d1cdb8..871ba308bb04 100644
@@ -1535,6 +1535,15 @@
 			Permit 'security.evm' to be updated regardless of
 			current integrity status.
 
+	exec.seal_system_mappings = [KNL]
+			Format: { never | always }
+			Seal system mappings: vdso, vvar, sigpage, uprobes,
+			vsyscall.
+			This overwrites KCONFIG CONFIG_SEAL_SYSTEM_MAPPINGS_*
+			- 'never':  never seal system mappings.
+			- 'always': always seal system mappings.
+			If not specified or invalid, default is the KCONFIG value.
+
 	early_page_ext [KNL,EARLY] Enforces page_ext initialization to earlier
 			stages so cover more early boot allocations.
 			Please note that as side effect some optimizations
arch/x86/entry/vsyscall/vsyscall_64.c +7 -2
index 2fb7d53cf333..20a3000550d2 100644
@@ -32,6 +32,7 @@
 #include <linux/mm_types.h>
 #include <linux/syscalls.h>
 #include <linux/ratelimit.h>
+#include <linux/fs.h>
 
 #include <asm/vsyscall.h>
 #include <asm/unistd.h>
@@ -366,8 +367,12 @@ void __init map_vsyscall(void)
 		set_vsyscall_pgtable_user_bits(swapper_pg_dir);
 	}
 
-	if (vsyscall_mode == XONLY)
-		vm_flags_init(&gate_vma, VM_EXEC);
+	if (vsyscall_mode == XONLY) {
+		unsigned long vm_flags = VM_EXEC;
+
+		update_seal_exec_system_mappings(&vm_flags);
+		vm_flags_init(&gate_vma, vm_flags);
+	}
 
 	BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
 		     (unsigned long)VSYSCALL_ADDR);
fs/exec.c +53 -0

62 lines not on this page · raw message

include/linux/fs.h +1 -0
index 1e25267e2e48..7539e89ccd03 100644
@@ -3075,6 +3075,7 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos);
 extern ssize_t kernel_write(struct file *, const void *, size_t, loff_t *);
 extern ssize_t __kernel_write(struct file *, const void *, size_t, loff_t *);
 extern struct file * open_exec(const char *);
+extern void update_seal_exec_system_mappings(unsigned long *vm_flags);
  
 /* fs/dcache.c -- generic fs support functions */
 extern bool is_subdir(struct dentry *, struct dentry *);
mm/mmap.c +1 -0
index ee8f91eaadb9..eb158e39ce0d 100644
@@ -2115,6 +2115,7 @@ struct vm_area_struct *_install_special_mapping(
 	unsigned long addr, unsigned long len,
 	unsigned long vm_flags, const struct vm_special_mapping *spec)
 {
+	update_seal_exec_system_mappings(&vm_flags);
 	return __install_special_mapping(mm, addr, len, vm_flags, (void *)spec,
 					&special_mapping_vmops);
 }
security/Kconfig +26 -0
index 28e685f53bd1..e289fbb5d676 100644
@@ -51,6 +51,32 @@ config PROC_MEM_NO_FORCE
 
 endchoice
 
+choice
+	prompt "Seal system mappings"
+	default SEAL_SYSTEM_MAPPINGS_NEVER
+	help
+	  Seal system mappings such as vdso, vvar, sigpage, uprobes and
+	  vsyscall.
+	  Note: kernel command line exec.seal_system_mappings overwrite this.
+
+config SEAL_SYSTEM_MAPPINGS_NEVER
+	bool "Traditional behavior - not sealed"
+	help
+	  Do not seal system mappings.
+	  This is default.
+
+config SEAL_SYSTEM_MAPPINGS_ALWAYS
+	bool "Always seal system mappings"
+	depends on 64BIT
+	depends on !CHECKPOINT_RESTORE
+	help
+	  Seal system mappings such as vdso, vvar, sigpage, uprobes and
+	  vsyscall.
+	  Note: CHECKPOINT_RESTORE might relocate vdso mapping during restore,
+	  and remap will fail if the mapping is sealed, therefore
+	  !CHECKPOINT_RESTORE is added as dependency.
+endchoice
+
 config SECURITY
 	bool "Enable different security models"
 	depends on SYSFS
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
maintainer
#2 lore raw

Re: [RFC PATCH v1 1/1] exec: seal system mappings

Quoted 5 lines · On 10/04, [email protected] wrote:

It is important to note that the CHECKPOINT_RESTORE feature (CRIU) may alter the mapping of vdso, vvar, and sigpage during restore operations. Consequently, this feature cannot be universally enabled across all systems.

Can't review.

But as for uprobes, I'd prefer a simpler patch which doesn't need the new CONFIG_ and/or kernel boot options, something like the patch below.

And I don't really like the fact that this patch changes the behaviour of the "generic" _install_special_mapping() helper, but I won't argue.

Oleg.

include/linux/mm.h +2 -0
@@ -430,6 +430,8 @@ extern unsigned int kobjsize(const void *objp);
 #ifdef CONFIG_64BIT
 /* VM is sealed, in vm_flags */
 #define VM_SEALED	_BITUL(63)
+#else
+#define VM_SEALED	0
 #endif
 
 /* Bits set in the VMA until the stack is in its final location */
kernel/events/uprobes.c +1 -1
index 40ecab0971ff..388373c11593 100644
@@ -1510,7 +1510,7 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
 	}
 
 	vma = _install_special_mapping(mm, area->vaddr, PAGE_SIZE,
-				VM_EXEC|VM_MAYEXEC|VM_DONTCOPY|VM_IO,
+				VM_EXEC|VM_MAYEXEC|VM_DONTCOPY|VM_IO|VM_SEALED,
 				&xol_mapping);
 	if (IS_ERR(vma)) {
 		ret = PTR_ERR(vma);
author
#3 lore raw

Re: [RFC PATCH v1 1/1] exec: seal system mappings

Quoted 8 lines · Oleg Nesterov
Quoted 5 lines · On 10/04, [email protected] wrote:

It is important to note that the CHECKPOINT_RESTORE feature (CRIU) may alter the mapping of vdso, vvar, and sigpage during restore operations. Consequently, this feature cannot be universally enabled across all systems.

Quoted 5 lines

Can't review.

But as for uprobes, I'd prefer a simpler patch which doesn't need the new CONFIG_ and/or kernel boot options, something like the patch below.

Ok.

Quoted 3 lines

And I don't really like the fact that this patch changes the behaviour of the "generic" _install_special_mapping() helper, but I won't argue.

This makes the minimum code change currently.
If in the future, there is a special mapping type that can't be
sealed, we can refactor _install_special_mapping() to support that.

Quoted 19 lines

Oleg.

include/linux/mm.h +2 -0
@@ -430,6 +430,8 @@ extern unsigned int kobjsize(const void *objp);
 #ifdef CONFIG_64BIT
 /* VM is sealed, in vm_flags */
 #define VM_SEALED      _BITUL(63)
+#else
+#define VM_SEALED      0
 #endif
 
 /* Bits set in the VMA until the stack is in its final location */
kernel/events/uprobes.c +0 -0
index 40ecab0971ff..388373c11593 100644

kernel/events/uprobes.c static int xol_add_vma(struct mm_struct *mm, struct xol_area *area) · line 1514

Quoted 6 lines
kernel/events/uprobes.c +1 -1
@@ -1510,7 +1510,7 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
        }
 
        vma = _install_special_mapping(mm, area->vaddr, PAGE_SIZE,
-                               VM_EXEC|VM_MAYEXEC|VM_DONTCOPY|VM_IO,
+                               VM_EXEC|VM_MAYEXEC|VM_DONTCOPY|VM_IO|VM_SEALED,
                                &xol_mapping);

OK.

Quoted 3 lines
kernel/events/uprobes.c +0 -0
        if (IS_ERR(vma)) {
                ret = PTR_ERR(vma);
maintainer
#4 lore raw

Re: [RFC PATCH v1 1/1] exec: seal system mappings

In reply to [email protected]

Sorry for the noise, forgot to mention...

Quoted 5 lines · On 10/04, [email protected] wrote:
Documentation/admin-guide/kernel-parameters.txt +0 -0
@@ -1535,6 +1535,15 @@
 			Permit 'security.evm' to be updated regardless of

Documentation/admin-guide/kernel-parameters.txt line 1545

Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +8 -0
 			current integrity status.
 
+	exec.seal_system_mappings = [KNL]
+			Format: { never | always }
+			Seal system mappings: vdso, vvar, sigpage, uprobes,
+			vsyscall.
+			This overwrites KCONFIG CONFIG_SEAL_SYSTEM_MAPPINGS_*
+			- 'never':  never seal system mappings.
+			- 'always': always seal system mappings.
+			If not specified or invalid, default is the KCONFIG value.

perhaps the documentation should also mention that this new parameter has no effect if CONFIG_64BIT=n.

Oleg.

author
#5 lore raw

Re: [RFC PATCH v1 1/1] exec: seal system mappings

Quoted 11 lines · Oleg Nesterov

Sorry for the noise, forgot to mention...

Quoted 7 lines · On 10/04, [email protected] wrote:
Documentation/admin-guide/kernel-parameters.txt +0 -0
@@ -1535,6 +1535,15 @@
                      Permit 'security.evm' to be updated regardless of
                      current integrity status.
 
Quoted 11 lines

Documentation/admin-guide/kernel-parameters.txt line 1545

Quoted 8 lines
Documentation/admin-guide/kernel-parameters.txt +8 -0
+     exec.seal_system_mappings = [KNL]
+                     Format: { never | always }
+                     Seal system mappings: vdso, vvar, sigpage, uprobes,
+                     vsyscall.
+                     This overwrites KCONFIG CONFIG_SEAL_SYSTEM_MAPPINGS_*
+                     - 'never':  never seal system mappings.
+                     - 'always': always seal system mappings.
+                     If not specified or invalid, default is the KCONFIG value.

perhaps the documentation should also mention that this new parameter has no effect if CONFIG_64BIT=n.

Good point, I will add that.

Thanks

Quoted 3 lines

Oleg.

reviewer
#6 lore raw

Re: [RFC PATCH v1 1/1] exec: seal system mappings

In reply to [email protected]

Hi Jeff,

Quoted 23 lines · On 10/4/24 9:31 AM, [email protected] wrote:

From: Jeff Xu <[email protected]>

Seal vdso, vvar, sigpage, uprobes and vsyscall.

---
 .../admin-guide/kernel-parameters.txt         |  9 ++++
 arch/x86/entry/vsyscall/vsyscall_64.c         |  9 +++-
 fs/exec.c                                     | 53 +++++++++++++++++++
 include/linux/fs.h                            |  1 +
 mm/mmap.c                                     |  1 +
 security/Kconfig                              | 26 +++++++++
 6 files changed, 97 insertions(+), 2 deletions(-)
security/Kconfig +0 -0
index 28e685f53bd1..e289fbb5d676 100644

security/Kconfig config PROC_MEM_NO_FORCE · line 60

Quoted 10 lines
security/Kconfig +7 -0
@@ -51,6 +51,32 @@ config PROC_MEM_NO_FORCE
 
 endchoice
 
+choice
+	prompt "Seal system mappings"
+	default SEAL_SYSTEM_MAPPINGS_NEVER
+	help
+	  Seal system mappings such as vdso, vvar, sigpage, uprobes and
+	  vsyscall.
+	  Note: kernel command line exec.seal_system_mappings overwrite this.

overwrites

Quoted 22 lines
security/Kconfig +19 -0
+
+config SEAL_SYSTEM_MAPPINGS_NEVER
+	bool "Traditional behavior - not sealed"
+	help
+	  Do not seal system mappings.
+	  This is default.
+
+config SEAL_SYSTEM_MAPPINGS_ALWAYS
+	bool "Always seal system mappings"
+	depends on 64BIT
+	depends on !CHECKPOINT_RESTORE
+	help
+	  Seal system mappings such as vdso, vvar, sigpage, uprobes and
+	  vsyscall.
+	  Note: CHECKPOINT_RESTORE might relocate vdso mapping during restore,
+	  and remap will fail if the mapping is sealed, therefore
+	  !CHECKPOINT_RESTORE is added as dependency.
+endchoice
+
 config SECURITY
 	bool "Enable different security models"
 	depends on SYSFS
Signature · 1 line
~Randy
author
#7 lore raw

Re: [RFC PATCH v1 1/1] exec: seal system mappings

Quoted 30 lines · Randy Dunlap

Hi Jeff,

Quoted 26 lines · On 10/4/24 9:31 AM, [email protected] wrote:

From: Jeff Xu <[email protected]>

Seal vdso, vvar, sigpage, uprobes and vsyscall.

---
 .../admin-guide/kernel-parameters.txt         |  9 ++++
 arch/x86/entry/vsyscall/vsyscall_64.c         |  9 +++-
 fs/exec.c                                     | 53 +++++++++++++++++++
 include/linux/fs.h                            |  1 +
 mm/mmap.c                                     |  1 +
 security/Kconfig                              | 26 +++++++++
 6 files changed, 97 insertions(+), 2 deletions(-)
security/Kconfig +0 -0
index 28e685f53bd1..e289fbb5d676 100644
@@ -51,6 +51,32 @@ config PROC_MEM_NO_FORCE
 
 endchoice
 
Quoted 9 lines

security/Kconfig config PROC_MEM_NO_FORCE · line 60

Quoted 7 lines
security/Kconfig +7 -0
+choice
+     prompt "Seal system mappings"
+     default SEAL_SYSTEM_MAPPINGS_NEVER
+     help
+       Seal system mappings such as vdso, vvar, sigpage, uprobes and
+       vsyscall.
+       Note: kernel command line exec.seal_system_mappings overwrite this.

overwrites

fixed.
Thanks

Quoted 26 lines
Quoted 13 lines
security/Kconfig +12 -0
+
+config SEAL_SYSTEM_MAPPINGS_NEVER
+     bool "Traditional behavior - not sealed"
+     help
+       Do not seal system mappings.
+       This is default.
+
+config SEAL_SYSTEM_MAPPINGS_ALWAYS
+     bool "Always seal system mappings"
+     depends on 64BIT
+     depends on !CHECKPOINT_RESTORE
+     help

security/Kconfig config PROC_MEM_NO_FORCE · line 82

Quoted 10 lines
security/Kconfig +7 -0
+       Seal system mappings such as vdso, vvar, sigpage, uprobes and
+       vsyscall.
+       Note: CHECKPOINT_RESTORE might relocate vdso mapping during restore,
+       and remap will fail if the mapping is sealed, therefore
+       !CHECKPOINT_RESTORE is added as dependency.
+endchoice
+
 config SECURITY
      bool "Enable different security models"
      depends on SYSFS

--
~Randy

#8 lore raw
In reply to [email protected]
Quoted 11 lines · * [email protected] <[email protected]> [241004 12:32]:

From: Jeff Xu <[email protected]>

Seal vdso, vvar, sigpage, uprobes and vsyscall.

Those mappings are readonly or executable only, sealing can protect them from ever changing during the life time of the process.

System mappings such as vdso, vvar, and sigpage (for arm) are generated by the kernel during program initialization. These mappings are designated as non-writable, and sealing them will prevent them from ever becoming writeable.

But it also means they cannot be unmapped, right?

I'm not saying it's a thing people should, but recent conversations with the ppc people seem to indicate that people do 'things' to the vdso such as removing it.

Won't this change mean they cannot do that, at least if mseal is enabled on ppc64? In which case we would have a different special mapping for powerpc, or any other platform that wants to be able to unmap the vdso (or vvar or whatever else?)

In fact, I came across people removing the vdso to catch callers to those functions which they didn't want to allow. In this case enabling the security of mseal would not allow them to stop applications from vdso calls. Again, I'm not saying this is a good (or bad) idea but it happening.

Quoted 15 lines

Unlike the aforementioned mappings, the uprobe mapping is not established during program startup. However, its lifetime is the same as the process's lifetime [1], thus sealable.

The vdso, vvar, sigpage, and uprobe mappings all invoke the _install_special_mapping() function. As no other mappings utilize this function, it is logical to incorporate sealing logic within _install_special_mapping(). This approach avoids the necessity of modifying code across various architecture-specific implementations.

The vsyscall mapping, which has its own initialization function, is sealed in the XONLY case, it seems to be the most common and secure case of using vsyscall.

Quoted 7 lines

It is important to note that the CHECKPOINT_RESTORE feature (CRIU) may alter the mapping of vdso, vvar, and sigpage during restore operations. Consequently, this feature cannot be universally enabled across all systems. To address this, a kernel configuration option has been introduced to enable or disable this functionality. I tested CONFIG_SEAL_SYSTEM_MAPPINGS_ALWAYS with ChromeOS, which doesn’t use CHECKPOINT_RESTORE, to verify the sealing works.

I am hesitant to say that CRIU is the only user of moving the vdso, as the ppc people wanted the ability for the fallback methods to still function when the vdso was unmapped.

I am not sure we can change the user expected behaviour based on a configuration option; users may be able to mmap/munmap but may not be able to boot their own kernel, but maybe it's okay?

Quoted 17 lines

[1] https://lore.kernel.org/all/CABi2SkU9BRUnqf70-nksuMCQ+yyiWjo3fM4XkRkL-NrCZxYAyg@mail.gmail.com/

Jeff Xu (1):
exec: seal system mappings

 .../admin-guide/kernel-parameters.txt         |  9 ++++
 arch/x86/entry/vsyscall/vsyscall_64.c         |  9 +++-
 fs/exec.c                                     | 53 +++++++++++++++++++
 include/linux/fs.h                            |  1 +
 mm/mmap.c                                     |  1 +
 security/Kconfig                              | 26 +++++++++
 6 files changed, 97 insertions(+), 2 deletions(-)
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
author
#9 lore raw

Hi Liam,

Quoted 54 lines · Liam R. Howlett
Quoted 11 lines · * [email protected] <[email protected]> [241004 12:32]:

From: Jeff Xu <[email protected]>

Seal vdso, vvar, sigpage, uprobes and vsyscall.

Those mappings are readonly or executable only, sealing can protect them from ever changing during the life time of the process.

System mappings such as vdso, vvar, and sigpage (for arm) are generated by the kernel during program initialization. These mappings are designated as non-writable, and sealing them will prevent them from ever becoming writeable.

But it also means they cannot be unmapped, right?

I'm not saying it's a thing people should, but recent conversations with the ppc people seem to indicate that people do 'things' to the vdso such as removing it.

Won't this change mean they cannot do that, at least if mseal is enabled on ppc64? In which case we would have a different special mapping for powerpc, or any other platform that wants to be able to unmap the vdso (or vvar or whatever else?)

In fact, I came across people removing the vdso to catch callers to those functions which they didn't want to allow. In this case enabling the security of mseal would not allow them to stop applications from vdso calls. Again, I'm not saying this is a good (or bad) idea but it happening.

Quoted 15 lines

Unlike the aforementioned mappings, the uprobe mapping is not established during program startup. However, its lifetime is the same as the process's lifetime [1], thus sealable.

The vdso, vvar, sigpage, and uprobe mappings all invoke the _install_special_mapping() function. As no other mappings utilize this function, it is logical to incorporate sealing logic within _install_special_mapping(). This approach avoids the necessity of modifying code across various architecture-specific implementations.

The vsyscall mapping, which has its own initialization function, is sealed in the XONLY case, it seems to be the most common and secure case of using vsyscall.

Quoted 7 lines

It is important to note that the CHECKPOINT_RESTORE feature (CRIU) may alter the mapping of vdso, vvar, and sigpage during restore operations. Consequently, this feature cannot be universally enabled across all systems. To address this, a kernel configuration option has been introduced to enable or disable this functionality. I tested CONFIG_SEAL_SYSTEM_MAPPINGS_ALWAYS with ChromeOS, which doesn’t use CHECKPOINT_RESTORE, to verify the sealing works.

Quoted 8 lines

I am hesitant to say that CRIU is the only user of moving the vdso, as the ppc people wanted the ability for the fallback methods to still function when the vdso was unmapped.

I am not sure we can change the user expected behaviour based on a configuration option; users may be able to mmap/munmap but may not be able to boot their own kernel, but maybe it's okay?

The text doesn't say CRIU is the **only** feature that is not compatible with this.

The default config is "CONFIG_SEAL_SYSTEM_MAPPINGS_NEVER", and distribution needs to opt-in for this feature, such as ChromeOS or Android or other safe-by-default systems that doesn't allow to unmap or remap vdso in production build.

Thanks
-Jeff

Quoted 17 lines
Quoted 17 lines

[1] https://lore.kernel.org/all/CABi2SkU9BRUnqf70-nksuMCQ+yyiWjo3fM4XkRkL-NrCZxYAyg@mail.gmail.com/

Jeff Xu (1):
exec: seal system mappings

 .../admin-guide/kernel-parameters.txt         |  9 ++++
 arch/x86/entry/vsyscall/vsyscall_64.c         |  9 +++-
 fs/exec.c                                     | 53 +++++++++++++++++++
 include/linux/fs.h                            |  1 +
 mm/mmap.c                                     |  1 +
 security/Kconfig                              | 26 +++++++++
 6 files changed, 97 insertions(+), 2 deletions(-)

--
2.47.0.rc0.187.ge670bccf7e-goog

#10 lore raw
Quoted 61 lines · Jeff Xu

Hi Liam,

Quoted 58 lines · Liam R. Howlett
Quoted 11 lines · * [email protected] <[email protected]> [241004 12:32]:

From: Jeff Xu <[email protected]>

Seal vdso, vvar, sigpage, uprobes and vsyscall.

Those mappings are readonly or executable only, sealing can protect them from ever changing during the life time of the process.

System mappings such as vdso, vvar, and sigpage (for arm) are generated by the kernel during program initialization. These mappings are designated as non-writable, and sealing them will prevent them from ever becoming writeable.

But it also means they cannot be unmapped, right?

I'm not saying it's a thing people should, but recent conversations with the ppc people seem to indicate that people do 'things' to the vdso such as removing it.

Won't this change mean they cannot do that, at least if mseal is enabled on ppc64? In which case we would have a different special mapping for powerpc, or any other platform that wants to be able to unmap the vdso (or vvar or whatever else?)

In fact, I came across people removing the vdso to catch callers to those functions which they didn't want to allow. In this case enabling the security of mseal would not allow them to stop applications from vdso calls. Again, I'm not saying this is a good (or bad) idea but it happening.

Quoted 15 lines

Unlike the aforementioned mappings, the uprobe mapping is not established during program startup. However, its lifetime is the same as the process's lifetime [1], thus sealable.

The vdso, vvar, sigpage, and uprobe mappings all invoke the _install_special_mapping() function. As no other mappings utilize this function, it is logical to incorporate sealing logic within _install_special_mapping(). This approach avoids the necessity of modifying code across various architecture-specific implementations.

The vsyscall mapping, which has its own initialization function, is sealed in the XONLY case, it seems to be the most common and secure case of using vsyscall.

Quoted 7 lines

It is important to note that the CHECKPOINT_RESTORE feature (CRIU) may alter the mapping of vdso, vvar, and sigpage during restore operations. Consequently, this feature cannot be universally enabled across all systems. To address this, a kernel configuration option has been introduced to enable or disable this functionality. I tested CONFIG_SEAL_SYSTEM_MAPPINGS_ALWAYS with ChromeOS, which doesn’t use CHECKPOINT_RESTORE, to verify the sealing works.

I am hesitant to say that CRIU is the only user of moving the vdso, as the ppc people wanted the ability for the fallback methods to still function when the vdso was unmapped.

Quoted 6 lines
Quoted 4 lines

I am not sure we can change the user expected behaviour based on a configuration option; users may be able to mmap/munmap but may not be able to boot their own kernel, but maybe it's okay?

The text doesn't say CRIU is the **only** feature that is not compatible with this.

Fair enough.

I read it that way since you pointed out breaking criu is the reason for not enabling this by default, although it's probably the biggest reason against doing this.

Quoted 5 lines

The default config is "CONFIG_SEAL_SYSTEM_MAPPINGS_NEVER", and distribution needs to opt-in for this feature, such as ChromeOS or Android or other safe-by-default systems that doesn't allow to unmap or remap vdso in production build.

Okay, but you never stated that they can't be unmapped or remapped in this change; just that they will never become writeable. It is worth adding that detail in the description since it isn't entirely obvious unless you know the workings of mseal.

Quoted 22 lines

Thanks
-Jeff

Quoted 17 lines
Quoted 17 lines

[1] https://lore.kernel.org/all/CABi2SkU9BRUnqf70-nksuMCQ+yyiWjo3fM4XkRkL-NrCZxYAyg@mail.gmail.com/

Jeff Xu (1):
exec: seal system mappings

 .../admin-guide/kernel-parameters.txt         |  9 ++++
 arch/x86/entry/vsyscall/vsyscall_64.c         |  9 +++-
 fs/exec.c                                     | 53 +++++++++++++++++++
 include/linux/fs.h                            |  1 +
 mm/mmap.c                                     |  1 +
 security/Kconfig                              | 26 +++++++++
 6 files changed, 97 insertions(+), 2 deletions(-)

--
2.47.0.rc0.187.ge670bccf7e-goog

author
#11 lore raw
Quoted 82 lines · Liam R. Howlett
Quoted 61 lines · Jeff Xu

Hi Liam,

Quoted 58 lines · Liam R. Howlett
Quoted 11 lines · * [email protected] <[email protected]> [241004 12:32]:

From: Jeff Xu <[email protected]>

Seal vdso, vvar, sigpage, uprobes and vsyscall.

Those mappings are readonly or executable only, sealing can protect them from ever changing during the life time of the process.

System mappings such as vdso, vvar, and sigpage (for arm) are generated by the kernel during program initialization. These mappings are designated as non-writable, and sealing them will prevent them from ever becoming writeable.

But it also means they cannot be unmapped, right?

I'm not saying it's a thing people should, but recent conversations with the ppc people seem to indicate that people do 'things' to the vdso such as removing it.

Won't this change mean they cannot do that, at least if mseal is enabled on ppc64? In which case we would have a different special mapping for powerpc, or any other platform that wants to be able to unmap the vdso (or vvar or whatever else?)

In fact, I came across people removing the vdso to catch callers to those functions which they didn't want to allow. In this case enabling the security of mseal would not allow them to stop applications from vdso calls. Again, I'm not saying this is a good (or bad) idea but it happening.

Quoted 15 lines

Unlike the aforementioned mappings, the uprobe mapping is not established during program startup. However, its lifetime is the same as the process's lifetime [1], thus sealable.

The vdso, vvar, sigpage, and uprobe mappings all invoke the _install_special_mapping() function. As no other mappings utilize this function, it is logical to incorporate sealing logic within _install_special_mapping(). This approach avoids the necessity of modifying code across various architecture-specific implementations.

The vsyscall mapping, which has its own initialization function, is sealed in the XONLY case, it seems to be the most common and secure case of using vsyscall.

Quoted 7 lines

It is important to note that the CHECKPOINT_RESTORE feature (CRIU) may alter the mapping of vdso, vvar, and sigpage during restore operations. Consequently, this feature cannot be universally enabled across all systems. To address this, a kernel configuration option has been introduced to enable or disable this functionality. I tested CONFIG_SEAL_SYSTEM_MAPPINGS_ALWAYS with ChromeOS, which doesn’t use CHECKPOINT_RESTORE, to verify the sealing works.

I am hesitant to say that CRIU is the only user of moving the vdso, as the ppc people wanted the ability for the fallback methods to still function when the vdso was unmapped.

Quoted 6 lines
Quoted 4 lines

I am not sure we can change the user expected behaviour based on a configuration option; users may be able to mmap/munmap but may not be able to boot their own kernel, but maybe it's okay?

The text doesn't say CRIU is the **only** feature that is not compatible with this.

Fair enough.

I read it that way since you pointed out breaking criu is the reason for not enabling this by default, although it's probably the biggest reason against doing this.

Quoted 5 lines

The default config is "CONFIG_SEAL_SYSTEM_MAPPINGS_NEVER", and distribution needs to opt-in for this feature, such as ChromeOS or Android or other safe-by-default systems that doesn't allow to unmap or remap vdso in production build.

Quoted 5 lines

Okay, but you never stated that they can't be unmapped or remapped in this change; just that they will never become writeable. It is worth adding that detail in the description since it isn't entirely obvious unless you know the workings of mseal.

Thanks, I will improve this section by adding more details on memory sealing or maybe point to the mseal.rst document.

Quoted 22 lines
Quoted 22 lines

Thanks
-Jeff

Quoted 17 lines
Quoted 17 lines

[1] https://lore.kernel.org/all/CABi2SkU9BRUnqf70-nksuMCQ+yyiWjo3fM4XkRkL-NrCZxYAyg@mail.gmail.com/

Jeff Xu (1):
exec: seal system mappings

 .../admin-guide/kernel-parameters.txt         |  9 ++++
 arch/x86/entry/vsyscall/vsyscall_64.c         |  9 +++-
 fs/exec.c                                     | 53 +++++++++++++++++++
 include/linux/fs.h                            |  1 +
 mm/mmap.c                                     |  1 +
 security/Kconfig                              | 26 +++++++++
 6 files changed, 97 insertions(+), 2 deletions(-)

--
2.47.0.rc0.187.ge670bccf7e-goog