diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-07-02 02:30:35 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-07-02 02:30:35 +0900 |
| commit | a6887f7253ae822357f0d4d019675acc8c3e0b4d (patch) | |
| tree | efe0938b82a3efbe4f1cdde4707740085d88ae26 /sandbox/mount.go | |
| parent | 69bd581af78909ce924b810da67979b57c5b5747 (diff) | |
sandbox/seccomp: import dot for syscall
This significantly increases readability in some places.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'sandbox/mount.go')
| -rw-r--r-- | sandbox/mount.go | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/sandbox/mount.go b/sandbox/mount.go index 73dd14aa..4dc7c0e8 100644 --- a/sandbox/mount.go +++ b/sandbox/mount.go @@ -5,7 +5,7 @@ import ( "fmt" "os" "path/filepath" - "syscall" + . "syscall" "git.gensokyo.uk/security/hakurei/sandbox/vfs" ) @@ -17,8 +17,7 @@ func (p *procPaths) bindMount(source, target string, flags uintptr, eq bool) err msg.Verbosef("resolved %q on %q flags %#x", source, target, flags) } - if err := syscall.Mount(source, target, "", - syscall.MS_SILENT|syscall.MS_BIND|flags&syscall.MS_REC, ""); err != nil { + if err := Mount(source, target, "", MS_SILENT|MS_BIND|flags&MS_REC, ""); err != nil { return wrapErrSuffix(err, fmt.Sprintf("cannot mount %q on %q:", source, target)) } @@ -38,7 +37,7 @@ func (p *procPaths) bindMount(source, target string, flags uintptr, eq bool) err { var destFd int if err := IgnoringEINTR(func() (err error) { - destFd, err = syscall.Open(targetFinal, O_PATH|syscall.O_CLOEXEC, 0) + destFd, err = Open(targetFinal, O_PATH|O_CLOEXEC, 0) return }); err != nil { return wrapErrSuffix(err, @@ -46,7 +45,7 @@ func (p *procPaths) bindMount(source, target string, flags uintptr, eq bool) err } if v, err := os.Readlink(p.fd(destFd)); err != nil { return wrapErrSelf(err) - } else if err = syscall.Close(destFd); err != nil { + } else if err = Close(destFd); err != nil { return wrapErrSuffix(err, fmt.Sprintf("cannot close %q:", targetFinal)) } else { @@ -54,11 +53,11 @@ func (p *procPaths) bindMount(source, target string, flags uintptr, eq bool) err } } - mf := syscall.MS_NOSUID | flags&syscall.MS_NODEV | flags&syscall.MS_RDONLY + mf := MS_NOSUID | flags&MS_NODEV | flags&MS_RDONLY return hostProc.mountinfo(func(d *vfs.MountInfoDecoder) error { n, err := d.Unfold(targetKFinal) if err != nil { - if errors.Is(err, syscall.ESTALE) { + if errors.Is(err, ESTALE) { return msg.WrapErr(err, fmt.Sprintf("mount point %q never appeared in mountinfo", targetKFinal)) } @@ -69,13 +68,13 @@ func (p *procPaths) bindMount(source, target string, flags uintptr, eq bool) err if err = remountWithFlags(n, mf); err != nil { return err } - if flags&syscall.MS_REC == 0 { + if flags&MS_REC == 0 { return nil } for cur := range n.Collective() { err = remountWithFlags(cur, mf) - if err != nil && !errors.Is(err, syscall.EACCES) { + if err != nil && !errors.Is(err, EACCES) { return err } } @@ -91,9 +90,8 @@ func remountWithFlags(n *vfs.MountInfoNode, mf uintptr) error { } if kf&mf != mf { - return wrapErrSuffix(syscall.Mount("none", n.Clean, "", - syscall.MS_SILENT|syscall.MS_BIND|syscall.MS_REMOUNT|kf|mf, - ""), + return wrapErrSuffix( + Mount("none", n.Clean, "", MS_SILENT|MS_BIND|MS_REMOUNT|kf|mf, ""), fmt.Sprintf("cannot remount %q:", n.Clean)) } return nil @@ -108,8 +106,8 @@ func mountTmpfs(fsname, name string, size int, perm os.FileMode) error { if size > 0 { opt += fmt.Sprintf(",size=%d", size) } - return wrapErrSuffix(syscall.Mount(fsname, target, "tmpfs", - syscall.MS_NOSUID|syscall.MS_NODEV, opt), + return wrapErrSuffix( + Mount(fsname, target, "tmpfs", MS_NOSUID|MS_NODEV, opt), fmt.Sprintf("cannot mount tmpfs on %q:", name)) } |
