From: Rich Felker <dalias@libc.org>
To: Tudor Cretu <tudor.cretu@arm.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] clone: Return EINVAL for null stack
Date: Tue, 2 Aug 2022 14:53:46 -0400 [thread overview]
Message-ID: <20220802185346.GS7074@brightrain.aerifal.cx> (raw)
In-Reply-To: <20220802113036.302819-1-tudor.cretu@arm.com>
On Tue, Aug 02, 2022 at 12:30:36PM +0100, Tudor Cretu wrote:
> This change aligns the clone wrapper with the man page. If the stack is
> null, clone sets errno to EINVAL, instead of throwing a segmentation fault.
> ---
> src/linux/clone.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/src/linux/clone.c b/src/linux/clone.c
> index 8c1af7d3..43a6803b 100644
> --- a/src/linux/clone.c
> +++ b/src/linux/clone.c
> @@ -1,4 +1,5 @@
> #define _GNU_SOURCE
> +#include <errno.h>
> #include <stdarg.h>
> #include <unistd.h>
> #include <sched.h>
> @@ -11,6 +12,10 @@ int clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
> pid_t *ptid, *ctid;
> void *tls;
>
> + if (!stack) {
> + return __syscall_ret(-EINVAL);
> + }
> +
> va_start(ap, arg);
> ptid = va_arg(ap, pid_t *);
> tls = va_arg(ap, void *);
> --
> 2.25.1
This is probably okay, but there's also a bigger discussion to be had
here about what to do about clone() -- deciding what the contract is
for what usage can be supported, and possibly making the rest produce
errors like the above. There's also a matter of the current very-wrong
use of va_arg for variadic arguments that might not exist, and which
probably *can't* exist in any valid application usage. This came up
before as part of the mt-fork work, but was basically deferred
indefinitely...
Rich
next prev parent reply other threads:[~2022-08-02 18:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 11:30 Tudor Cretu
2022-08-02 18:53 ` Rich Felker [this message]
2022-08-03 14:42 ` Tudor Cretu
2022-08-03 16:42 ` Rich Felker
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=20220802185346.GS7074@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
--cc=tudor.cretu@arm.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).