All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Doucha <mdoucha@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] cgroup_core02: Allocate child stack using mmap()
Date: Mon, 20 Jan 2025 11:49:09 +0100	[thread overview]
Message-ID: <20250120104911.39566-1-mdoucha@suse.cz> (raw)

Some architectures like arm64 have strict requirements for stack alignment.
Statically allocated buffer may result in one of the test processes
getting killed by SIGBUS. Allocate child stack using mmap() to ensure
the requirements are met.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
Acked-by: Petr Vorel <pvorel@suse.cz>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
---

Changes since v1: Added #define for stack size

I've also verified that the CVE is still reproducible on affected kernels
with this test fix.

 testcases/kernel/controllers/cgroup/cgroup_core02.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/controllers/cgroup/cgroup_core02.c b/testcases/kernel/controllers/cgroup/cgroup_core02.c
index 733e88ee7..b19bf2e58 100644
--- a/testcases/kernel/controllers/cgroup/cgroup_core02.c
+++ b/testcases/kernel/controllers/cgroup/cgroup_core02.c
@@ -32,6 +32,8 @@
 #include "tst_safe_file_at.h"
 #include "lapi/sched.h"
 
+#define STACK_SIZE 65536
+
 static struct tst_cg_group *cg_child_a, *cg_child_b;
 static uid_t nobody_uid;
 
@@ -51,7 +53,7 @@ static int lesser_ns_open_thread_fn(void *arg)
 static void test_lesser_ns_open(void)
 {
 	int i;
-	static char stack[65536];
+	char *stack;
 	pid_t pid;
 	int status;
 	struct lesser_ns_open_thread_arg targ = { .fds = {0}, .loops = -1};
@@ -63,14 +65,19 @@ static void test_lesser_ns_open(void)
 		SAFE_CG_PRINT(cg_child_a, "cgroup.procs", "0");
 		SAFE_CG_FCHOWN(cg_child_a, "cgroup.procs",  nobody_uid, -1);
 		SAFE_CG_FCHOWN(cg_child_b, "cgroup.procs",  nobody_uid, -1);
+		stack = SAFE_MMAP(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
+			MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
 		pid  = ltp_clone(CLONE_NEWCGROUP | CLONE_FILES | CLONE_VM | SIGCHLD,
-					lesser_ns_open_thread_fn, &targ, 65536, stack);
+					lesser_ns_open_thread_fn, &targ, STACK_SIZE, stack);
+
 		if (pid < 0)  {
 			tst_res(TFAIL, "unexpected negative pid %d", pid);
 			exit(1);
 		}
 
 		SAFE_WAITPID(pid, &status, 0);
+		SAFE_MUNMAP(stack, STACK_SIZE);
+
 		for (i = 0; i < targ.loops; i++) {
 			if (targ.fds[i] < 1) {
 				tst_res(TFAIL, "unexpected negative fd %d", targ.fds[i]);
-- 
2.47.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2025-01-20 10:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20 10:49 Martin Doucha [this message]
2025-01-20 13:07 ` [LTP] [PATCH v2] cgroup_core02: Allocate child stack using mmap() Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250120104911.39566-1-mdoucha@suse.cz \
    --to=mdoucha@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.