[LTP] [PATCH] setpgid02: Use pid_max as PGID for EPERM
Teo Couprie Diaz
teo.coupriediaz@arm.com
Tue Apr 18 15:09:46 CEST 2023
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
More information about the ltp
mailing list