Compare commits

...

5 Commits

Author SHA1 Message Date
Gorgeous-Patrick
8e64bc5e5c
Merge 369229e0d5 into 63db3b54e6 2025-08-24 11:37:06 +00:00
criyle
63db3b54e6 mount: ensure bind mount preserve the mount flag from source 2025-08-23 20:21:02 +00:00
Patrick Li
369229e0d5 fix: allow more essential syscalls 2024-12-05 18:36:33 -05:00
Gorgeous-Patrick
d58b2485a2 test: makefile for test 2024-12-05 14:56:57 -05:00
Gorgeous-Patrick
6407c89d90 DOCKER NOT WORKING 2024-12-05 14:47:05 -05:00
7 changed files with 53 additions and 64 deletions

3
.gitignore vendored
View File

@ -2,7 +2,6 @@
.DS_Store
# Test Env
test*/
env*.sh
# Test Files
@ -10,3 +9,5 @@ env*.sh
/test
.vscode
runprog
*.test

7
Dockerfile Normal file
View File

@ -0,0 +1,7 @@
FROM golang
COPY . /app
WORKDIR /app/cmd/runprog
RUN apt update && apt install -y gcc libstdc++6 libseccomp-dev
RUN go build

View File

@ -16,6 +16,10 @@ var (
"/dev/urandom",
"/proc/meminfo",
"/etc/localtime",
"/usr/lib/libstdc++.so.6",
"/usr/lib/libc.so.6",
"/usr/lib/libm.so.6",
"/usr/lib/libgcc_s.so.1",
}
// default write permission files
@ -71,6 +75,17 @@ var (
"clock_gettime",
"restart_syscall",
"futex",
"gettid",
"getpid",
"prlimit64",
"getrandom",
"set_tid_address",
"set_robust_list",
"rseq",
"newfstatat",
}
// default syscalls to trace
@ -98,71 +113,11 @@ var (
// config for different type of program
// workpath and arg0 have additional read / stat permission
runptraceConfig = map[string]ProgramConfig{
"python2.7": {
Syscall: SyscallConfig{
ExtraAllow: []string{
"futex", "getdents", "getdents64", "prlimit64", "getpid", "sysinfo",
},
ExtraCount: map[string]int{
"set_tid_address": 1,
"set_robust_list": 1,
},
},
FileAccess: FileAccessConfig{
ExtraRead: []string{
"/usr/bin/python2.7",
"/usr/lib/python2.7/",
"/usr/bin/lib/python2.7/",
"/usr/local/lib/python2.7/",
"/usr/lib/pymodules/python2.7/",
"/usr/bin/Modules/",
"/usr/bin/pybuilddir.txt",
"/usr/lib/locale/",
"./answer.code",
},
ExtraStat: []string{
"/usr", "/usr/bin",
},
},
RunCommand: []string{"/usr/bin/python2.7", "-E", "-s", "-B"},
},
"python3": {
Syscall: SyscallConfig{
ExtraAllow: []string{
"futex", "getdents", "getdents64", "prlimit64", "getpid", "sysinfo", "getrandom",
},
ExtraCount: map[string]int{
"set_tid_address": 1,
"set_robust_list": 1,
},
},
FileAccess: FileAccessConfig{
ExtraRead: []string{
"/usr/bin/python3",
"/usr/lib/python3/",
"/usr/bin/python3.6",
"/usr/lib/python3.6/",
"/usr/bin/lib/python3.6/",
"/usr/local/lib/python3.6/",
"/usr/bin/pyvenv.cfg",
"/usr/pyvenv.cfg",
"/usr/bin/Modules",
"/usr/bin/pybuilddir.txt",
"/usr/lib/dist-python",
"/usr/lib/locale/",
"./answer.code",
},
ExtraStat: []string{
"/usr", "/usr/bin", "/usr/lib", "/usr/lib/python36.zip",
},
},
RunCommand: []string{"/usr/bin/python3", "-I", "-B"},
},
"compiler": {
Syscall: SyscallConfig{
ExtraAllow: []string{
"gettid", "set_tid_address", "set_robust_list", "futex",
"getpid", "vfork", "fork", "clone", "execve", "wait4",
"set_tid_address", "set_robust_list", "futex",
"vfork", "fork", "clone", "execve", "wait4",
"clock_gettime", "clock_getres",
"setrlimit", "pipe",
"getdents64", "getdents",

View File

@ -17,8 +17,15 @@ func (m *Mount) Mount() error {
}
// Read-only bind mount need to be remounted
const bindRo = syscall.MS_BIND | syscall.MS_RDONLY
const mask = syscall.MS_NOSUID | syscall.MS_NODEV | syscall.MS_NOEXEC | syscall.MS_NOATIME | syscall.MS_NODIRATIME | syscall.MS_RELATIME
if m.Flags&bindRo == bindRo {
if err := syscall.Mount("", m.Target, m.FsType, m.Flags|syscall.MS_REMOUNT, m.Data); err != nil {
// Ensure the flag retains for bind mount
var s syscall.Statfs_t
if err := syscall.Statfs(m.Source, &s); err != nil {
return fmt.Errorf("statfs: %w", err)
}
flag := m.Flags | syscall.MS_REMOUNT | uintptr(s.Flags&mask)
if err := syscall.Mount("", m.Target, m.FsType, flag, m.Data); err != nil {
return fmt.Errorf("remount: %w", err)
}
}

10
test_c/Makefile Normal file
View File

@ -0,0 +1,10 @@
all: helloworld/main.test nonzeroexit/main.test
helloworld/main.test: helloworld/main.cpp
g++ helloworld/main.cpp -o helloworld/main.test -DNDEBUG -O3
nonzeroexit/main.test: nonzeroexit/main.cpp
g++ nonzeroexit/main.cpp -o nonzeroexit/main.test -DNDEBUG -O3
clean:
rm -rf helloworld/*.test nonzeroexit/*.test

View File

@ -0,0 +1,6 @@
#include<iostream>
int main() {
std::cout << "Hello, world" << std::endl;
return 0;
}

View File

@ -0,0 +1,3 @@
int main() {
return 100;
}