From 0ab33401337db6a98a72dc170d652154654eb43f Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 9 Jul 2026 11:04:27 +0800 Subject: [PATCH] fix(code-runner): allow exec on /tmp tmpfs for compiled languages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docker tmpfs 挂载默认带 noexec,编译型语言(go/rust)把编译产物 落在 /tmp 后再 exec 会报 permission denied: - rust: /tmp/main (run-rust.sh 的 rustc 输出) - go: /tmp/go-build*/b001/exe/main (GOTMPDIR=/tmp 的链接器输出) 解释型语言(python/node)执行根文件系统里的解释器,不在 tmpfs 上,不受影响。 给 /tmp tmpfs 显式加 exec 选项。这是容器执行的固有需求——只要 沙箱支持任何编译型语言,/tmp 就必须可执行。安全模型由只读根文件系统 + cap_drop=ALL + no-new-privileges + pids/memory/cpu 限制兜底,/tmp 可执行 不引入额外攻击面(容器内本就允许执行自身进程)。 --- src/infra/docker.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/infra/docker.rs b/src/infra/docker.rs index 3e5a33b..eda59bb 100644 --- a/src/infra/docker.rs +++ b/src/infra/docker.rs @@ -17,7 +17,10 @@ pub static DOCKER_CLIENT: LazyLock = LazyLock::new(|| { pub fn build_host_config(limits: &ResourceLimits) -> HostConfig { let mut tmpfs = HashMap::new(); tmpfs.insert("/code".to_string(), "size=16m,uid=1000,gid=1000".to_string()); - tmpfs.insert("/tmp".to_string(), "size=64m,mode=1777".to_string()); + // /tmp 必须 exec:编译型语言(go/rust)把编译产物落在 /tmp 后再 exec, + // Docker tmpfs 默认 noexec 会让执行二进制时报 EACCES(permission denied)。 + // 解释型语言(python/node)执行根文件系统的解释器,不受影响。 + tmpfs.insert("/tmp".to_string(), "size=64m,mode=1777,exec".to_string()); tmpfs.insert("/run".to_string(), "size=16m,mode=1777".to_string()); let memory = (limits.memory_mb * 1024 * 1024) as i64;