Skip to content

Commit

Permalink
Drop privileges in chroot spec (#13226)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Mar 27, 2023
1 parent 8a509b6 commit 62f27b2
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/std/process_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ describe Process do
{% if flag?(:unix) && !flag?(:android) %}
it "raises when unprivileged" do
status, output, _ = compile_and_run_source <<-'CRYSTAL'
# Try to drop privileges. Ignoring any errors because dropping is only
# necessary for a privileged user and it doesn't matter when it fails
# for an unprivileged one.
# This particular UID is often attributed to the `nobody` user.
LibC.setuid(65534)

begin
Process.chroot(".")
puts "FAIL"
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/aarch64-android/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(__fd : Int) : Int
fun ttyname_r(__fd : Int, __buf : Char*, __buf_size : SizeT) : Int
fun lchown(__path : Char*, __owner : UidT, __group : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/aarch64-darwin/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(x0 : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(x0 : Char*, x1 : UidT, x2 : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/aarch64-linux-gnu/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(fd : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(file : Char*, owner : UidT, group : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/aarch64-linux-musl/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(x0 : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(x0 : Char*, x1 : UidT, x2 : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/arm-linux-gnueabihf/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(fd : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(file : Char*, owner : UidT, group : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/i386-linux-gnu/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(fd : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(file : Char*, owner : UidT, group : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/i386-linux-musl/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(x0 : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(x0 : Char*, x1 : UidT, x2 : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-darwin/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(x0 : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(x0 : Char*, x1 : UidT, x2 : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-dragonfly/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(x0 : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(x0 : Char*, x1 : UidT, x2 : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-freebsd/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(x0 : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(x0 : Char*, x1 : UidT, x2 : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-linux-gnu/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(fd : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(file : Char*, owner : UidT, group : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-linux-musl/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(x0 : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(x0 : Char*, x1 : UidT, x2 : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-netbsd/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(x0 : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown = __posix_lchown(x0 : Char*, x1 : UidT, x2 : GidT) : Int
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-openbsd/c/unistd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ lib LibC
fun getpid : PidT
fun getppid : PidT
fun getuid : UidT
fun setuid(uid : UidT) : Int
fun isatty(x0 : Int) : Int
fun ttyname_r(fd : Int, buf : Char*, buffersize : SizeT) : Int
fun lchown(x0 : Char*, x1 : UidT, x2 : GidT) : Int
Expand Down

0 comments on commit 62f27b2

Please sign in to comment.