[LTP] [PATCH] setpgid02: Use pid_max as PGID for EPERM

Cyril Hrubis chrubis@suse.cz
Wed Apr 19 13:00:22 CEST 2023


Hi!
> 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.

So I suppose that we hit slightly different condition in the kernel:

        if (pgid != pid) {
                struct task_struct *g;

                pgrp = find_vpid(pgid);
                g = pid_task(pgrp, PIDTYPE_PGID);
                if (!g || task_session(g) != task_session(group_leader))
                        goto out;
        }

Previously we were supposed to hit the task_session(g) !=
task_session(group_leader) now we hit !g.

Also I guess that the only way to hit the second part of the condition
is to actually open and initialize a pty so that we have a process
outside of the current session.

The patch itself looks okay, but we should at least update the
documentation comment such as:

diff --git a/testcases/kernel/syscalls/setpgid/setpgid02.c b/testcases/kernel/syscalls/setpgid/setpgid02.c
index 4b63afee8..68b663633 100644
--- a/testcases/kernel/syscalls/setpgid/setpgid02.c
+++ b/testcases/kernel/syscalls/setpgid/setpgid02.c
@@ -13,8 +13,8 @@
  * - EINVAL when given pgid is less than 0.
  * - ESRCH when pid is not the calling process and not a child of
  * the calling process.
- * - EPERM when an attempt was made to move a process into a process
- * group in a different session.
+ * - EPERM when an attempt was made to move a process into a nonexisting
+ *   process group.
  */

And ideally write a test for the second case as well.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list