aboutsummaryrefslogtreecommitdiffhomepage
path: root/sandbox/init.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-26 06:28:32 +0900
committerOphestra <cat@gensokyo.uk>2025-03-26 06:32:08 +0900
commit52fcc48ac141147324c3baac0e87ea49e8c2ca09 (patch)
treea3b2cc75d7d7266427580258cfdd11dc307cb92f /sandbox/init.go
parent8b69bcd2154fdc7903aceca662e9694588c982f2 (diff)
sandbox/init: drop capabilities
During development the syscall filter caused me to make an incorrect assumption about SysProcAttr. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'sandbox/init.go')
-rw-r--r--sandbox/init.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/sandbox/init.go b/sandbox/init.go
index 11167679..437eb7aa 100644
--- a/sandbox/init.go
+++ b/sandbox/init.go
@@ -108,6 +108,9 @@ func Init(prepare func(prefix string), setVerbose func(verbose bool)) {
}
}
+ // cache sysctl before pivot_root
+ LastCap()
+
/*
set up mount points from intermediate root
*/
@@ -217,15 +220,21 @@ func Init(prepare func(prefix string), setVerbose func(verbose bool)) {
load seccomp filter
*/
- if _, _, err := syscall.Syscall(PR_SET_NO_NEW_PRIVS, 1, 0, 0); err != 0 {
- log.Fatalf("prctl(PR_SET_NO_NEW_PRIVS): %v", err)
+ if _, _, errno := syscall.Syscall(PR_SET_NO_NEW_PRIVS, 1, 0, 0); errno != 0 {
+ log.Fatalf("prctl(PR_SET_NO_NEW_PRIVS): %v", errno)
+ }
+ if _, _, errno := syscall.Syscall(syscall.SYS_PRCTL, PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0); errno != 0 {
+ log.Fatalf("cannot clear the ambient capability set: %v", errno)
+ }
+ for i := uintptr(0); i <= LastCap(); i++ {
+ if _, _, errno := syscall.Syscall(syscall.SYS_PRCTL, syscall.PR_CAPBSET_DROP, i, 0); errno != 0 {
+ log.Fatalf("cannot drop capability: %v", errno)
+ }
}
if err := seccomp.Load(params.Flags.seccomp(params.Seccomp)); err != nil {
log.Fatalf("cannot load syscall filter: %v", err)
}
- /* at this point CAP_SYS_ADMIN can be dropped, however it is kept for now as it does not increase attack surface */
-
/*
pass through extra files
*/