public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] clone.2: note EINVAL when exit_signal + bad flags
@ 2022-12-14 21:28 Jack Pearson
  2023-02-22  2:28 ` Jack Pearson
  0 siblings, 1 reply; 4+ messages in thread
From: Jack Pearson @ 2022-12-14 21:28 UTC (permalink / raw)
  To: Alejandro Colomar
  Cc: linux-man, GNU C Library, Carlos O'Donell, Jack Pearson

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(+)

diff --git a/man2/clone.2 b/man2/clone.2
index f04d713d1..3829d04c3 100644
--- a/man2/clone.2
+++ b/man2/clone.2
@@ -1435,6 +1435,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.
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] clone.2: note EINVAL when exit_signal + bad flags
  2022-12-14 21:28 [PATCH v2] clone.2: note EINVAL when exit_signal + bad flags Jack Pearson
@ 2023-02-22  2:28 ` Jack Pearson
  2023-02-25  1:04   ` Alex Colomar
  0 siblings, 1 reply; 4+ messages in thread
From: Jack Pearson @ 2023-02-22  2:28 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: linux-man, GNU C Library, Carlos O'Donell

Hello,

In this patch, I included my test program for the absence of this behavior with
normal `clone` per Alex's request:

https://lore.kernel.org/linux-man/fba3de52-91cc-6cbe-b4ae-7140564e9ad2@pearson.onl/T/#mde63a642e9c8d0b4e367b0a2817248e8e0b29a50

Let me know if there's anything else I should do.

Thanks,
Jack

On 12/14/22 13:28, Jack Pearson wrote:
> Document that Linux will report EINVAL when exit_signal is specified and
> either CLONE_THREAD or CLONE_PARENT is specified.
> 
...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] clone.2: note EINVAL when exit_signal + bad flags
  2023-02-22  2:28 ` Jack Pearson
@ 2023-02-25  1:04   ` Alex Colomar
  2023-02-28 23:43     ` Jack Pearson
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Colomar @ 2023-02-25  1:04 UTC (permalink / raw)
  To: Jack Pearson; +Cc: linux-man, GNU C Library, Carlos O'Donell


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

Hi Jack,

On 2/22/23 03:28, Jack Pearson wrote:
> Hello,
> 
> In this patch, I included my test program for the absence of this 
> behavior with
> normal `clone` per Alex's request:
> 
> https://lore.kernel.org/linux-man/fba3de52-91cc-6cbe-b4ae-7140564e9ad2@pearson.onl/T/#mde63a642e9c8d0b4e367b0a2817248e8e0b29a50
> 
> Let me know if there's anything else I should do.

Could you please resend the patch (keeping all CCs), and I'll have a 
look at it again?

Thanks for the ping,

Alex

> 
> Thanks,
> Jack
> 
> On 12/14/22 13:28, Jack Pearson wrote:
>> Document that Linux will report EINVAL when exit_signal is specified and
>> either CLONE_THREAD or CLONE_PARENT is specified.
>>
> ...

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


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] clone.2: note EINVAL when exit_signal + bad flags
  2023-02-25  1:04   ` Alex Colomar
@ 2023-02-28 23:43     ` Jack Pearson
  0 siblings, 0 replies; 4+ messages in thread
From: Jack Pearson @ 2023-02-28 23:43 UTC (permalink / raw)
  To: Alex Colomar; +Cc: linux-man, GNU C Library, Carlos O'Donell

Alright, done!

Thanks,

Jack

On 2/24/23 17:04, Alex Colomar wrote:
> Hi Jack,
> 
> On 2/22/23 03:28, Jack Pearson wrote:
>> Hello,
>>
>> In this patch, I included my test program for the absence of this behavior with
>> normal `clone` per Alex's request:
>>
>> https://lore.kernel.org/linux-man/fba3de52-91cc-6cbe-b4ae-7140564e9ad2@pearson.onl/T/#mde63a642e9c8d0b4e367b0a2817248e8e0b29a50
>>
>> Let me know if there's anything else I should do.
> 
> Could you please resend the patch (keeping all CCs), and I'll have a look at it again?
> 
> Thanks for the ping,
> 
> Alex
> 
>>
>> Thanks,
>> Jack
>>
>> On 12/14/22 13:28, Jack Pearson wrote:
>>> Document that Linux will report EINVAL when exit_signal is specified and
>>> either CLONE_THREAD or CLONE_PARENT is specified.
>>>
>> ...
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-28 23:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-14 21:28 [PATCH v2] clone.2: note EINVAL when exit_signal + bad flags Jack Pearson
2023-02-22  2:28 ` Jack Pearson
2023-02-25  1:04   ` Alex Colomar
2023-02-28 23:43     ` Jack Pearson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).