mirror of
https://github.com/criyle/go-sandbox.git
synced 2025-09-26 23:19:11 +08:00
Compare commits
5 Commits
fa6ddd2119
...
8e64bc5e5c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8e64bc5e5c | ||
![]() |
63db3b54e6 | ||
![]() |
369229e0d5 | ||
![]() |
d58b2485a2 | ||
![]() |
6407c89d90 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -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
7
Dockerfile
Normal 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
|
@ -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",
|
||||
|
@ -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
10
test_c/Makefile
Normal 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
|
6
test_c/helloworld/main.cpp
Normal file
6
test_c/helloworld/main.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include<iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello, world" << std::endl;
|
||||
return 0;
|
||||
}
|
3
test_c/nonzeroexit/main.cpp
Normal file
3
test_c/nonzeroexit/main.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
int main() {
|
||||
return 100;
|
||||
}
|
Loading…
Reference in New Issue
Block a user