public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] setpgid02: Use pid_max as PGID for EPERM
@ 2023-04-18 13:09 Teo Couprie Diaz
  2023-04-19  8:25 ` Li Wang
  2023-04-19 11:00 ` Cyril Hrubis
  0 siblings, 2 replies; 6+ messages in thread
From: Teo Couprie Diaz @ 2023-04-18 13:09 UTC (permalink / raw)
  To: ltp

In some simple systems (like Busybox), the login shell might be run
as init (PID 1).
This leads to a case where LTP is run in the same session as init,
thus setpgid is allowed to the PGID of init which results in a test fail.
Indeed, the test retrieves the PGID of init to try and generate EPERM.

Instead, get the PGID we use to generate EPERM from the kernel pid_max.
It should not be used by any process, guaranteeing a different session
and generating an EPERM error.

Signed-off-by: Teo Couprie Diaz <teo.coupriediaz@arm.com>
---
See discussion on the origin of this patch (end of thread):
https://lists.linux.it/pipermail/ltp/2023-April/033505.html

Apologies for the time it took to send this.

CI Build:
https://github.com/Teo-CD/ltp/actions/runs/4732620255

 testcases/kernel/syscalls/setpgid/setpgid02.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/syscalls/setpgid/setpgid02.c b/testcases/kernel/syscalls/setpgid/setpgid02.c
index 4b63afee8..5341774e1 100644
--- a/testcases/kernel/syscalls/setpgid/setpgid02.c
+++ b/testcases/kernel/syscalls/setpgid/setpgid02.c
@@ -21,7 +21,7 @@
 #include <unistd.h>
 #include "tst_test.h"
 
-static pid_t pgid, pid, ppid, init_pgid;
+static pid_t pgid, pid, ppid, inval_pgid;
 static pid_t negative_pid = -1;
 
 static struct tcase {
@@ -31,7 +31,7 @@ static struct tcase {
 } tcases[] = {
 	{&pid, &negative_pid, EINVAL},
 	{&ppid, &pgid, ESRCH},
-	{&pid, &init_pgid, EPERM}
+	{&pid, &inval_pgid, EPERM}
 };
 
 static void setup(void)
@@ -41,10 +41,10 @@ static void setup(void)
 	pgid = getpgrp();
 
 	/*
-	 * Getting pgid of init/systemd process to use it as a
-	 * process group from a different session for EPERM test
+	 * pid_max would not be in use by another process and guarantees that
+	 * it corresponds to "another session", generating EPERM.
 	 */
-	init_pgid = SAFE_GETPGID(1);
+	SAFE_FILE_SCANF("/proc/sys/kernel/pid_max", "%d\n", &inval_pgid);
 }
 
 static void run(unsigned int n)
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-04-20  8:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-18 13:09 [LTP] [PATCH] setpgid02: Use pid_max as PGID for EPERM Teo Couprie Diaz
2023-04-19  8:25 ` Li Wang
2023-04-19 11:00 ` Cyril Hrubis
2023-04-19 11:11   ` Li Wang
2023-04-19 12:40     ` Teo Couprie Diaz
2023-04-20  8:50       ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox