teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0254-test-account-for-ADDR_NO_RANDOMIZE-if-it-s-set.patch

594167
From f55e25db1b2f69cd5d19508bda34c52f5f92e800 Mon Sep 17 00:00:00 2001
594167
From: Frantisek Sumsal <frantisek@sumsal.cz>
594167
Date: Thu, 9 Jun 2022 11:34:09 +0200
594167
Subject: [PATCH] test: account for ADDR_NO_RANDOMIZE if it's set
594167
594167
On ppc64le sanitizers disable ASLR (i.e. by setting ADDR_NO_RANDOMIZE),
594167
which opinionated_personality() doesn't return. Let's tweak the current
594167
personality ourselves in such cases.
594167
594167
See: https://github.com/llvm/llvm-project/commit/78f7a6eaa601bfdd6ae70ffd3da2254c21ff77f9
594167
594167
Resolves: #23666
594167
(cherry picked from commit 894dad2975c61f59e71561cab21d6f85e8523b57)
594167
594167
Related: #2087652
594167
---
594167
 src/test/test-seccomp.c | 16 ++++++++++++----
594167
 1 file changed, 12 insertions(+), 4 deletions(-)
594167
594167
diff --git a/src/test/test-seccomp.c b/src/test/test-seccomp.c
594167
index 7ccfeadbb8..1f96ba4f80 100644
594167
--- a/src/test/test-seccomp.c
594167
+++ b/src/test/test-seccomp.c
594167
@@ -934,8 +934,15 @@ TEST(lock_personality) {
594167
         }
594167
 
594167
         assert_se(opinionated_personality(&current) >= 0);
594167
+        /* On ppc64le sanitizers disable ASLR (i.e. by setting ADDR_NO_RANDOMIZE),
594167
+         * which opinionated_personality() doesn't return. Let's tweak the current
594167
+         * personality ourselves in such cases.
594167
+         * See: https://github.com/llvm/llvm-project/commit/78f7a6eaa601bfdd6ae70ffd3da2254c21ff77f9
594167
+         */
594167
+        if (FLAGS_SET(safe_personality(PERSONALITY_INVALID), ADDR_NO_RANDOMIZE))
594167
+                current |= ADDR_NO_RANDOMIZE;
594167
 
594167
-        log_info("current personality=%lu", current);
594167
+        log_info("current personality=0x%lX", current);
594167
 
594167
         pid = fork();
594167
         assert_se(pid >= 0);
594167
@@ -945,13 +952,14 @@ TEST(lock_personality) {
594167
 
594167
                 assert_se((unsigned long) safe_personality(current) == current);
594167
 
594167
-                /* Note, we also test that safe_personality() works correctly, by checkig whether errno is properly
594167
+                /* Note, we also test that safe_personality() works correctly, by checking whether errno is properly
594167
                  * set, in addition to the return value */
594167
                 errno = 0;
594167
-                assert_se(safe_personality(PER_LINUX | ADDR_NO_RANDOMIZE) == -EPERM);
594167
+                assert_se(safe_personality(PER_LINUX | MMAP_PAGE_ZERO) == -EPERM);
594167
                 assert_se(errno == EPERM);
594167
 
594167
-                assert_se(safe_personality(PER_LINUX | MMAP_PAGE_ZERO) == -EPERM);
594167
+                if (!FLAGS_SET(current, ADDR_NO_RANDOMIZE))
594167
+                        assert_se(safe_personality(PER_LINUX | ADDR_NO_RANDOMIZE) == -EPERM);
594167
                 assert_se(safe_personality(PER_LINUX | ADDR_COMPAT_LAYOUT) == -EPERM);
594167
                 assert_se(safe_personality(PER_LINUX | READ_IMPLIES_EXEC) == -EPERM);
594167
                 assert_se(safe_personality(PER_LINUX_32BIT) == -EPERM);