Add mseal() testing suite
v2 cover Add mseal() testing suite
Smoke test for mseal() syscall added in the kernel 6.10. All information can be found at the following link:
https://docs.kernel.org/userspace-api/mseal.html
---
Changes in v2:
- don't use TST_ABI32 var anymore, but let tst_syscall handling ENOSYS
- call protection key syscalls via tst_syscall
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (2):
Add mseal() syscall declaration
Add mseal01 test
include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arc.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/loongarch.in | 1 + include/lapi/syscalls/mips_n32.in | 1 + include/lapi/syscalls/mips_n64.in | 1 + include/lapi/syscalls/mips_o32.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + testcases/kernel/syscalls/mseal/.gitignore | 1 + testcases/kernel/syscalls/mseal/Makefile | 7 ++ testcases/kernel/syscalls/mseal/mseal01.c | 173 +++++++++++++++++++++++++++++ 21 files changed, 199 insertions(+)
---
base-commit: c5d95b6d34e2356bd19e6b646da06f1bce66a024
change-id: 20240607-mseal-dfac12675096
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/2 Add mseal() syscall declaration
From: Andrea Cervesato <[email protected]>
--- include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arc.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/loongarch.in | 1 + include/lapi/syscalls/mips_n32.in | 1 + include/lapi/syscalls/mips_n64.in | 1 + include/lapi/syscalls/mips_o32.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 18 files changed, 18 insertions(+)
include/lapi/syscalls/aarch64.in +1 -0
@@ -300,4 +300,5 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462 _sysctl 1078
include/lapi/syscalls/arc.in +1 -0
@@ -320,3 +320,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/arm.in +1 -0
@@ -399,3 +399,4 @@ landlock_add_rule (__NR_SYSCALL_BASE+445) landlock_restrict_self (__NR_SYSCALL_BASE+446) memfd_secret (__NR_SYSCALL_BASE+447) futex_waitv (__NR_SYSCALL_BASE+449) +mseal (__NR_SYSCALL_BASE+462)
include/lapi/syscalls/hppa.in +1 -0
@@ -47,3 +47,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/i386.in +1 -0
@@ -434,3 +434,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/ia64.in +1 -0
@@ -347,3 +347,4 @@ landlock_create_ruleset 1468 landlock_add_rule 1469 landlock_restrict_self 1470 futex_waitv 1473 +mseal 1486
include/lapi/syscalls/loongarch.in +1 -0
@@ -305,3 +305,4 @@ memfd_secret 447 process_mrelease 448 futex_waitv 449 set_mempolicy_home_node 450 +mseal 462
include/lapi/syscalls/mips_n32.in +1 -0
@@ -374,3 +374,4 @@ landlock_create_ruleset 6444 landlock_add_rule 6445 landlock_restrict_self 6446 futex_waitv 6449 +mseal 6462
include/lapi/syscalls/mips_n64.in +1 -0
@@ -350,3 +350,4 @@ landlock_create_ruleset 5444 landlock_add_rule 5445 landlock_restrict_self 5446 futex_waitv 5449 +mseal 5462
include/lapi/syscalls/mips_o32.in +1 -0
@@ -420,3 +420,4 @@ landlock_create_ruleset 4444 landlock_add_rule 4445 landlock_restrict_self 4446 futex_waitv 4449 +mseal 4462
include/lapi/syscalls/powerpc.in +1 -0
@@ -427,3 +427,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/powerpc64.in +1 -0
@@ -427,3 +427,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/s390.in +1 -0
@@ -414,3 +414,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/s390x.in +1 -0
@@ -362,3 +362,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/sh.in +1 -0
@@ -408,3 +408,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/sparc.in +1 -0
@@ -413,3 +413,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/sparc64.in +1 -0
@@ -378,3 +378,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462
include/lapi/syscalls/x86_64.in +1 -0
@@ -355,6 +355,7 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +mseal 462 rt_sigaction 512 rt_sigreturn 513 ioctl 514
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] Add mseal() syscall declaration
Hi!
This patch obviously does not apply after I've merged cachestat. I guess that the easiest solution is to have a one patch that adds all these fallbacks for all new syscalls you are working on pushed first, otherwise there will be conflicts for each patchset.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] Add mseal() syscall declaration
I can send v3 if needed.
Quoted 6 lines · Cyril Hrubis
Hi!
This patch obviously does not apply after I've merged cachestat. I guess that the easiest solution is to have a one patch that adds all these fallbacks for all new syscalls you are working on pushed first, otherwise there will be conflicts for each patchset.
Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] Add mseal() syscall declaration
Hi!
Quoted 1 line
I can send v3 if needed.
But that would solve only mseal() and the fhcmodat2() has the same collision and would need a v3 that would apply on the top of mseal(). The syscall in files are unfortunatelly contetion point so I'm suggesting to add all the definitions you are going to need in a single patch instead.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] Add mseal() syscall declaration
Sorry but I don’t get it. Resolving conflicts is really something up to people who push the code on the mainline (:
Also it should be pretty easy since it requires to accept both head and coming changes.
Andrea
Quoted 14 lines · Cyril Hrubis
Hi!
Quoted 1 line
I can send v3 if needed.
But that would solve only
mseal()and thefhcmodat2()has the same collision and would need a v3 that would apply on the top ofmseal(). The syscall in files are unfortunatelly contetion point so I'm suggesting to add all the definitions you are going to need in a single patch instead.--
Cyril Hrubis
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] Add mseal() syscall declaration
Hi!
Quoted 3 lines
Sorry but I don’t get it. Resolving conflicts is really something up to people who push the code on the mainline (: Also it should be pretty easy since it requires to accept both head and coming changes.
I'm pretty sure you would get some pretty hars word if you send patches to linux kernel that does not apply on the top of each other...
Anyways I'm just trying to get to a solution that would save time for everyone, because manually fixing a patch that fails to add a line into 18 different files is not something I want to do for each new syscall patchset you send...
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 Add mseal01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This is a smoke test that verifies if mseal() protects specific VMA portions of a process. According to documentation, the syscall should protect memory from the following actions:
- unmapping, moving to another location, and shrinking the size, via munmap() and mremap()
- moving or expanding a different VMA into the current location, via mremap()
- modifying a VMA via mmap(MAP_FIXED)
- mprotect() and pkey_mprotect()
- destructive madvice() behaviors (e.g. MADV_DONTNEED) for anonymous memory, when users don’t have write permission to the memory
Any of the described actions is recognized via EPERM errno.
--- testcases/kernel/syscalls/mseal/.gitignore | 1 + testcases/kernel/syscalls/mseal/Makefile | 7 ++ testcases/kernel/syscalls/mseal/mseal01.c | 173 +++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+)
testcases/kernel/syscalls/mseal/.gitignore new file +1 -0
@@ -0,0 +1 @@ +mseal01
testcases/kernel/syscalls/mseal/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/mseal/mseal01.c new file +173 -0
173 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] Add mseal01 test
Hi!
Quoted 20 lines
testcases/kernel/syscalls/mseal/mseal01.c new file +20
-0+static void child (unsigned int n) +{ +struct tcase *tc = &tcases[n]; + + mem_addr =SAFE_MMAP (NULL , mem_size, + tc->prot, +MAP_ANONYMOUS |MAP_PRIVATE , +-1 ,0 ); + +tst_res (TINFO ,"Testing %s" , tc->message); + +TST_EXP_PASS (sys_mseal (mem_addr + mem_offset, mem_alignment)); + + tc->func_test (); +} + +static void run (unsigned int n) +{ +/* the reason why we spawn a child is that mseal() will +* protect VMA until process will call _exit()
testcases/kernel/syscalls/mseal/mseal01.c line 149
Quoted 10 lines
testcases/kernel/syscalls/mseal/mseal01.c new file +10
-0+*/ +if (!SAFE_FORK ()) { +child (n); +_exit (0 ); + } + +tst_reap_children (); + +if (mem_addr !=MAP_FAILED ) +SAFE_MUNMAP (mem_addr, mem_size);
The memory is mapped in the child, it's hence not propagated to the parent. With fork() only changes done in parent before the fork happens are visible in child as well, since the memory is CoW.
testcases/kernel/syscalls/mseal/mseal01.c line 162
Quoted 13 lines
testcases/kernel/syscalls/mseal/mseal01.c new file +13
-0+} + +static void setup (void ) +{ + mem_alignment =getpagesize (); + mem_size = mem_alignment *MEMPAGES ; + mem_offset = mem_alignment *MEMSEAL ; +} + +static void cleanup (void ) +{ +if (mem_addr !=MAP_FAILED ) +SAFE_MUNMAP (mem_addr, mem_size);
Here as well, this is useless, since the memory was allocated in child, and freed automatically when the child exits.
The rest look fine.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp