[LTP] [PATCH v2 1/8] Refactor mmap03 test

Ricardo B. Marlière ricardo@marliere.net
Mon Feb 10 12:46:40 CET 2025


On Mon Feb 10, 2025 at 6:41 AM -03, Petr Vorel wrote:
> Hi Andrea, all,
>
> ...
>> - *	07/2001 Ported by Wayne Boyer
>> + * With ia64 and PARISC/hppa, an attempt to access the contents of the
>> + * mapped region should rise signal SIGSEGV.
>
> You kept this:
>  * With ia64 and PARISC/hppa, an attempt to access the contents of the
>  * mapped region should rise signal SIGSEGV.
>
> You kept checking SIGSEGV, but not sigsetjmp() which should cause it (IMHO it
> will not work).

In my initial testing [1], I hit a situation where SIGSEGV was raised in
my Tumbleweed SUT. I eventually found out that it was due to
CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS=y in openSUSE kernels.

[1]: https://lore.kernel.org/ltp/20250114-conversions-v1-2-7869a9f786d0@suse.com/

I was playing with the following diff here but was unable to catch any
signal in the current version:

diff --git a/testcases/kernel/syscalls/mmap/mmap03.c b/testcases/kernel/syscalls/mmap/mmap03.c
index f22365b259da..25f9c5ce4d18 100644
--- a/testcases/kernel/syscalls/mmap/mmap03.c
+++ b/testcases/kernel/syscalls/mmap/mmap03.c
@@ -22,6 +22,7 @@
  * mapped region should rise signal SIGSEGV.
  */
 
+#include "tst_kconfig.h"
 #include "tst_test.h"
 
 #define TEMPFILE "mmapfile"
@@ -67,7 +68,14 @@ static void run(void)
 
 	SAFE_WAITPID(pid, &status, 0);
 
-#if defined(__ia64__) || defined(__hppa__) || defined(__mips__)
+#if defined(__ia64__) || defined(__hppa__) || defined(__mips__) || defined(__x86_64__)
+	struct tst_kconfig_var kconfig =
+		TST_KCONFIG_INIT("CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS");
+	tst_kconfig_read(&kconfig, 1);
+	if (kconfig.choice == 'y')
+		tst_res(TINFO, "CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS=y");
+
+	tst_res(TINFO, "%d == 11 (SEGV)?", WTERMSIG(status));
 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
 		tst_res(TPASS, "SIGSEGV has been received");
 	} else {


BTW, thanks for the mmap cleanup, Andrea!

>
> I wonder if we should care about these old archs. Both ia64 and hppa are
> dropped. The only still living arch is __mips__. But looking at change when it
> mips was added it's quite recent - 2021:
> c7f979b3d ("syscalls/mmap03: Fix SegFault on MIPS")

TIL, thanks :)

-    Ricardo.



>
> @Cyril? Should we keep only mips? And I strongly suspect nobody is testing LTP
> on mips, but we should probably not kill a still living arch.
> If all these archs removed whole fork could be removed.
>
> ...
>> +	tst_res(TINFO, "Map temporary file in memory with PROT_EXEC");
> nit: I would remove it. In case of the problem SAFE_MMAP() will notify,
> otherwise not important.
>
> Also, can we move SAFE_MALLOC() to setup and free to cleanup()
>
> data = SAFE_MALLOC(page_sz);
>
> Kind regards,
> Petr



More information about the ltp mailing list