Skip to content

Commit a380fae

Browse files
committed
libcontainer: use Prctl() from x/sys/unix
Use unix.Prctl() instead of manually reimplementing it using unix.RawSyscall. Also use unix.SECCOMP_MODE_FILTER instead of locally defining it. Signed-off-by: Tobias Klauser <[email protected]>
1 parent 05ea5e4 commit a380fae

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

libcontainer/seccomp/seccomp_linux.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ var (
2020
actKill = libseccomp.ActKill
2121
actTrace = libseccomp.ActTrace.SetReturnCode(int16(unix.EPERM))
2222
actErrno = libseccomp.ActErrno.SetReturnCode(int16(unix.EPERM))
23-
24-
// SeccompModeFilter refers to the syscall argument SECCOMP_MODE_FILTER.
25-
SeccompModeFilter = uintptr(2)
2623
)
2724

2825
// Filters given syscalls in a container, preventing them from being used
@@ -85,9 +82,9 @@ func IsEnabled() bool {
8582
s, err := parseStatusFile("/proc/self/status")
8683
if err != nil {
8784
// Check if Seccomp is supported, via CONFIG_SECCOMP.
88-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_GET_SECCOMP, 0, 0); err != unix.EINVAL {
85+
if err := unix.Prctl(unix.PR_GET_SECCOMP, 0, 0, 0, 0); err != unix.EINVAL {
8986
// Make sure the kernel has CONFIG_SECCOMP_FILTER.
90-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_SECCOMP, SeccompModeFilter, 0); err != unix.EINVAL {
87+
if err := unix.Prctl(unix.PR_SET_SECCOMP, unix.SECCOMP_MODE_FILTER, 0, 0, 0); err != unix.EINVAL {
9188
return true
9289
}
9390
}

libcontainer/system/linux.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,30 @@ func Prlimit(pid, resource int, limit unix.Rlimit) error {
6464
}
6565

6666
func SetParentDeathSignal(sig uintptr) error {
67-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_PDEATHSIG, sig, 0); err != 0 {
67+
if err := unix.Prctl(unix.PR_SET_PDEATHSIG, sig, 0, 0, 0); err != nil {
6868
return err
6969
}
7070
return nil
7171
}
7272

7373
func GetParentDeathSignal() (ParentDeathSignal, error) {
7474
var sig int
75-
_, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_GET_PDEATHSIG, uintptr(unsafe.Pointer(&sig)), 0)
76-
if err != 0 {
75+
if err := unix.Prctl(unix.PR_GET_PDEATHSIG, uintptr(unsafe.Pointer(&sig)), 0, 0, 0); err != nil {
7776
return -1, err
7877
}
7978
return ParentDeathSignal(sig), nil
8079
}
8180

8281
func SetKeepCaps() error {
83-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_KEEPCAPS, 1, 0); err != 0 {
82+
if err := unix.Prctl(unix.PR_SET_KEEPCAPS, 1, 0, 0, 0); err != nil {
8483
return err
8584
}
8685

8786
return nil
8887
}
8988

9089
func ClearKeepCaps() error {
91-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_KEEPCAPS, 0, 0); err != 0 {
90+
if err := unix.Prctl(unix.PR_SET_KEEPCAPS, 0, 0, 0, 0); err != nil {
9291
return err
9392
}
9493

0 commit comments

Comments
 (0)