public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Teo Couprie Diaz <teo.coupriediaz@arm.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] setpgid02: Use pid_max as PGID for EPERM
Date: Wed, 19 Apr 2023 13:00:22 +0200	[thread overview]
Message-ID: <ZD/JxunXsz7Lms9U@yuki> (raw)
In-Reply-To: <20230418130944.181716-1-teo.coupriediaz@arm.com>

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

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

  parent reply	other threads:[~2023-04-19 10:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2023-04-19 11:11   ` Li Wang
2023-04-19 12:40     ` Teo Couprie Diaz
2023-04-20  8:50       ` Cyril Hrubis

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=ZD/JxunXsz7Lms9U@yuki \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=teo.coupriediaz@arm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox