Bug 13134

Summary: posix_spawn() invokes sh on unknown executable image types
Product: glibc Reporter: Shea Levy <shea>
Component: libcAssignee: Ulrich Drepper <drepper.fsp>
Status: RESOLVED FIXED    
Severity: normal CC: bruno, bugdal, fweimer, shea
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: Trivial fix

Description Shea Levy 2011-08-25 20:46:01 UTC
The current glibc implementation of posix_spawn() invokes /bin/sh if execve sets errno to ENOEXEC. This is not specified by the POSIX.2004 definition (http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html), is different from the behavior of the sample implementation in the POSIX.2004 rationale section (http://pubs.opengroup.org/onlinepubs/009604599/xrat/xsh_chap03.html), and seems to have the same security risks that system() and popen() do in set{u,g}id executables. In particular, the Rationale section says "The effective behavior of a successful invocation of posix_spawn() is as if the operation were implemented with POSIX operations as follows:", which as I've said is followed by an implementation that behaves differently than the glibc posix_spawn(). This appears to be non-compliant behavior.
Comment 1 Rich Felker 2011-08-26 06:12:58 UTC
Confirmed. My cynical prediction is that this bug will be ignored either for "compatibility reasons" or because of the fact that someone obviously went to a bit of trouble to write that completely wrong code for shell invocation that doesn't even belong in spawni.c. Please prove me wrong...
Comment 2 Shea Levy 2011-08-26 08:35:19 UTC
Created attachment 5915 [details]
Trivial fix

This patch removes the non-compliant behaviour.
Comment 3 Ulrich Drepper 2011-09-06 00:26:50 UTC
You really don't know what binary compatibility means, right?  git contains a change.
Comment 4 Shea Levy 2011-09-06 00:38:09 UTC
(In reply to comment #3)
> You really don't know what binary compatibility means, right?  git contains a
> change.

Sorry, my fix was far too naive. I shouldn't have submitted that patch at all if I wasn't going to take the time to get it right.
Comment 5 Bruno Haible 2020-12-26 15:59:16 UTC
The change from 2011 had no effect on the Hurd.
The Hurd case has been fixed now, by Samuel Thibault:
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=13adfa34aff03fd9f1c1612b537a0d736ddb6c2b