From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: bugzilla-daemon@kernel.org,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Коренберг Марк" <socketpair@gmail.com>,
"Christian Brauner" <brauner@kernel.org>
Cc: Andrei Vagin <avagin@openvz.org>,
Dmitry Safonov <dima@arista.com>,
Thomas Gleixner <tglx@linutronix.de>,
Arnd Bergmann <arnd@arndb.de>, Serge Hallyn <serge@hallyn.com>
Subject: vfork(2) fails after unshare(CLONE_NEWTIME) (was: [Bug 215769] man 2 vfork() does not document corner case when PID == 1)
Date: Sat, 2 Apr 2022 23:15:52 +0200 [thread overview]
Message-ID: <4fb02f5f-60f9-42af-ddd5-fe5af877231f@gmail.com> (raw)
In-Reply-To: <bug-215769-216477-to2O9X1Knw@https.bugzilla.kernel.org/>
[Added some kernel CCs that may know what's going on]
Hi,
On 3/31/22 09:53, bugzilla-daemon@kernel.org wrote:
> https://bugzilla.kernel.org/show_bug.cgi?id=215769
>
> --- Comment #3 from Коренберг Марк (socketpair@gmail.com) ---
> Hi,
> I appreciate depth of information validation. Actually, you are right. vfork()
> DOES work with pid=1 processes. I figured out the cause in my case. In order to
> reproduce -- add unshare(CLONE_NEWTIME) just before vfork(). Now, I don't know
> if it's a bug in vfork() or in fork(). Yes, both are clone() actually.
>
> In any case, they should either both give EINVAL or both don't fail. But it's
> definitely bug in the kernel around CLONE_NEWTIME.
>
On 3/31/22 10:12, bugzilla-daemon@kernel.org wrote:
> https://bugzilla.kernel.org/show_bug.cgi?id=215769
>
> --- Comment #4 from Коренберг Марк (socketpair@gmail.com) ---
> #define _GNU_SOURCE 1
> #include <stdio.h>
> #include <sched.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/wait.h>
> #include <err.h>
>
> #ifndef CLONE_NEWTIME
> #define CLONE_NEWTIME 0x00000080
> #endif
>
> int main (void)
> {
> if (unshare (CLONE_NEWTIME)) err (EXIT_FAILURE, "UNSHARE_NEWTIME");
>
> pid_t pid;
> switch (pid=vfork ())
> {
> case 0:
> _exit(0);
> case -1:
> err(EXIT_FAILURE, "vfork BUG");
> default:
> waitpid(pid, NULL, 0);
> }
> return 0;
> }
>
I could reproduce it with the following code. I tried
syscall(SYS_vfork) to make sure it's not a problem in the libc wrapper,
and to make sure I do call vfork(2). If I replace vfork(2) with
fork(2), I don't get the error.
$ cat vfork.c
#define _GNU_SOURCE
#include <err.h>
#include <linux/sched.h>
#include <sched.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
int main(void)
{
pid_t pid;
if (unshare(CLONE_NEWTIME) == -1)
err(EXIT_FAILURE, "unshare(2)");
if (signal(SIGCHLD, SIG_IGN) == SIG_ERR)
err(EXIT_FAILURE, "sigaction(2)");
pid = syscall(SYS_vfork);
switch (pid) {
case 0:
errx(EXIT_SUCCESS, "Grandchild exiting normally.");
case -1:
/* If we got here, the report is confirmed. */
err(EXIT_FAILURE, "vfork(2)");
default:
errx(EXIT_SUCCESS, "Child exiting normally.");
}
}
$ cc -Wall -Wextra -Werror vfork.c
$ sudo ./a.out
a.out: vfork(2): Invalid argument
$ grep_syscall_def vfork
kernel/fork.c:2711:
SYSCALL_DEFINE0(vfork)
{
struct kernel_clone_args args = {
.flags = CLONE_VFORK | CLONE_VM,
.exit_signal = SIGCHLD,
};
return kernel_clone(&args);
}
Maybe someone in the kernel can send some patch for the clone(2) and/or
vfork(2) manual pages that explains the reason (if it's intended).
Thanks,
Alex
--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
next parent reply other threads:[~2022-04-02 21:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-215769-216477@https.bugzilla.kernel.org/>
[not found] ` <bug-215769-216477-to2O9X1Knw@https.bugzilla.kernel.org/>
2022-04-02 21:15 ` Alejandro Colomar (man-pages) [this message]
2022-04-04 8:05 ` vfork(2) fails after unshare(CLONE_NEWTIME) (was: [Bug 215769] man 2 vfork() does not document corner case when PID == 1) Christian Brauner
2022-04-05 19:28 ` vfork(2) behavior not consistent with fork(2) (was: vfork(2) fails after unshare(CLONE_NEWTIME) (was: [Bug 215769] man 2 vfork() does not document corner case when PID == 1)) Alejandro Colomar
2022-04-06 8:46 ` Christian Brauner
2022-04-06 19:22 ` Alejandro Colomar
2022-04-06 19:26 ` vfork(2) behavior not consistent with fork(2) Florian Weimer
2022-04-06 19:31 ` [Bug 215813] syscall(SYS_vfork) causes execve() to return 0. (was: vfork(2) behavior not consistent with fork(2)) 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=4fb02f5f-60f9-42af-ddd5-fe5af877231f@gmail.com \
--to=alx.manpages@gmail.com \
--cc=arnd@arndb.de \
--cc=avagin@openvz.org \
--cc=brauner@kernel.org \
--cc=bugzilla-daemon@kernel.org \
--cc=dima@arista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=socketpair@gmail.com \
--cc=tglx@linutronix.de \
/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