Bug 877 - Sudo executes all process with ENOEXEC return as a shell script
Sudo executes all process with ENOEXEC return as a shell script
Status: ASSIGNED
Product: Sudo
Classification: Unclassified
Component: Sudo
1.8.27
All All
: low low
Assigned To: Todd C. Miller
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2019-03-18 03:30 MDT by Sam Bingner
Modified: 2019-03-18 13:03 MDT (History)
0 users

See Also:


Attachments
Patch to fix the issue (738 bytes, application/octet-stream)
2019-03-18 03:30 MDT, Sam Bingner
Details
Corrected patch (777 bytes, patch)
2019-03-18 03:43 MDT, Sam Bingner
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Bingner 2019-03-18 03:30:45 MDT
Created attachment 522 [details]
Patch to fix the issue

If sudo gets ENOEXEC it will execute '/bin/sh file args' where it should be '/bin/sh -c "file" args' as the former tries to execute any file as a shell script.

Patch to fix this on 1.8.27 attached
Comment 1 Sam Bingner 2019-03-18 03:35:18 MDT
This patch is bad, fixing :|
Comment 2 Sam Bingner 2019-03-18 03:43:36 MDT
Created attachment 523 [details]
Corrected patch

This should correct the issue because if ENOEXEC is encountered, the shell will correctly interpret the proper command from the shebang.  My original patch erroneously did not include arguments to the command being executed.
Comment 3 Todd C. Miller 2019-03-18 07:05:53 MDT
I'm sorry but I don't think this is correct.  The current behavior is consistent with how the execvp(3) C library function and /bin/sh behave.

The purpose is to support shell scripts *without* a shebang.  If a shebang was present we should not get ENOEXEC when trying to execute it in the first place.

What problem are you trying to solve?
Comment 4 Sam Bingner 2019-03-18 12:52:08 MDT
Some OS do not have kernel support for shebangs, that is when this patch would make a difference.  

You can see how bash handles these things here: http://git.savannah.gnu.org/cgit/bash.git/tree/execute_cmd.c#n5731

The logic to handle shebangs in bash is just before that comment at line 5701.  As you can see it says that it should only treat it as a shell script if there is NO shebang and it is a non-binary file.  If you don't like letting the shell handle the logic, I could port over the bash logic.
Comment 5 Todd C. Miller 2019-03-18 12:57:08 MDT
Are you actually using such an OS or is this just theoretical?
Comment 6 Sam Bingner 2019-03-18 13:03:20 MDT
I sort of use such an OS.  On jailbroken iOS (iPhones) apple has disabled support for shebang scripts.