mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Bruno Haible <bruno@clisp.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] insufficient checking in posix_spawn_file_actions_add{open,dup2}
Date: Mon, 25 Jan 2021 09:42:36 -0500	[thread overview]
Message-ID: <20210125144236.GV23432@brightrain.aerifal.cx> (raw)
In-Reply-To: <3521697.b4TYcCAa2N@omega>

On Mon, Jan 25, 2021 at 09:31:50AM +0100, Bruno Haible wrote:
> Hi,
> 
> POSIX [1][2] says about the functions
>   posix_spawn_file_actions_addopen
>   posix_spawn_file_actions_adddup2
> 
> The function "shall fail if:
>   [EBADF]
>       The value specified by fildes is negative or greater than or equal to {OPEN_MAX}."
> 
> However, in musl libc 1.2.2, these two test programs exit with status 2:
> ========================================================================
> #include <spawn.h>
> #include <fcntl.h>
> int main ()
> {
>   posix_spawn_file_actions_t actions;
>   if (posix_spawn_file_actions_init (&actions) != 0)
>     return 1;
>   if (posix_spawn_file_actions_addopen (&actions, 10000000, "foo", 0, O_RDONLY)
>       == 0)
>     return 2;
>   return 0;
> }
> ========================================================================
> #include <spawn.h>
> int main ()
> {
>   posix_spawn_file_actions_t actions;
>   if (posix_spawn_file_actions_init (&actions) != 0)
>     return 1;
>   if (posix_spawn_file_actions_adddup2 (&actions, 10000000, 2) == 0)
>     return 2;
>   return 0;
> }
> ========================================================================
> 
> sysconf (_SC_OPEN_MAX) is 1024, on that system.
> 
> Best regards,
> 
>       Bruno
> 
> [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn_file_actions_addopen.html
> [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn_file_actions_adddup2.html

Thanks. I think I was vaguely aware of this, but misremembered
https://www.austingroupbugs.net/view.php?id=418 as dropping the
requirement (which is rather odious, especially if a file action for
changing rlimit were ever to be added) rather than just removing it
for close.

With that said, is there any normative text that {OPEN_MAX} in the
spec indicates a requirement to honor a dynamic max
sysconf(_SC_OPEN_MAX)? As written, the "shall fail" seems to apply
just on systems where OPEN_MAX is defined; sysconf isn't referenced. I
would very much prefer not to have to enforce such a max here since
it's hostile to future extensibility and wastes a syscall in an
operation that should not require one.

In any case negative values should be checked.

Rich

  parent reply	other threads:[~2021-01-25 14:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25  8:31 Bruno Haible
2021-01-25  8:40 ` [musl] insufficient checking in posix_spawn_file_actions_addclose Bruno Haible
2021-01-25 14:42 ` Rich Felker [this message]
2021-01-25 16:07   ` [musl] insufficient checking in posix_spawn_file_actions_add{open,dup2} Bruno Haible
2021-01-25 16:15     ` Rich Felker
2021-01-25 17:58       ` Bruno Haible
2021-01-25 19:33       ` Alexey Izbyshev
2021-01-25 19:37       ` Markus Wichmann
2021-01-25 19:48         ` Florian Weimer

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=20210125144236.GV23432@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=bruno@clisp.org \
    --cc=musl@lists.openwall.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).