Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 25 Jan 2021 09:42:36 -0500
From: Rich Felker <dalias@...c.org>
To: Bruno Haible <bruno@...sp.org>
Cc: musl@...ts.openwall.com
Subject: Re: insufficient checking in
 posix_spawn_file_actions_add{open,dup2}

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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.