X7ROOT File Manager
Current Path:
/opt/golang/1.22.0/src/syscall
opt
/
golang
/
1.22.0
/
src
/
syscall
/
📁
..
📄
asan.go
(410 B)
📄
asan0.go
(342 B)
📄
asm9_unix2_amd64.s
(1.19 KB)
📄
asm_aix_ppc64.s
(540 B)
📄
asm_darwin_amd64.s
(2.93 KB)
📄
asm_darwin_arm64.s
(2.83 KB)
📄
asm_freebsd_arm.s
(2.96 KB)
📄
asm_freebsd_arm64.s
(2.79 KB)
📄
asm_freebsd_riscv64.s
(2.76 KB)
📄
asm_linux_386.s
(3.08 KB)
📄
asm_linux_amd64.s
(1.33 KB)
📄
asm_linux_arm.s
(1.77 KB)
📄
asm_linux_arm64.s
(916 B)
📄
asm_linux_loong64.s
(947 B)
📄
asm_linux_mips64x.s
(985 B)
📄
asm_linux_mipsx.s
(1.75 KB)
📄
asm_linux_ppc64x.s
(913 B)
📄
asm_linux_riscv64.s
(861 B)
📄
asm_linux_s390x.s
(2.15 KB)
📄
asm_netbsd_arm.s
(2.85 KB)
📄
asm_netbsd_arm64.s
(2.88 KB)
📄
asm_openbsd_386.s
(1.04 KB)
📄
asm_openbsd_amd64.s
(1.04 KB)
📄
asm_openbsd_arm.s
(1.04 KB)
📄
asm_openbsd_arm64.s
(1.04 KB)
📄
asm_openbsd_mips64.s
(2.85 KB)
📄
asm_openbsd_ppc64.s
(1.04 KB)
📄
asm_openbsd_riscv64.s
(1.04 KB)
📄
asm_plan9_386.s
(3.14 KB)
📄
asm_plan9_amd64.s
(3.36 KB)
📄
asm_plan9_arm.s
(3.25 KB)
📄
asm_solaris_amd64.s
(1.8 KB)
📄
asm_unix_386.s
(2.74 KB)
📄
asm_unix_amd64.s
(2.15 KB)
📄
bpf_bsd.go
(4.03 KB)
📄
const_plan9.go
(1.36 KB)
📄
creds_test.go
(3.37 KB)
📄
dir_plan9.go
(5.62 KB)
📄
dirent.go
(3.09 KB)
📄
dirent_test.go
(3.43 KB)
📄
dll_windows.go
(7.63 KB)
📄
endian_big.go
(249 B)
📄
endian_little.go
(309 B)
📄
env_unix.go
(2.73 KB)
📄
env_windows.go
(1.96 KB)
📄
errors_plan9.go
(1.61 KB)
📄
exec_aix_test.go
(823 B)
📄
exec_bsd.go
(7.95 KB)
📄
exec_freebsd.go
(8.43 KB)
📄
exec_freebsd_test.go
(2.41 KB)
📄
exec_libc.go
(8.17 KB)
📄
exec_libc2.go
(8.19 KB)
📄
exec_linux.go
(22.81 KB)
📄
exec_linux_test.go
(20.37 KB)
📄
exec_pdeathsig_test.go
(4.49 KB)
📄
exec_plan9.go
(13.25 KB)
📄
exec_solaris_test.go
(815 B)
📄
exec_unix.go
(8.63 KB)
📄
exec_unix_test.go
(8.28 KB)
📄
exec_windows.go
(10.3 KB)
📄
exec_windows_test.go
(3.11 KB)
📄
export_darwin_test.go
(348 B)
📄
export_linux_test.go
(296 B)
📄
export_rlimit_test.go
(262 B)
📄
export_unix_test.go
(391 B)
📄
export_wasip1_test.go
(267 B)
📄
export_windows_test.go
(500 B)
📄
flock_aix.go
(564 B)
📄
flock_bsd.go
(469 B)
📄
flock_linux.go
(641 B)
📄
flock_linux_32bit.go
(511 B)
📄
forkpipe.go
(604 B)
📄
forkpipe2.go
(2.6 KB)
📄
fs_js.go
(10.84 KB)
📄
fs_wasip1.go
(24.07 KB)
📄
fs_wasip1_test.go
(1.98 KB)
📄
getdirentries_test.go
(2.07 KB)
📁
js
📄
lsf_linux.go
(2.12 KB)
📄
mkall.sh
(14.62 KB)
📄
mkasm.go
(1.88 KB)
📄
mkerrors.sh
(10.71 KB)
📄
mkpost.go
(2.28 KB)
📄
mksyscall.pl
(10.19 KB)
📄
mksyscall_libc.pl
(8.02 KB)
📄
mksyscall_windows.go
(1.99 KB)
📄
mksysctl_openbsd.pl
(5.04 KB)
📄
mksysnum_dragonfly.pl
(866 B)
📄
mksysnum_freebsd.pl
(1.35 KB)
📄
mksysnum_linux.pl
(1.26 KB)
📄
mksysnum_netbsd.pl
(1.01 KB)
📄
mksysnum_openbsd.pl
(872 B)
📄
mksysnum_plan9.sh
(459 B)
📄
mmap_unix_test.go
(500 B)
📄
msan.go
(410 B)
📄
msan0.go
(342 B)
📄
net.go
(1.19 KB)
📄
net_fake.go
(883 B)
📄
net_js.go
(1.38 KB)
📄
net_wasip1.go
(1.82 KB)
📄
netlink_linux.go
(4.77 KB)
📄
os_wasip1.go
(252 B)
📄
pwd_plan9.go
(2.27 KB)
📄
rlimit.go
(1.59 KB)
📄
rlimit_darwin.go
(593 B)
📄
rlimit_stub.go
(338 B)
📄
rlimit_test.go
(953 B)
📄
route_bsd.go
(9.1 KB)
📄
route_darwin.go
(2.01 KB)
📄
route_dragonfly.go
(2.61 KB)
📄
route_freebsd.go
(2.67 KB)
📄
route_freebsd_32bit.go
(1.14 KB)
📄
route_freebsd_64bit.go
(762 B)
📄
route_netbsd.go
(1.43 KB)
📄
route_openbsd.go
(1.46 KB)
📄
security_windows.go
(10.01 KB)
📄
setuidgid_32_linux.go
(435 B)
📄
setuidgid_linux.go
(421 B)
📄
sockcmsg_dragonfly.go
(547 B)
📄
sockcmsg_linux.go
(1.12 KB)
📄
sockcmsg_unix.go
(2.51 KB)
📄
sockcmsg_unix_other.go
(1.08 KB)
📄
syscall.go
(3.78 KB)
📄
syscall_aix.go
(17.9 KB)
📄
syscall_aix_ppc64.go
(405 B)
📄
syscall_bsd.go
(13.63 KB)
📄
syscall_bsd_test.go
(1.17 KB)
📄
syscall_darwin.go
(10.74 KB)
📄
syscall_darwin_amd64.go
(1.91 KB)
📄
syscall_darwin_arm64.go
(1.82 KB)
📄
syscall_dragonfly.go
(8.55 KB)
📄
syscall_dragonfly_amd64.go
(1.12 KB)
📄
syscall_freebsd.go
(8.72 KB)
📄
syscall_freebsd_386.go
(1.17 KB)
📄
syscall_freebsd_amd64.go
(1.12 KB)
📄
syscall_freebsd_arm.go
(1.16 KB)
📄
syscall_freebsd_arm64.go
(1.12 KB)
📄
syscall_freebsd_riscv64.go
(1.12 KB)
📄
syscall_freebsd_test.go
(424 B)
📄
syscall_illumos.go
(613 B)
📄
syscall_js.go
(6.71 KB)
📄
syscall_linux.go
(35.62 KB)
📄
syscall_linux_386.go
(10.34 KB)
📄
syscall_linux_accept.go
(961 B)
📄
syscall_linux_accept4.go
(592 B)
📄
syscall_linux_amd64.go
(4.78 KB)
📄
syscall_linux_arm.go
(7.05 KB)
📄
syscall_linux_arm64.go
(6.21 KB)
📄
syscall_linux_loong64.go
(7.08 KB)
📄
syscall_linux_mips64x.go
(5.98 KB)
📄
syscall_linux_mipsx.go
(6.85 KB)
📄
syscall_linux_ppc64x.go
(4.63 KB)
📄
syscall_linux_riscv64.go
(5.75 KB)
📄
syscall_linux_s390x.go
(7.9 KB)
📄
syscall_linux_test.go
(21.1 KB)
📄
syscall_netbsd.go
(7.78 KB)
📄
syscall_netbsd_386.go
(716 B)
📄
syscall_netbsd_amd64.go
(709 B)
📄
syscall_netbsd_arm.go
(716 B)
📄
syscall_netbsd_arm64.go
(709 B)
📄
syscall_openbsd.go
(6.97 KB)
📄
syscall_openbsd1.go
(534 B)
📄
syscall_openbsd_386.go
(715 B)
📄
syscall_openbsd_amd64.go
(701 B)
📄
syscall_openbsd_arm.go
(715 B)
📄
syscall_openbsd_arm64.go
(906 B)
📄
syscall_openbsd_libc.go
(3.28 KB)
📄
syscall_openbsd_mips64.go
(970 B)
📄
syscall_openbsd_ppc64.go
(906 B)
📄
syscall_openbsd_riscv64.go
(906 B)
📄
syscall_plan9.go
(9.37 KB)
📄
syscall_plan9_test.go
(1.15 KB)
📄
syscall_ptrace_test.go
(768 B)
📄
syscall_solaris.go
(15.66 KB)
📄
syscall_solaris_amd64.go
(487 B)
📄
syscall_solarisonly.go
(304 B)
📄
syscall_test.go
(1.44 KB)
📄
syscall_unix.go
(12.11 KB)
📄
syscall_unix_test.go
(9.43 KB)
📄
syscall_wasip1.go
(9.37 KB)
📄
syscall_windows.go
(52.6 KB)
📄
syscall_windows_test.go
(5.73 KB)
📄
tables_js.go
(19.17 KB)
📄
tables_wasip1.go
(6.49 KB)
📄
time_fake.go
(677 B)
📄
time_nofake.go
(351 B)
📄
timestruct.go
(954 B)
📄
types_aix.go
(3.35 KB)
📄
types_darwin.go
(5.03 KB)
📄
types_dragonfly.go
(5.05 KB)
📄
types_freebsd.go
(6.72 KB)
📄
types_illumos_amd64.go
(379 B)
📄
types_linux.go
(10.9 KB)
📄
types_netbsd.go
(4.77 KB)
📄
types_openbsd.go
(5.04 KB)
📄
types_solaris.go
(4.88 KB)
📄
types_windows.go
(27.75 KB)
📄
types_windows_386.go
(477 B)
📄
types_windows_amd64.go
(477 B)
📄
types_windows_arm.go
(477 B)
📄
types_windows_arm64.go
(477 B)
📄
wtf8_windows.go
(2.67 KB)
📄
wtf8_windows_test.go
(4.31 KB)
📄
zerrors_aix_ppc64.go
(47.16 KB)
📄
zerrors_darwin_amd64.go
(55.28 KB)
📄
zerrors_darwin_arm64.go
(55.79 KB)
📄
zerrors_dragonfly_amd64.go
(59.62 KB)
📄
zerrors_freebsd_386.go
(67.35 KB)
📄
zerrors_freebsd_amd64.go
(67.4 KB)
📄
zerrors_freebsd_arm.go
(67.34 KB)
📄
zerrors_freebsd_arm64.go
(67.41 KB)
📄
zerrors_freebsd_riscv64.go
(67.41 KB)
📄
zerrors_linux_386.go
(57.36 KB)
📄
zerrors_linux_amd64.go
(57.39 KB)
📄
zerrors_linux_arm.go
(57.88 KB)
📄
zerrors_linux_arm64.go
(68.57 KB)
📄
zerrors_linux_loong64.go
(82.47 KB)
📄
zerrors_linux_mips.go
(69.18 KB)
📄
zerrors_linux_mips64.go
(68.5 KB)
📄
zerrors_linux_mips64le.go
(68.5 KB)
📄
zerrors_linux_mipsle.go
(69.18 KB)
📄
zerrors_linux_ppc64.go
(70.89 KB)
📄
zerrors_linux_ppc64le.go
(71.84 KB)
📄
zerrors_linux_riscv64.go
(70.8 KB)
📄
zerrors_linux_s390x.go
(73.28 KB)
📄
zerrors_netbsd_386.go
(67.48 KB)
📄
zerrors_netbsd_amd64.go
(67.07 KB)
📄
zerrors_netbsd_arm.go
(66.49 KB)
📄
zerrors_netbsd_arm64.go
(67.07 KB)
📄
zerrors_openbsd_386.go
(62.52 KB)
📄
zerrors_openbsd_amd64.go
(62.48 KB)
📄
zerrors_openbsd_arm.go
(62.47 KB)
📄
zerrors_openbsd_arm64.go
(66.36 KB)
📄
zerrors_openbsd_mips64.go
(66.66 KB)
📄
zerrors_openbsd_ppc64.go
(67.14 KB)
📄
zerrors_openbsd_riscv64.go
(67.1 KB)
📄
zerrors_solaris_amd64.go
(50.72 KB)
📄
zerrors_windows.go
(9.97 KB)
📄
zsyscall_aix_ppc64.go
(41.4 KB)
📄
zsyscall_darwin_amd64.go
(51.72 KB)
📄
zsyscall_darwin_amd64.s
(8.7 KB)
📄
zsyscall_darwin_arm64.go
(51.67 KB)
📄
zsyscall_darwin_arm64.s
(8.67 KB)
📄
zsyscall_dragonfly_amd64.go
(31.67 KB)
📄
zsyscall_freebsd_386.go
(31.21 KB)
📄
zsyscall_freebsd_amd64.go
(31.07 KB)
📄
zsyscall_freebsd_arm.go
(31.23 KB)
📄
zsyscall_freebsd_arm64.go
(31.07 KB)
📄
zsyscall_freebsd_riscv64.go
(31.07 KB)
📄
zsyscall_linux_386.go
(34.68 KB)
📄
zsyscall_linux_amd64.go
(39.5 KB)
📄
zsyscall_linux_arm.go
(38.92 KB)
📄
zsyscall_linux_arm64.go
(37.81 KB)
📄
zsyscall_linux_loong64.go
(37.08 KB)
📄
zsyscall_linux_mips.go
(40.34 KB)
📄
zsyscall_linux_mips64.go
(40.34 KB)
📄
zsyscall_linux_mips64le.go
(40.35 KB)
📄
zsyscall_linux_mipsle.go
(40.34 KB)
📄
zsyscall_linux_ppc64.go
(40.98 KB)
📄
zsyscall_linux_ppc64le.go
(40.99 KB)
📄
zsyscall_linux_riscv64.go
(37.84 KB)
📄
zsyscall_linux_s390x.go
(35.3 KB)
📄
zsyscall_netbsd_386.go
(30.11 KB)
📄
zsyscall_netbsd_amd64.go
(29.97 KB)
📄
zsyscall_netbsd_arm.go
(30.12 KB)
📄
zsyscall_netbsd_arm64.go
(29.97 KB)
📄
zsyscall_openbsd_386.go
(48.07 KB)
📄
zsyscall_openbsd_386.s
(8.09 KB)
📄
zsyscall_openbsd_amd64.go
(47.92 KB)
📄
zsyscall_openbsd_amd64.s
(8.09 KB)
📄
zsyscall_openbsd_arm.go
(48.09 KB)
📄
zsyscall_openbsd_arm.s
(8.09 KB)
📄
zsyscall_openbsd_arm64.go
(47.92 KB)
📄
zsyscall_openbsd_arm64.s
(8.09 KB)
📄
zsyscall_openbsd_mips64.go
(30.05 KB)
📄
zsyscall_openbsd_ppc64.go
(47.92 KB)
📄
zsyscall_openbsd_ppc64.s
(8.78 KB)
📄
zsyscall_openbsd_riscv64.go
(47.93 KB)
📄
zsyscall_openbsd_riscv64.s
(8.09 KB)
📄
zsyscall_plan9_386.go
(6.17 KB)
📄
zsyscall_plan9_amd64.go
(6.18 KB)
📄
zsyscall_plan9_arm.go
(6.17 KB)
📄
zsyscall_solaris_amd64.go
(37.56 KB)
📄
zsyscall_windows.go
(56.73 KB)
📄
zsysctl_openbsd.go
(11.39 KB)
📄
zsysnum_darwin_amd64.go
(14.55 KB)
📄
zsysnum_darwin_arm64.go
(14.39 KB)
📄
zsysnum_dragonfly_amd64.go
(22.94 KB)
📄
zsysnum_freebsd_386.go
(25.46 KB)
📄
zsysnum_freebsd_amd64.go
(25.46 KB)
📄
zsysnum_freebsd_arm.go
(25.46 KB)
📄
zsysnum_freebsd_arm64.go
(35.79 KB)
📄
zsysnum_freebsd_riscv64.go
(35.79 KB)
📄
zsysnum_linux_386.go
(11.27 KB)
📄
zsysnum_linux_amd64.go
(10.11 KB)
📄
zsysnum_linux_arm.go
(11.55 KB)
📄
zsysnum_linux_arm64.go
(8.95 KB)
📄
zsysnum_linux_loong64.go
(10.28 KB)
📄
zsysnum_linux_mips.go
(12.1 KB)
📄
zsysnum_linux_mips64.go
(10.93 KB)
📄
zsysnum_linux_mips64le.go
(10.93 KB)
📄
zsysnum_linux_mipsle.go
(12.1 KB)
📄
zsysnum_linux_ppc64.go
(11.47 KB)
📄
zsysnum_linux_ppc64le.go
(11.49 KB)
📄
zsysnum_linux_riscv64.go
(8.88 KB)
📄
zsysnum_linux_s390x.go
(10.64 KB)
📄
zsysnum_netbsd_386.go
(25.69 KB)
📄
zsysnum_netbsd_amd64.go
(25.69 KB)
📄
zsysnum_netbsd_arm.go
(25.69 KB)
📄
zsysnum_netbsd_arm64.go
(25.69 KB)
📄
zsysnum_openbsd_386.go
(14.16 KB)
📄
zsysnum_openbsd_amd64.go
(14.16 KB)
📄
zsysnum_openbsd_arm.go
(14.46 KB)
📄
zsysnum_openbsd_arm64.go
(14.72 KB)
📄
zsysnum_openbsd_mips64.go
(14.93 KB)
📄
zsysnum_openbsd_ppc64.go
(15.83 KB)
📄
zsysnum_openbsd_riscv64.go
(15.67 KB)
📄
zsysnum_plan9.go
(1.03 KB)
📄
zsysnum_solaris_amd64.go
(293 B)
📄
ztypes_aix_ppc64.go
(4.17 KB)
📄
ztypes_darwin_amd64.go
(6.95 KB)
📄
ztypes_darwin_arm64.go
(6.95 KB)
📄
ztypes_dragonfly_amd64.go
(6.7 KB)
📄
ztypes_freebsd_386.go
(8 KB)
📄
ztypes_freebsd_amd64.go
(8.03 KB)
📄
ztypes_freebsd_arm.go
(8.03 KB)
📄
ztypes_freebsd_arm64.go
(8.03 KB)
📄
ztypes_freebsd_riscv64.go
(8.03 KB)
📄
ztypes_linux_386.go
(11.58 KB)
📄
ztypes_linux_amd64.go
(11.95 KB)
📄
ztypes_linux_arm.go
(11.47 KB)
📄
ztypes_linux_arm64.go
(10.16 KB)
📄
ztypes_linux_loong64.go
(10.77 KB)
📄
ztypes_linux_mips.go
(9.96 KB)
📄
ztypes_linux_mips64.go
(10.08 KB)
📄
ztypes_linux_mips64le.go
(10.08 KB)
📄
ztypes_linux_mipsle.go
(9.96 KB)
📄
ztypes_linux_ppc64.go
(10.25 KB)
📄
ztypes_linux_ppc64le.go
(10.38 KB)
📄
ztypes_linux_riscv64.go
(10.23 KB)
📄
ztypes_linux_s390x.go
(10.44 KB)
📄
ztypes_netbsd_386.go
(5.99 KB)
📄
ztypes_netbsd_amd64.go
(6.17 KB)
📄
ztypes_netbsd_arm.go
(6.13 KB)
📄
ztypes_netbsd_arm64.go
(6.17 KB)
📄
ztypes_openbsd_386.go
(6.73 KB)
📄
ztypes_openbsd_amd64.go
(6.89 KB)
📄
ztypes_openbsd_arm.go
(6.84 KB)
📄
ztypes_openbsd_arm64.go
(6.66 KB)
📄
ztypes_openbsd_mips64.go
(6.66 KB)
📄
ztypes_openbsd_ppc64.go
(6.69 KB)
📄
ztypes_openbsd_riscv64.go
(6.69 KB)
📄
ztypes_solaris_amd64.go
(5.57 KB)
Editing: exec_linux_test.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build linux package syscall_test import ( "bytes" "errors" "flag" "fmt" "internal/platform" "internal/syscall/unix" "internal/testenv" "io" "os" "os/exec" "os/user" "path" "path/filepath" "runtime" "strconv" "strings" "syscall" "testing" "time" "unsafe" ) // whoamiNEWUSER returns a command that runs "whoami" with CLONE_NEWUSER, // mapping uid and gid 0 to the actual uid and gid of the test. func whoamiNEWUSER(t *testing.T, uid, gid int, setgroups bool) *exec.Cmd { t.Helper() testenv.MustHaveExecPath(t, "whoami") cmd := testenv.Command(t, "whoami") cmd.SysProcAttr = &syscall.SysProcAttr{ Cloneflags: syscall.CLONE_NEWUSER, UidMappings: []syscall.SysProcIDMap{ {ContainerID: 0, HostID: uid, Size: 1}, }, GidMappings: []syscall.SysProcIDMap{ {ContainerID: 0, HostID: gid, Size: 1}, }, GidMappingsEnableSetgroups: setgroups, } return cmd } func TestCloneNEWUSERAndRemap(t *testing.T) { for _, setgroups := range []bool{false, true} { setgroups := setgroups t.Run(fmt.Sprintf("setgroups=%v", setgroups), func(t *testing.T) { uid := os.Getuid() gid := os.Getgid() cmd := whoamiNEWUSER(t, uid, gid, setgroups) out, err := cmd.CombinedOutput() t.Logf("%v: %v", cmd, err) if uid != 0 && setgroups { t.Logf("as non-root, expected permission error due to unprivileged gid_map") if !os.IsPermission(err) { if err == nil { t.Skipf("unexpected success: probably old kernel without security fix?") } if testenv.SyscallIsNotSupported(err) { t.Skipf("skipping: CLONE_NEWUSER appears to be unsupported") } t.Fatalf("got non-permission error") // Already logged above. } return } if err != nil { if testenv.SyscallIsNotSupported(err) { // May be inside a container that disallows CLONE_NEWUSER. t.Skipf("skipping: CLONE_NEWUSER appears to be unsupported") } t.Fatalf("unexpected command failure; output:\n%s", out) } sout := strings.TrimSpace(string(out)) want := "root" if sout != want { t.Fatalf("whoami = %q; want %q", out, want) } }) } } func TestEmptyCredGroupsDisableSetgroups(t *testing.T) { cmd := whoamiNEWUSER(t, os.Getuid(), os.Getgid(), false) cmd.SysProcAttr.Credential = &syscall.Credential{} if err := cmd.Run(); err != nil { if testenv.SyscallIsNotSupported(err) { t.Skipf("skipping: %v: %v", cmd, err) } t.Fatal(err) } } func TestUnshare(t *testing.T) { path := "/proc/net/dev" if _, err := os.Stat(path); err != nil { if os.IsNotExist(err) { t.Skip("kernel doesn't support proc filesystem") } if os.IsPermission(err) { t.Skip("unable to test proc filesystem due to permissions") } t.Fatal(err) } b, err := os.ReadFile(path) if err != nil { t.Fatal(err) } orig := strings.TrimSpace(string(b)) if strings.Contains(orig, "lo:") && strings.Count(orig, ":") == 1 { // This test expects there to be at least 1 more network interface // in addition to the local network interface, so that it can tell // that unshare worked. t.Skip("not enough network interfaces to test unshare with") } cmd := testenv.Command(t, "cat", path) cmd.SysProcAttr = &syscall.SysProcAttr{ Unshareflags: syscall.CLONE_NEWNET, } out, err := cmd.CombinedOutput() if err != nil { if testenv.SyscallIsNotSupported(err) { // CLONE_NEWNET does not appear to be supported. t.Skipf("skipping due to permission error: %v", err) } t.Fatalf("Cmd failed with err %v, output: %s", err, out) } // Check there is only the local network interface. sout := strings.TrimSpace(string(out)) if !strings.Contains(sout, "lo:") { t.Fatalf("Expected lo network interface to exist, got %s", sout) } origLines := strings.Split(orig, "\n") lines := strings.Split(sout, "\n") if len(lines) >= len(origLines) { t.Logf("%s before unshare:\n%s", path, orig) t.Logf("%s after unshare:\n%s", path, sout) t.Fatalf("Got %d lines of output, want < %d", len(lines), len(origLines)) } } func TestGroupCleanup(t *testing.T) { testenv.MustHaveExecPath(t, "id") cmd := testenv.Command(t, "id") cmd.SysProcAttr = &syscall.SysProcAttr{ Credential: &syscall.Credential{ Uid: 0, Gid: 0, }, } out, err := cmd.CombinedOutput() if err != nil { if testenv.SyscallIsNotSupported(err) { t.Skipf("skipping: %v: %v", cmd, err) } t.Fatalf("Cmd failed with err %v, output: %s", err, out) } strOut := strings.TrimSpace(string(out)) t.Logf("id: %s", strOut) expected := "uid=0(root) gid=0(root)" // Just check prefix because some distros reportedly output a // context parameter; see https://golang.org/issue/16224. // Alpine does not output groups; see https://golang.org/issue/19938. if !strings.HasPrefix(strOut, expected) { t.Errorf("expected prefix: %q", expected) } } func TestGroupCleanupUserNamespace(t *testing.T) { testenv.MustHaveExecPath(t, "id") cmd := testenv.Command(t, "id") uid, gid := os.Getuid(), os.Getgid() cmd.SysProcAttr = &syscall.SysProcAttr{ Cloneflags: syscall.CLONE_NEWUSER, Credential: &syscall.Credential{ Uid: uint32(uid), Gid: uint32(gid), }, UidMappings: []syscall.SysProcIDMap{ {ContainerID: 0, HostID: uid, Size: 1}, }, GidMappings: []syscall.SysProcIDMap{ {ContainerID: 0, HostID: gid, Size: 1}, }, } out, err := cmd.CombinedOutput() if err != nil { if testenv.SyscallIsNotSupported(err) { t.Skipf("skipping: %v: %v", cmd, err) } t.Fatalf("Cmd failed with err %v, output: %s", err, out) } strOut := strings.TrimSpace(string(out)) t.Logf("id: %s", strOut) // As in TestGroupCleanup, just check prefix. // The actual groups and contexts seem to vary from one distro to the next. expected := "uid=0(root) gid=0(root) groups=0(root)" if !strings.HasPrefix(strOut, expected) { t.Errorf("expected prefix: %q", expected) } } // Test for https://go.dev/issue/19661: unshare fails because systemd // has forced / to be shared func TestUnshareMountNameSpace(t *testing.T) { const mountNotSupported = "mount is not supported: " // Output prefix indicatating a test skip. if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { dir := flag.Args()[0] err := syscall.Mount("none", dir, "proc", 0, "") if testenv.SyscallIsNotSupported(err) { fmt.Print(mountNotSupported, err) } else if err != nil { fmt.Fprintf(os.Stderr, "unshare: mount %s: %v\n", dir, err) os.Exit(2) } os.Exit(0) } testenv.MustHaveExec(t) exe, err := os.Executable() if err != nil { t.Fatal(err) } d := t.TempDir() t.Cleanup(func() { // If the subprocess fails to unshare the parent directory, force-unmount it // so that the test can clean it up. if _, err := os.Stat(d); err == nil { syscall.Unmount(d, syscall.MNT_FORCE) } }) cmd := testenv.Command(t, exe, "-test.run=^TestUnshareMountNameSpace$", d) cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1") cmd.SysProcAttr = &syscall.SysProcAttr{Unshareflags: syscall.CLONE_NEWNS} out, err := cmd.CombinedOutput() if err != nil { if testenv.SyscallIsNotSupported(err) { t.Skipf("skipping: could not start process with CLONE_NEWNS: %v", err) } t.Fatalf("unshare failed: %v\n%s", err, out) } else if len(out) != 0 { if bytes.HasPrefix(out, []byte(mountNotSupported)) { t.Skipf("skipping: helper process reported %s", out) } t.Fatalf("unexpected output from helper process: %s", out) } // How do we tell if the namespace was really unshared? It turns out // to be simple: just try to remove the directory. If it's still mounted // on the rm will fail with EBUSY. if err := os.Remove(d); err != nil { t.Errorf("rmdir failed on %v: %v", d, err) } } // Test for Issue 20103: unshare fails when chroot is used func TestUnshareMountNameSpaceChroot(t *testing.T) { const mountNotSupported = "mount is not supported: " // Output prefix indicatating a test skip. if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { dir := flag.Args()[0] err := syscall.Mount("none", dir, "proc", 0, "") if testenv.SyscallIsNotSupported(err) { fmt.Print(mountNotSupported, err) } else if err != nil { fmt.Fprintf(os.Stderr, "unshare: mount %s: %v\n", dir, err) os.Exit(2) } os.Exit(0) } d := t.TempDir() // Since we are doing a chroot, we need the binary there, // and it must be statically linked. testenv.MustHaveGoBuild(t) if platform.MustLinkExternal(runtime.GOOS, runtime.GOARCH, false) { t.Skipf("skipping: can't build static binary because %s/%s requires external linking", runtime.GOOS, runtime.GOARCH) } x := filepath.Join(d, "syscall.test") t.Cleanup(func() { // If the subprocess fails to unshare the parent directory, force-unmount it // so that the test can clean it up. if _, err := os.Stat(d); err == nil { syscall.Unmount(d, syscall.MNT_FORCE) } }) cmd := testenv.Command(t, testenv.GoToolPath(t), "test", "-c", "-o", x, "syscall") cmd.Env = append(cmd.Environ(), "CGO_ENABLED=0") if o, err := cmd.CombinedOutput(); err != nil { t.Fatalf("%v: %v\n%s", cmd, err, o) } cmd = testenv.Command(t, "/syscall.test", "-test.run=^TestUnshareMountNameSpaceChroot$", "/") cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1") cmd.SysProcAttr = &syscall.SysProcAttr{Chroot: d, Unshareflags: syscall.CLONE_NEWNS} out, err := cmd.CombinedOutput() if err != nil { if testenv.SyscallIsNotSupported(err) { t.Skipf("skipping: could not start process with CLONE_NEWNS and Chroot %q: %v", d, err) } t.Fatalf("unshare failed: %v\n%s", err, out) } else if len(out) != 0 { if bytes.HasPrefix(out, []byte(mountNotSupported)) { t.Skipf("skipping: helper process reported %s", out) } t.Fatalf("unexpected output from helper process: %s", out) } // How do we tell if the namespace was really unshared? It turns out // to be simple: just try to remove the executable. If it's still mounted // on, the rm will fail. if err := os.Remove(x); err != nil { t.Errorf("rm failed on %v: %v", x, err) } if err := os.Remove(d); err != nil { t.Errorf("rmdir failed on %v: %v", d, err) } } // Test for Issue 29789: unshare fails when uid/gid mapping is specified func TestUnshareUidGidMapping(t *testing.T) { if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { defer os.Exit(0) if err := syscall.Chroot(os.TempDir()); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) } } if os.Getuid() == 0 { t.Skip("test exercises unprivileged user namespace, fails with privileges") } testenv.MustHaveExec(t) exe, err := os.Executable() if err != nil { t.Fatal(err) } cmd := testenv.Command(t, exe, "-test.run=^TestUnshareUidGidMapping$") cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1") cmd.SysProcAttr = &syscall.SysProcAttr{ Unshareflags: syscall.CLONE_NEWNS | syscall.CLONE_NEWUSER, GidMappingsEnableSetgroups: false, UidMappings: []syscall.SysProcIDMap{ { ContainerID: 0, HostID: syscall.Getuid(), Size: 1, }, }, GidMappings: []syscall.SysProcIDMap{ { ContainerID: 0, HostID: syscall.Getgid(), Size: 1, }, }, } out, err := cmd.CombinedOutput() if err != nil { if testenv.SyscallIsNotSupported(err) { t.Skipf("skipping: could not start process with CLONE_NEWNS and CLONE_NEWUSER: %v", err) } t.Fatalf("Cmd failed with err %v, output: %s", err, out) } } func prepareCgroupFD(t *testing.T) (int, string) { t.Helper() const O_PATH = 0x200000 // Same for all architectures, but for some reason not defined in syscall for 386||amd64. // Requires cgroup v2. const prefix = "/sys/fs/cgroup" selfCg, err := os.ReadFile("/proc/self/cgroup") if err != nil { if os.IsNotExist(err) || os.IsPermission(err) { t.Skip(err) } t.Fatal(err) } // Expect a single line like this: // 0::/user.slice/user-1000.slice/user@1000.service/app.slice/vte-spawn-891992a2-efbb-4f28-aedb-b24f9e706770.scope // Otherwise it's either cgroup v1 or a hybrid hierarchy. if bytes.Count(selfCg, []byte("\n")) > 1 { t.Skip("cgroup v2 not available") } cg := bytes.TrimPrefix(selfCg, []byte("0::")) if len(cg) == len(selfCg) { // No prefix found. t.Skipf("cgroup v2 not available (/proc/self/cgroup contents: %q)", selfCg) } // Need an ability to create a sub-cgroup. subCgroup, err := os.MkdirTemp(prefix+string(bytes.TrimSpace(cg)), "subcg-") if err != nil { // ErrPermission or EROFS (#57262) when running in an unprivileged container. // ErrNotExist when cgroupfs is not mounted in chroot/schroot. if os.IsNotExist(err) || testenv.SyscallIsNotSupported(err) { t.Skipf("skipping: %v", err) } t.Fatal(err) } t.Cleanup(func() { syscall.Rmdir(subCgroup) }) cgroupFD, err := syscall.Open(subCgroup, O_PATH, 0) if err != nil { t.Fatal(&os.PathError{Op: "open", Path: subCgroup, Err: err}) } t.Cleanup(func() { syscall.Close(cgroupFD) }) return cgroupFD, "/" + path.Base(subCgroup) } func TestUseCgroupFD(t *testing.T) { testenv.MustHaveExec(t) if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { // Read and print own cgroup path. selfCg, err := os.ReadFile("/proc/self/cgroup") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) } fmt.Print(string(selfCg)) os.Exit(0) } exe, err := os.Executable() if err != nil { t.Fatal(err) } fd, suffix := prepareCgroupFD(t) cmd := testenv.Command(t, exe, "-test.run=^TestUseCgroupFD$") cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1") cmd.SysProcAttr = &syscall.SysProcAttr{ UseCgroupFD: true, CgroupFD: fd, } out, err := cmd.CombinedOutput() if err != nil { if testenv.SyscallIsNotSupported(err) && !errors.Is(err, syscall.EINVAL) { // Can be one of: // - clone3 not supported (old kernel); // - clone3 not allowed (by e.g. seccomp); // - lack of CAP_SYS_ADMIN. t.Skipf("clone3 with CLONE_INTO_CGROUP not available: %v", err) } t.Fatalf("Cmd failed with err %v, output: %s", err, out) } // NB: this wouldn't work with cgroupns. if !bytes.HasSuffix(bytes.TrimSpace(out), []byte(suffix)) { t.Fatalf("got: %q, want: a line that ends with %q", out, suffix) } } func TestCloneTimeNamespace(t *testing.T) { testenv.MustHaveExec(t) if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { timens, err := os.Readlink("/proc/self/ns/time") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) } fmt.Print(string(timens)) os.Exit(0) } exe, err := os.Executable() if err != nil { t.Fatal(err) } cmd := testenv.Command(t, exe, "-test.run=^TestCloneTimeNamespace$") cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1") cmd.SysProcAttr = &syscall.SysProcAttr{ Cloneflags: syscall.CLONE_NEWTIME, } out, err := cmd.CombinedOutput() if err != nil { if testenv.SyscallIsNotSupported(err) { // CLONE_NEWTIME does not appear to be supported. t.Skipf("skipping, CLONE_NEWTIME not supported: %v", err) } t.Fatalf("Cmd failed with err %v, output: %s", err, out) } // Inode number of the time namespaces should be different. // Based on https://man7.org/linux/man-pages/man7/time_namespaces.7.html#EXAMPLES timens, err := os.Readlink("/proc/self/ns/time") if err != nil { t.Fatal(err) } parentTimeNS := timens childTimeNS := string(out) if childTimeNS == parentTimeNS { t.Fatalf("expected child time namespace to be different from parent time namespace: %s", parentTimeNS) } } func testPidFD(t *testing.T, userns bool) error { testenv.MustHaveExec(t) if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { // Child: wait for a signal. time.Sleep(time.Hour) } exe, err := os.Executable() if err != nil { t.Fatal(err) } var pidfd int cmd := testenv.Command(t, exe, "-test.run=^TestPidFD$") cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1") cmd.SysProcAttr = &syscall.SysProcAttr{ PidFD: &pidfd, } if userns { cmd.SysProcAttr.Cloneflags = syscall.CLONE_NEWUSER } if err := cmd.Start(); err != nil { return err } defer func() { cmd.Process.Kill() cmd.Wait() }() t.Log("got pidfd:", pidfd) // If pidfd is not supported by the kernel, -1 is returned. if pidfd == -1 { t.Skip("pidfd not supported") } defer syscall.Close(pidfd) // Use pidfd to send a signal to the child. sig := syscall.SIGINT if err := unix.PidFDSendSignal(uintptr(pidfd), sig); err != nil { if err != syscall.EINVAL && testenv.SyscallIsNotSupported(err) { t.Skip("pidfd_send_signal syscall not supported:", err) } t.Fatal("pidfd_send_signal syscall failed:", err) } // Check if the child received our signal. err = cmd.Wait() if cmd.ProcessState == nil || cmd.ProcessState.Sys().(syscall.WaitStatus).Signal() != sig { t.Fatal("unexpected child error:", err) } return nil } func TestPidFD(t *testing.T) { if err := testPidFD(t, false); err != nil { t.Fatal("can't start a process:", err) } } func TestPidFDWithUserNS(t *testing.T) { if err := testPidFD(t, true); err != nil { if testenv.SyscallIsNotSupported(err) { t.Skip("userns not supported:", err) } t.Fatal("can't start a process:", err) } } func TestPidFDClone3(t *testing.T) { *syscall.ForceClone3 = true defer func() { *syscall.ForceClone3 = false }() if err := testPidFD(t, false); err != nil { if testenv.SyscallIsNotSupported(err) { t.Skip("clone3 not supported:", err) } t.Fatal("can't start a process:", err) } } type capHeader struct { version uint32 pid int32 } type capData struct { effective uint32 permitted uint32 inheritable uint32 } const CAP_SYS_TIME = 25 const CAP_SYSLOG = 34 type caps struct { hdr capHeader data [2]capData } func getCaps() (caps, error) { var c caps // Get capability version if _, _, errno := syscall.Syscall(syscall.SYS_CAPGET, uintptr(unsafe.Pointer(&c.hdr)), uintptr(unsafe.Pointer(nil)), 0); errno != 0 { return c, fmt.Errorf("SYS_CAPGET: %v", errno) } // Get current capabilities if _, _, errno := syscall.Syscall(syscall.SYS_CAPGET, uintptr(unsafe.Pointer(&c.hdr)), uintptr(unsafe.Pointer(&c.data[0])), 0); errno != 0 { return c, fmt.Errorf("SYS_CAPGET: %v", errno) } return c, nil } func TestAmbientCaps(t *testing.T) { testAmbientCaps(t, false) } func TestAmbientCapsUserns(t *testing.T) { testAmbientCaps(t, true) } func testAmbientCaps(t *testing.T, userns bool) { if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { caps, err := getCaps() if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) } if caps.data[0].effective&(1<<uint(CAP_SYS_TIME)) == 0 { fmt.Fprintln(os.Stderr, "CAP_SYS_TIME unexpectedly not in the effective capability mask") os.Exit(2) } if caps.data[1].effective&(1<<uint(CAP_SYSLOG&31)) == 0 { fmt.Fprintln(os.Stderr, "CAP_SYSLOG unexpectedly not in the effective capability mask") os.Exit(2) } os.Exit(0) } // skip on android, due to lack of lookup support if runtime.GOOS == "android" { t.Skip("skipping test on android; see Issue 27327") } u, err := user.Lookup("nobody") if err != nil { t.Fatal(err) } uid, err := strconv.ParseInt(u.Uid, 0, 32) if err != nil { t.Fatal(err) } gid, err := strconv.ParseInt(u.Gid, 0, 32) if err != nil { t.Fatal(err) } // Copy the test binary to a temporary location which is readable by nobody. f, err := os.CreateTemp("", "gotest") if err != nil { t.Fatal(err) } t.Cleanup(func() { f.Close() os.Remove(f.Name()) }) testenv.MustHaveExec(t) exe, err := os.Executable() if err != nil { t.Fatal(err) } e, err := os.Open(exe) if err != nil { t.Fatal(err) } defer e.Close() if _, err := io.Copy(f, e); err != nil { t.Fatal(err) } if err := f.Chmod(0755); err != nil { t.Fatal(err) } if err := f.Close(); err != nil { t.Fatal(err) } cmd := testenv.Command(t, f.Name(), "-test.run=^"+t.Name()+"$") cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.SysProcAttr = &syscall.SysProcAttr{ Credential: &syscall.Credential{ Uid: uint32(uid), Gid: uint32(gid), }, AmbientCaps: []uintptr{CAP_SYS_TIME, CAP_SYSLOG}, } if userns { cmd.SysProcAttr.Cloneflags = syscall.CLONE_NEWUSER const nobody = 65534 uid := os.Getuid() gid := os.Getgid() cmd.SysProcAttr.UidMappings = []syscall.SysProcIDMap{{ ContainerID: int(nobody), HostID: uid, Size: int(1), }} cmd.SysProcAttr.GidMappings = []syscall.SysProcIDMap{{ ContainerID: int(nobody), HostID: gid, Size: int(1), }} // Set credentials to run as user and group nobody. cmd.SysProcAttr.Credential = &syscall.Credential{ Uid: nobody, Gid: nobody, } } if err := cmd.Run(); err != nil { if testenv.SyscallIsNotSupported(err) { t.Skipf("skipping: %v: %v", cmd, err) } t.Fatal(err.Error()) } }
Upload File
Create Folder