All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: Jack Pearson <jack@pearson.onl>, linux-man@vger.kernel.org
Cc: Carlos O'Donell <carlos@redhat.com>,
	GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] clone.2: note EINVAL when exit_signal + bad flags
Date: Wed, 1 Mar 2023 22:31:38 +0100	[thread overview]
Message-ID: <1ec9c450-3bb3-b6e9-b3f1-112869b62798@gmail.com> (raw)
In-Reply-To: <20230228234246.466811-1-jack@pearson.onl>


[-- Attachment #1.1: Type: text/plain, Size: 2279 bytes --]

Hi Jack,

On 3/1/23 00:42, Jack Pearson wrote:
> Document that Linux will report EINVAL when exit_signal is specified and
> either CLONE_THREAD or CLONE_PARENT is specified.
> 
> From clone3_args_valid in Linux:
> ```
> 	if ((kargs->flags & (CLONE_THREAD | CLONE_PARENT)) &&
> 	    kargs->exit_signal)
> 		return false;
> ```
> 
> I have verified that this happens on my kernel with a small program:
> 
> ```
> #include <stdio.h>
> #include <linux/sched.h>
> #include <signal.h>
> #include <sys/syscall.h>
> #include <unistd.h>
> 
> int main() {
> 	struct clone_args ca = {
> 		.flags = CLONE_THREAD | CLONE_SIGHAND | CLONE_VM,
> 		.exit_signal = SIGCHLD, // comment me out to fix error
> 		.set_tid_size = 0,
> 	};
> 	syscall(SYS_clone3, &ca, sizeof(struct clone_args));
> 	perror("");
> }
> ```
> 
> And I have verified that this doesn't happen with normal `clone` through
> the glibc helper:
> 
> ```
> #define _GNU_SOURCE
> 
> #include <sched.h>
> #include <signal.h>
> #include <stdio.h>
> #include <sys/mman.h>
> 
> int do_nothing(void *_) { return 0; }
> 
> int main() {
>         void *map = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE,
> 	                 MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
> 	void *stack_top = map + 0x10000 - 1;
> 	clone(do_nothing, stack_top,
> 	      CLONE_THREAD | CLONE_VM | CLONE_SIGHAND | SIGCHLD, NULL);
> 	perror("");
> }
> ```
> 
> Signed-off-by: Jack Pearson <jack@pearson.onl>
> ---
>  man2/clone.2 | 10 ++++++++++
>  1 file changed, 10 insertions(+)

Patch applied.  Thanks!

Alex

> 
> diff --git a/man2/clone.2 b/man2/clone.2
> index d63895189..be802a280 100644
> --- a/man2/clone.2
> +++ b/man2/clone.2
> @@ -1436,6 +1436,16 @@ One of the PIDs specified in
>  .I set_tid
>  was an invalid.
>  .TP
> +.BR EINVAL " (" clone3 "() only)"
> +.\" commit 7f192e3cd316ba58c88dfa26796cf77789dd9872
> +.B CLONE_THREAD
> +or
> +.B CLONE_PARENT
> +was specified in the
> +.I flags
> +mask, but a signal was specified in
> +.I exit_signal.
> +.TP
>  .BR EINVAL " (AArch64 only, Linux 4.6 and earlier)"
>  .I stack
>  was not aligned to a 128-bit boundary.

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-03-01 21:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28 23:42 [PATCH] clone.2: note EINVAL when exit_signal + bad flags Jack Pearson
2023-03-01 21:31 ` Alejandro Colomar [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-12-02 22:44 Jack Pearson
2022-12-09 19:49 ` Alejandro Colomar
2022-12-13  2:53   ` Carlos O'Donell
2022-12-13 22:59     ` Alejandro Colomar
2022-12-14 21:00     ` Jack Pearson
2022-12-14 21:02       ` Alejandro Colomar
2022-12-14 21:13         ` Jack Pearson

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=1ec9c450-3bb3-b6e9-b3f1-112869b62798@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=carlos@redhat.com \
    --cc=jack@pearson.onl \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-man@vger.kernel.org \
    /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.