From: Alejandro Colomar <alx@kernel.org>
To: linux-man@vger.kernel.org, Sargun Dhillon <sargun@sargun.me>,
Serge Hallyn <serge@hallyn.com>
Cc: Alejandro Colomar <alx@kernel.org>, John Watts <contact@jookia.org>
Subject: [PATCH v2] clone.2: Fix outdated statement about CLONE_NEWPID
Date: Sun, 13 Aug 2023 15:17:27 +0200 [thread overview]
Message-ID: <20230813131727.35849-1-alx@kernel.org> (raw)
In-Reply-To: <CAMp4zn-BHvCAKWTiVTWb6oEzkFRzd0jHXWHBE1h-BQ+mGUD=WQ@mail.gmail.com>
From: Sargun Dhillon <sargun@sargun.me>
[TO += Serge]
Hi Sargun, Serge!
Sargun, I've slightly changed your patch, to keep the historical
information that in old versions of Linux this restriction was in place.
I also cleaned up the example program a little bit, and fixed the
formatting mistake I mentioned. See scissor patch below.
However, reading the Linux commit that changed this, I had some doubts.
I've added Serge, in case he can remember the details.
Serge, I see that the commit message for (Linux) 1f7f4dde5c94 quotes
some email of yours, and mentions that the commit fixes a regression.
So my doubt is: was this restriction in place before v3.13 as a stable
thing, or was it only accidentally introduced temporarily and soon
fixed? How should we document it?
Cheers,
Alex
---8<-----
It appears like the documentation is based on out of date information in
regards to using CLONE_NEWPID and CLONE_PARENT together. Since Linux
v3.13, this restriction has been lifted. See commit 1f7f4dde5c94
("fork: Allow CLONE_PARENT after setns(CLONE_NEWPID)").
For example, in this test program, one can see that it works:
#include <assert.h>
#include <err.h>
#include <linux/sched.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
static pid_t sys_clone3(struct clone_args *args);
int
main(void)
{
int ret;
struct clone_args args = {
.flags = CLONE_PARENT | CLONE_NEWPID,
};
printf("main program: pid: %d, and ppid: %d\n", getpid(), getppid());
ret = sys_clone3(&args);
switch (ret) {
case -1:
err(EXIT_FAILURE, "clone3");
case 0:
printf("child: pid: %d, and ppid: %d\n", getpid(), getppid());
exit(EXIT_SUCCESS);
default:
exit(EXIT_SUCCESS);
}
}
static pid_t
sys_clone3(struct clone_args *args)
{
fflush(stdout);
fflush(stderr);
return syscall(SYS_clone3, args, sizeof(*args));
}
This test program (successfully) outputs:
# ./a.out
main program: pid: 34663, and ppid: 34662
child: pid: 1, and ppid: 0
Cowritten-by: Sargun Dhillon <sargun@sargun.me>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: John Watts <contact@jookia.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
man2/clone.2 | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/man2/clone.2 b/man2/clone.2
index b91b71831..225fef86d 100644
--- a/man2/clone.2
+++ b/man2/clone.2
@@ -736,9 +736,11 @@ .SS The flags mask
can employ
.BR CLONE_NEWPID .
This flag can't be specified in conjunction with
-.B CLONE_THREAD
-or
-.BR CLONE_PARENT .
+.BR CLONE_THREAD .
+Before Linux 3.13,
+this flag couldn't be specified in conjunction with
+.B CLONE_PARENT
+either.
.TP
.B CLONE_NEWUSER
(This flag first became meaningful for
--
2.40.1
next prev parent reply other threads:[~2023-08-13 13:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 2:26 [PATCH] clone.2: Fix the erroneous statement about CLONE_NEWPID Sargun Dhillon
2023-08-12 17:48 ` Alejandro Colomar
2023-08-12 17:51 ` Alejandro Colomar
2023-08-12 19:05 ` John Watts
2023-08-13 0:57 ` Sargun Dhillon
2023-08-13 13:17 ` Alejandro Colomar [this message]
2023-08-13 13:35 ` [PATCH v2] clone.2: Fix outdated " Serge E. Hallyn
2023-08-13 13:40 ` Alejandro Colomar
2023-08-13 13:53 ` Serge E. Hallyn
2023-08-13 13:55 ` [PATCH v3] clone.2: Fix erroneous statement about CLONE_NEWPID|CLONE_PARENT Alejandro Colomar
2023-08-13 14:03 ` Alejandro Colomar
2023-08-13 14:36 ` Serge E. Hallyn
2023-08-13 14:37 ` Alejandro Colomar
2023-08-13 14:40 ` Alejandro Colomar
2023-08-13 14:14 ` [PATCH v4] " Alejandro Colomar
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=20230813131727.35849-1-alx@kernel.org \
--to=alx@kernel.org \
--cc=contact@jookia.org \
--cc=linux-man@vger.kernel.org \
--cc=sargun@sargun.me \
--cc=serge@hallyn.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 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.