clone.2: note EINVAL when exit_signal + bad flags
PATCH v2 1/1 clone.2: note EINVAL when exit_signal + bad flags
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("");
}
```--- man2/clone.2 | 10 ++++++++++ 1 file changed, 10 insertions(+)
man2/clone.2 +10 -0
@@ -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.
Signature · 1 line
2.35.1
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/[email protected]/T/#mde63a642e9c8d0b4e367b0a2817248e8e0b29a50
Let me know if there's anything else I should do.
Thanks,
Jack
Quoted 3 lines · Jack Pearson
Document that Linux will report EINVAL when
exit_signalis specified and eitherCLONE_THREADorCLONE_PARENTis specified.
...
Hi Jack,
Quoted 8 lines · Jack Pearson
Hello,
In this patch, I included my test program for the absence of this behavior with normal
cloneper Alex's request:https://lore.kernel.org/linux-man/[email protected]/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
Quoted 9 lines
Thanks,
JackQuoted 3 lines · Jack Pearson
Document that Linux will report EINVAL when
exit_signalis specified and eitherCLONE_THREADorCLONE_PARENTis specified....
Signature · 2 lines
<http://www.alejandro-colomar.es/> GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
Alright, done!
Thanks,
Jack
Quoted 28 lines · Alex Colomar
Hi Jack,
Quoted 8 lines · Jack Pearson
Hello,
In this patch, I included my test program for the absence of this behavior with normal
cloneper Alex's request:https://lore.kernel.org/linux-man/[email protected]/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
Quoted 9 lines
Thanks,
JackQuoted 3 lines · Jack Pearson
Document that Linux will report EINVAL when
exit_signalis specified and eitherCLONE_THREADorCLONE_PARENTis specified....