#54963 closed defect (fixed)
Ports cannot set setuid bit
Reported by: | danchr (Dan Villiom Podlaski Christiansen) | Owned by: | raimue (Rainer Müller) |
---|---|---|---|
Priority: | Normal | Milestone: | MacPorts 2.4.2 |
Component: | base | Version: | 2.4.99 |
Keywords: | highsierra | Cc: | ryandesign (Ryan Carsten Schmidt), Schamschula (Marius Schamschula), raimue (Rainer Müller), jmroot (Joshua Root) |
Port: |
Description
Found in bug #54958:
Ports cannot set the setuid bit on High Sierra; it works outside the ports infrastructure, but not within it. The attached tarball contains a simple port that tries to set the setuid bit on a file, checks that it succeeds. The ‘build’ phase fails on High Sierra.
Attachments (1)
Change History (11)
comment:1 Changed 7 years ago by raimue (Rainer Müller)
Cc: | raimue added |
---|
comment:2 follow-up: 3 Changed 7 years ago by raimue (Rainer Müller)
The problem appears to occur due to sandbox-exec
:
highsierra $ files/test.sh -rwsr-xr-x+ 1 raimue wheel 0 Oct 1 20:29 xxx -rwsr-xr-x -> 104755 highsierra $ rm -f xxx highsierra $ sandbox-exec -p '(version 1) (allow default)' files/test.sh -rwxr-xr-x+ 1 raimue wheel 0 Oct 1 20:29 xxx -rwxr-xr-x -> 100755
That behavior changed from macOS 10.12 Sierra:
sierra $ sandbox-exec -p '(version 1) (allow default)' files/test.sh -rwsr-xr-x+ 1 raimue wheel 0 Oct 1 20:29 xxx -rwsr-xr-x -> 104755
Changed 7 years ago by danchr (Dan Villiom Podlaski Christiansen)
Attachment: | setuid-test.tar added |
---|
Fixed test port
comment:3 Changed 7 years ago by danchr (Dan Villiom Podlaski Christiansen)
Replying to raimue:
The problem appears to occur due to
sandbox-exec
: […]
Interestingly, it works if you cd into files and invoke ./test.sh
instead…
comment:4 Changed 7 years ago by danchr (Dan Villiom Podlaski Christiansen)
Summary: | Ports cannot set sticky bit → Ports cannot set setuid bit |
---|
comment:5 Changed 7 years ago by raimue (Rainer Müller)
I can get it to work if I grant the file-write-setugid
permission explicitly. I guess the default changed, but I have no idea how to retrieve that to confirm it.
highsierra $ sandbox-exec -p '(version 1) (allow default) (allow file-write-setugid)' files/test.sh -rwsr-xr-x+ 1 raimue wheel 0 Oct 1 20:44 xxx -rwsr-xr-x -> 104755
As a side note, it looks like Apple also killed the very useful tracing ability with sandbox-exec -p '(version 1) (deny default) (trace "xxx.sb")' ...
that reports all actions that would were attempted while still allowing all actions. This is the way I could debug this using Sierra. No idea how something like that could be done on High Sierra alone...
comment:6 Changed 7 years ago by danchr (Dan Villiom Podlaski Christiansen)
AFAICT this fixes it:
-
src/port1.0/portsandbox.tcl
diff --git a/src/port1.0/portsandbox.tcl b/src/port1.0/portsandbox.tcl
a b proc portsandbox::set_profile {target} { 89 89 (regex #\"^(/private)?(/var)?/tmp/\" #\"^(/private)?/var/folders/\"))" 90 90 91 91 foreach dir $allow_dirs { 92 append portsandbox_profile " (allow file-write* ("92 append portsandbox_profile " (allow file-write* file-write-setugid (" 93 93 if {${os.major} > 9} { 94 94 append portsandbox_profile "subpath \"${dir}\"))" 95 95 } else {
comment:7 Changed 7 years ago by ryandesign (Ryan Carsten Schmidt)
Cc: | jmroot added |
---|
Sounds like we should get a MacPorts 2.4.2 out quickly with this fix.
comment:8 Changed 7 years ago by raimue (Rainer Müller)
comment:9 Changed 7 years ago by raimue (Rainer Müller)
Owner: | set to raimue |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:10 Changed 7 years ago by raimue (Rainer Müller)
Milestone: | → MacPorts 2.4.2 |
---|
This fix was released with MacPorts 2.4.2.
The test script uses
chmod u+t
, which is invalid. This is the sticky bit (+t), not setuid (+s). The sticky bit cannot be set in combination with any ofugo
as it is a global flag. This should readchmod u+s
.Also the result in the test command in the last line for
stat -f %p
should probably be104755
.After fixing the issues above with
chmod u+s
and104755
, I can confirm that this port works on macOS 10.12 Sierra, but not on macOS 10.13 High Sierra.