Skip to content

feat(runner): hybrid seccomp backend with structured syscall policy - #4

Merged
freefcw merged 7 commits into
masterfrom
feat/seccomp-hybrid
Jul 5, 2026
Merged

freefcw merged 7 commits into
masterfrom
feat/seccomp-hybrid

Conversation

@freefcw

@freefcw freefcw commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

为 runner 引入 seccomp-BPF hybrid syscall 后端,并叠加 Phase 2 结构化 SyscallPolicy 兼容层,逐步把 syscall 过滤下沉到内核态,同时保留 ptrace 对启动边界、生命周期和按名单审计的职责。

Phase 1:hybrid seccomp 后端(054a6b5、f8a342d)

  • 新增 runner/seccomp_linux.go:在 Linux child 完成沙箱与 ptrace(TRACEME) 后、execve 前安装 seccomp-BPF 过滤器;runtime allowlist 走 SECCOMP_RET_ALLOW,OneTimeCalls 走 SECCOMP_RET_TRACE 交 ptrace 审批。
  • exec_linux.go 增加 hybrid child 启动阶段;process_linux.go 打开 PTRACE_O_TRACESECCOMP;tracer_linux.go 处理 PTRACE_EVENT_SECCOMP。
  • 新增 tests/clone-syscall-phase-hybrid 集成用例并接入 make testall。

Phase 2:结构化 SyscallPolicy + event-only resume(16bcbbf、8603ead、320d692、23d362b)

  • 新增 runner/syscall_policy.go:SyscallPolicyConfig{Allow,Deny,Trace,Audit} 作为兼容层,与 legacy AllowedCalls/AdditionCalls/OneTimeCalls 归一为 EffectiveSyscallPolicy,再编译成 ptrace 与 seccomp 各自消费的后端输入。
  • hybrid 改用 event-only resume(PTRACE_CONT),普通 ALLOW 调用不再产生 syscall enter/exit stop;Trace/Audit 通过 SECCOMP_RET_TRACE 路由到 ptrace 并输出 audit 日志。
  • ownership fail-loud:同一 syscall 不能同时属于 OneTimeCalls、runtime allowlist、Trace、Audit;Deny 只对 allowlist 做减法,不能与 OneTimeCalls/Trace/Audit 重叠。
  • hybrid 启动协议保留 write/close/exit/exit_group,禁止放入 Deny/Trace/Audit/OneTimeCalls。
  • seccomp filter 生成增加 BPF 指令上限校验。
  • 新增 tests/syscall-policy-deny-hybrid、tests/syscall-policy-trace-audit-hybrid 集成用例并接入 make testall。
  • 同步 docs/architecture.md、docs/runner/syscalls.md、docs/seccomp-bpf-migration.md。
  • .gitignore 修正 .workflows/→.workflow/ 并忽略 .pi-subagents/。

影响平台

  • Linux:hybrid 后端、seccomp-BPF、event-only resume、cgroup child 启动、新集成用例。
  • Darwin:仅补充 ContinueWithMode 等 panic 占位与跨平台构建,不参与 hybrid 运行。

安全行为变更

  • 新增 SyscallBackend: "hybrid" 路径,普通禁止 syscall 在内核态执行前被 KILL_PROCESS 拒绝,不再依赖 ptrace enter/exit 相位。
  • syscall ownership 收紧为 fail-loud:旧版本中 OneTimeCalls 与 AllowedCalls/AdditionCalls 重叠会退化为永久 allow,现改为配置加载阶段直接报错。
  • 未放宽任何允许的系统调用;hybrid 启动协议保留 syscall 显式禁止写入 Deny/Trace/Audit/OneTimeCalls。

Test plan

  • go build ./...
  • go vet ./runner/ ./sec/
  • go test ./runner/ ./sec/(含新增 syscall_policy / seccomp / tracer / process 单测)
  • Linux 远程:sudo -E env PATH="$PATH" make testall(含 23 个集成 case,REMOTE_TESTALL_WITH_PATH:0)
  • pre-commit hooks(golangci-lint v2、conventional commit、文本卫生、安全检查)全部通过

Summary by CodeRabbit

  • 新功能

    • 新增混合(hybrid)系统调用后端支持,运行时可按配置启用 seccomp 过滤与追踪。
    • 增加系统调用策略配置,支持允许、拒绝、追踪和审计规则。
    • 新增相关测试场景,覆盖混合后端、策略拒绝以及追踪/审计行为。
  • 文档

    • 更新架构、迁移与使用说明,补充 hybrid 模式和策略规则的说明。

freefcw added 6 commits July 5, 2026 10:18
Install a Linux seccomp-BPF allow/trace filter before execve when SyscallBackend is set to hybrid. Keep ptrace as the default backend and retain ptrace checks for bootstrap and migration coverage.
Introduce SyscallPolicyConfig (Allow/Deny/Trace/Audit) as a Phase 2
compatibility layer over the legacy AllowedCalls/AdditionCalls/OneTimeCalls.
The runner now normalizes both sources into an EffectiveSyscallPolicy, then
compiles it into backend inputs: ptrace consumes a callPolicySpec, seccomp
consumes final ALLOW/TRACE syscall lists.

Hybrid mode switches to event-only ptrace resume (PTRACE_CONT) so ordinary
seccomp ALLOW calls no longer produce syscall enter/exit stops; Trace/Audit
calls are routed through SECCOMP_RET_TRACE for ptrace handling and named
audit logging. Ownership is enforced fail-loud: a syscall cannot belong to
more than one of OneTimeCalls, runtime allowlist, Trace, or Audit, and Deny
only subtracts from the allowlist. Hybrid startup protocol reserves
write/close/exit/exit_group, which cannot be placed in Deny/Trace/Audit/
OneTimeCalls. Seccomp filter generation now rejects BPF instruction limit
overflow.
Add tests/syscall-policy-deny-hybrid covering Deny overriding an inherited
AdditionCalls allow, and tests/syscall-policy-trace-audit-hybrid covering
Trace and Audit end-to-end with seccomp audit log assertion. Wire both into
makefile testall and update tests/README.md.
Document the SyscallPolicy Allow/Deny/Trace/Audit compatibility layer,
event-only hybrid resume, ownership fail-loud semantics, startup protocol
reservations, and the two new hybrid integration cases.
@coderabbitai

coderabbitai Bot commented Jul 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@freefcw, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 238eaf68-f62c-47e5-b2a1-8f4aab99c0a1

📥 Commits

Reviewing files that changed from the base of the PR and between 320d692 and b6b6f91.

📒 Files selected for processing (1)
  • runner/exec_linux.go
📝 Walkthrough

Walkthrough

本次变更为 runner 引入 hybrid syscall 过滤后端:新增 SyscallPolicy(Allow/Deny/Trace/Audit)配置模型与归一化/编译逻辑,Linux 下新增 seccomp-BPF 过滤器生成与安装(seccomp_linux.go),ptrace 与 seccomp 事件协同处理及审计日志,并同步更新架构/迁移文档与新增三组 hybrid 集成测试。

Changes

Hybrid Syscall 过滤主线

Layer / File(s) Summary
SyscallPolicy 数据模型与配置校验
runner/syscall_policy.go, runner/syscall_policy_test.go, runner/config.go, runner/config_darwin.go, runner/config_linux.go, runner/config_linux_test.go, runner/config_test.go
新增 SyscallPolicyConfig/EffectiveSyscallPolicy 结构、归一化合并/所有权校验,TaskConfig 增加 SyscallBackend/SyscallPolicy 字段及平台相关校验,并配套单元测试。
seccomp-BPF 过滤器构建与安装
runner/seccomp_linux.go, runner/seccomp_linux_test.go, runner/sec.go, runner/process_linux_test.go
新增 prepareChildSeccompSpec/buildSeccompHybridFilter/installSeccompFilter 等函数生成并通过 prctl 安装 BPF 过滤器,CallPolicy 新增 auditCalls/ShouldAudit。
ptrace 恢复模式与 seccomp 事件对接
runner/process.go, runner/process_linux.go, runner/process_darwin.go, runner/process_linux_test.go, runner/exec_linux.go, runner/exec_linux_test.go
新增 traceResumeMode 枚举与 ContinueWithMode,SetPtraceOptions 支持 traceSeccomp 参数,exec_linux.go 新增混合模式下 ptrace 与 seccomp 安装的启动握手逻辑。
trace 主循环与 seccomp 事件处理/审计
runner/exec.go, runner/tracer_linux.go, runner/tracer_darwin.go, runner/tracer.go, runner/tracer_linux_test.go, runner/tracer_regs_linux_*_test.go
exec.go 基于编译后的策略选择恢复模式并处理 ptraceEventSeccomp 事件,tracer_linux.go 新增 checkSeccompTrace 与 auditSyscall 审计日志。
架构与迁移文档更新
docs/architecture.md, docs/runner/syscalls.md, docs/seccomp-bpf-migration.md, docs/README.md, runner/README.md, tests/README.md
更新文档描述 hybrid 后端行为、SyscallPolicy 语义、测试用例数量与导航链接。
Hybrid 集成测试用例与构建集成
tests/clone-syscall-phase-hybrid/*, tests/syscall-policy-deny-hybrid/*, tests/syscall-policy-trace-audit-hybrid/*, makefile, .gitignore
新增三组 hybrid 集成测试目录并接入 testall 目标,同时更新忽略规则。

Estimated code review effort: 4 (Complex) | ~75 minutes

Sequence Diagram(s)

sequenceDiagram
participant Parent
participant Child
participant TracerDetect
Child->>Child: PTRACE_TRACEME + stopForPtraceOptions
Parent->>Parent: waitForTraceeStop
Parent->>Child: SetPtraceOptions(traceSeccomp)
Parent->>Child: ContinueWithMode
Child->>Child: installSeccompFilter (prctl)
Child->>Child: execve
Parent->>Parent: verifyStartupSeccompEvent
loop 运行期
Child->>TracerDetect: seccomp/ptrace 事件 stop
TracerDetect->>TracerDetect: checkSeccompTrace / checkSyscall
TracerDetect->>TracerDetect: auditSyscall (若 ShouldAudit)
TracerDetect->>Child: ContinueWithMode
end
Loading

Poem

洞里跑着两只兔,一只 ptrace 一只 seccomp,
白名单编好又归一,BPF 指令排成行,
execve 一跳过安检,审计日志轻轻响,
混合模式护家园,测试三窝也安康~ 🐇🕳️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:为 runner 引入 hybrid seccomp 后端并添加结构化 syscall policy。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/seccomp-hybrid

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The spec is already consulted by the caller via shouldSyncSeccompTracee;
the function body only runs the ptrace sync flow and never reads spec.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (6)
runner/seccomp_linux.go (1)

190-196: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

用标准库排序替换手写插入排序。

sortUint32 手动实现了插入排序,建议改用标准库 sort.Slice(或 Go 1.21+ 的 slices.Sort),减少自造轮子、提升可读性。

♻️ 建议重构
-func sortUint32(values []uint32) {
-	for i := 1; i < len(values); i++ {
-		for j := i; j > 0 && values[j-1] > values[j]; j-- {
-			values[j-1], values[j] = values[j], values[j-1]
-		}
-	}
-}
+func sortUint32(values []uint32) {
+	sort.Slice(values, func(i, j int) bool { return values[i] < values[j] })
+}

需要在 import 中添加 "sort"(或使用 "slices" 包的 slices.Sort,需确认项目最低 Go 版本 ≥ 1.21)。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runner/seccomp_linux.go` around lines 190 - 196, The sortUint32 helper
currently uses a hand-written insertion sort; replace it with the standard
library sorter for clearer, less error-prone code. Update sortUint32 to use
sort.Slice (or slices.Sort if the project targets Go 1.21+), and add the
corresponding import in the same file while keeping the function’s behavior
unchanged.
tests/clone-syscall-phase-hybrid/makefile (1)

1-17: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

把这些命令型目标声明为 .PHONY。

default / compile / test / assert / clean 都不是文件产物,不加 .PHONY 时,一旦目录里出现同名文件,make 可能直接跳过测试或清理流程。

🔧 建议修正
+.PHONY: default compile test assert clean
 default: compile test assert clean
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/clone-syscall-phase-hybrid/makefile` around lines 1 - 17, Declare the
non-file targets in this Makefile as .PHONY so make never skips them when
same-named files exist. Update the rules for default, compile, test, assert, and
clean to be marked phony, keeping their current behavior in place while ensuring
the target names remain command-only entry points.

Source: Linters/SAST tools

runner/syscall_policy.go (1)

65-70: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

compileSyscallPolicy 未内联执行 hybrid 专属校验,存在隐式耦合风险。

compileSyscallPolicy 只调用了通用的 validateSyscallPolicy(),并未根据后端类型调用 validateHybridSyscallPolicy;该校验目前仅在 config.go 的 Validate() 中、且仅当 backend == syscallBackendHybrid 时才触发。当前风险被 LoadConfig() 内部调用 Validate() 的事实所缓解(config_linux_test.go 中的 TestValidateRejectsHybridDenyOfStartupProtocolCalls 证实了这一点),但 compileSyscallPolicy 作为策略编译的唯一入口,如果未来有调用方(或单测,如本文件 TestCompileSyscallPolicyProducesBackendInputs)在未经过 Validate() 的 TaskConfig 上直接调用它,hybrid 模式下 Deny/Trace/Audit 对保留调用(write/close/exit/exit_group)的"fail-loud"保证会被静默绕过——compile() 仍会无条件把这些调用塞入 SeccompAllowedCalls。建议让 compileSyscallPolicy 自身根据 tc.effectiveSyscallBackend() 决定是否执行 validateHybridSyscallPolicy,使其不依赖调用顺序即可保持不变量。

♻️ 建议的修复
 func (tc *TaskConfig) compileSyscallPolicy() (compiledSyscallPolicy, error) {
 	if err := tc.validateSyscallPolicy(); err != nil {
 		return compiledSyscallPolicy{}, err
 	}
+	if tc.effectiveSyscallBackend() == syscallBackendHybrid {
+		if err := validateHybridSyscallPolicy(tc.effectiveSyscallPolicy()); err != nil {
+			return compiledSyscallPolicy{}, err
+		}
+	}
 	return tc.effectiveSyscallPolicy().compile(), nil
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runner/syscall_policy.go` around lines 65 - 70, compileSyscallPolicy
currently only runs validateSyscallPolicy and can bypass hybrid-specific
protection when called on an unvalidated TaskConfig. Update compileSyscallPolicy
to check tc.effectiveSyscallBackend() and invoke validateHybridSyscallPolicy for
syscallBackendHybrid before calling effectiveSyscallPolicy().compile(), so the
hybrid deny/trace/audit invariants are enforced inside this entrypoint instead
of depending on Validate() being called first.
runner/config.go (1)

100-117: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

NoNewPrivs 检查顺序先于平台校验,非 Linux 场景下报错信息具有误导性。

当 backend == hybrid 且 NoNewPrivs == false 且运行在非 Linux 平台时(参考 config_darwin.go 的 validateSyscallBackendForPlatform),当前顺序会先返回 "syscallBackend hybrid requires NoNewPrivs",掩盖了真正的问题——hybrid 后端在该平台根本不受支持。建议先做平台校验,再做 NoNewPrivs 校验,避免误导用户"设置 NoNewPrivs 即可解决"。

🩹 建议的修复
-	if backend == syscallBackendHybrid && !tc.NoNewPrivs {
-		return errors.New("syscallBackend hybrid requires NoNewPrivs")
-	}
 	if err := validateSyscallBackendForPlatform(backend); err != nil {
 		return err
 	}
+	if backend == syscallBackendHybrid && !tc.NoNewPrivs {
+		return errors.New("syscallBackend hybrid requires NoNewPrivs")
+	}
 	if backend == syscallBackendHybrid {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runner/config.go` around lines 100 - 117, The validation order in config
validation is wrong: the NoNewPrivs check for syscallBackendHybrid runs before
platform support is verified, so on non-Linux platforms it returns a misleading
error. In the config validation path around effectiveSyscallBackend,
validateSyscallBackendForPlatform, and the hybrid backend branch, move the
platform-specific check ahead of the hybrid NoNewPrivs check so unsupported
platforms fail with the correct error first, then keep the NoNewPrivs
requirement for platforms where hybrid is valid.
runner/exec.go (1)

135-142: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

与 92-101 处的 SetPtraceOptions+ContinueWithMode 组合重复,可抽取 helper。

初次设置(Line 94-101)与子进程 attach 后重设(Line 135-142)的逻辑结构完全一致(仅日志文案不同),建议抽成一个小函数以减少重复、避免后续两处修改不同步。

♻️ 建议重构
+func (task *RunningTask) armPtrace(process *Process, traceSeccomp bool, resumeMode traceResumeMode, context string) bool {
+	if err := process.SetPtraceOptions(traceSeccomp); err != nil {
+		log.Infof("PtraceSetOptions(%s): err %v", context, err)
+		task.Result.RetCode = RUNTIME_ERROR
+		process.Kill()
+		task.parseRunningInfo()
+		return false
+	}
+	return process.ContinueWithMode(resumeMode, 0)
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runner/exec.go` around lines 135 - 142, The SetPtraceOptions +
ContinueWithMode sequence is duplicated in the initial setup and the
child-attach path. Extract the repeated logic in exec.go into a small helper
around process.SetPtraceOptions and process.ContinueWithMode, keeping the
caller-specific log message as an argument. Update both call sites to use the
helper so the behavior stays identical while avoiding divergence between the two
blocks.
runner/tracer_linux_test.go (1)

82-199: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

建议补充针对"纯 Trace"(非 Allow、非 OneTime)系统调用的 checkSeccompTrace 用例。

现有用例覆盖了 OneTimeCalls(TestCheckSeccompTraceRejectsConsumedExecveBeforeEnter、TestCheckSeccompTraceConsumesPolicyAtEventStop)以及 AllowedCalls + AuditCalls 组合(TestCheckSeccompTraceLogsAuditCall),但没有用例验证:系统调用仅存在于 Trace 列表(既不在 Allow 也不在 OneTime)时,checkSeccompTrace 是否仍返回 syscallCheckOK。结合上面在 tracer_linux.go 中提出的跨文件契约疑问,建议补充这一用例,以在单测层面锁定 Trace 语义的正确性。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runner/tracer_linux_test.go` around lines 82 - 199, Add a test for
“trace-only” syscall handling in checkSeccompTrace: the current TracerDetect
coverage verifies OneTimeCalls and AllowedCalls+AuditCalls, but not a syscall
that appears only in the Trace list. Extend the tracer_linux_test.go suite with
a case around TracerDetect.checkSeccompTrace and makeCallPolicy(callPolicySpec)
asserting that a trace-only syscall returns syscallCheckOK and does not get
consumed or rejected, using the existing RegisterTracee, setCallPolicy, and
ptraceGetRegs test pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@runner/process_linux.go`:
- Line 11: The syscallStopSignal declaration has a redundant type conversion:
syscall.SIGTRAP | 0x80 already yields a syscall.Signal, so remove the outer
syscall.Signal(...) cast to satisfy unconvert. Update the constant in
process_linux.go at syscallStopSignal and keep the expression as a plain bitwise
OR result.

In `@runner/seccomp_linux.go`:
- Around line 1-14: The import block in seccomp_linux.go is not
goimports-compliant and is causing the golangci-lint check to fail. Reformat the
imports in that file using goimports so the standard/library and third-party
groups are ordered correctly and any unused imports are removed, then verify the
package still builds cleanly.

In `@tests/syscall-policy-trace-audit-hybrid/makefile`:
- Around line 10-12: The assert target currently validates only the pass result
and the getppid audit log, so the getpid trace path in the hybrid seccomp flow
is not being checked. Update the assert rule to also verify a seccomp trace
output for getpid, using the existing runner.log checks alongside the current
grep assertions, so the trace branch in the syscall policy test is explicitly
exercised.

---

Nitpick comments:
In `@runner/config.go`:
- Around line 100-117: The validation order in config validation is wrong: the
NoNewPrivs check for syscallBackendHybrid runs before platform support is
verified, so on non-Linux platforms it returns a misleading error. In the config
validation path around effectiveSyscallBackend,
validateSyscallBackendForPlatform, and the hybrid backend branch, move the
platform-specific check ahead of the hybrid NoNewPrivs check so unsupported
platforms fail with the correct error first, then keep the NoNewPrivs
requirement for platforms where hybrid is valid.

In `@runner/exec.go`:
- Around line 135-142: The SetPtraceOptions + ContinueWithMode sequence is
duplicated in the initial setup and the child-attach path. Extract the repeated
logic in exec.go into a small helper around process.SetPtraceOptions and
process.ContinueWithMode, keeping the caller-specific log message as an
argument. Update both call sites to use the helper so the behavior stays
identical while avoiding divergence between the two blocks.

In `@runner/seccomp_linux.go`:
- Around line 190-196: The sortUint32 helper currently uses a hand-written
insertion sort; replace it with the standard library sorter for clearer, less
error-prone code. Update sortUint32 to use sort.Slice (or slices.Sort if the
project targets Go 1.21+), and add the corresponding import in the same file
while keeping the function’s behavior unchanged.

In `@runner/syscall_policy.go`:
- Around line 65-70: compileSyscallPolicy currently only runs
validateSyscallPolicy and can bypass hybrid-specific protection when called on
an unvalidated TaskConfig. Update compileSyscallPolicy to check
tc.effectiveSyscallBackend() and invoke validateHybridSyscallPolicy for
syscallBackendHybrid before calling effectiveSyscallPolicy().compile(), so the
hybrid deny/trace/audit invariants are enforced inside this entrypoint instead
of depending on Validate() being called first.

In `@runner/tracer_linux_test.go`:
- Around line 82-199: Add a test for “trace-only” syscall handling in
checkSeccompTrace: the current TracerDetect coverage verifies OneTimeCalls and
AllowedCalls+AuditCalls, but not a syscall that appears only in the Trace list.
Extend the tracer_linux_test.go suite with a case around
TracerDetect.checkSeccompTrace and makeCallPolicy(callPolicySpec) asserting that
a trace-only syscall returns syscallCheckOK and does not get consumed or
rejected, using the existing RegisterTracee, setCallPolicy, and ptraceGetRegs
test pattern.

In `@tests/clone-syscall-phase-hybrid/makefile`:
- Around line 1-17: Declare the non-file targets in this Makefile as .PHONY so
make never skips them when same-named files exist. Update the rules for default,
compile, test, assert, and clean to be marked phony, keeping their current
behavior in place while ensuring the target names remain command-only entry
points.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: febd1d7e-8355-42f8-8959-d8127ce9d0df

📥 Commits

Reviewing files that changed from the base of the PR and between e76ab2c and 320d692.

📒 Files selected for processing (40)
  • .gitignore
  • docs/README.md
  • docs/architecture.md
  • docs/runner/syscalls.md
  • docs/seccomp-bpf-migration.md
  • makefile
  • runner/README.md
  • runner/config.go
  • runner/config_darwin.go
  • runner/config_linux.go
  • runner/config_linux_test.go
  • runner/config_test.go
  • runner/exec.go
  • runner/exec_linux.go
  • runner/exec_linux_test.go
  • runner/process.go
  • runner/process_darwin.go
  • runner/process_linux.go
  • runner/process_linux_test.go
  • runner/sec.go
  • runner/seccomp_linux.go
  • runner/seccomp_linux_test.go
  • runner/syscall_policy.go
  • runner/syscall_policy_test.go
  • runner/tracer.go
  • runner/tracer_darwin.go
  • runner/tracer_linux.go
  • runner/tracer_linux_test.go
  • runner/tracer_regs_linux_amd64_test.go
  • runner/tracer_regs_linux_arm64_test.go
  • tests/README.md
  • tests/clone-syscall-phase-hybrid/case.json
  • tests/clone-syscall-phase-hybrid/main.c
  • tests/clone-syscall-phase-hybrid/makefile
  • tests/syscall-policy-deny-hybrid/case.json
  • tests/syscall-policy-deny-hybrid/main.c
  • tests/syscall-policy-deny-hybrid/makefile
  • tests/syscall-policy-trace-audit-hybrid/case.json
  • tests/syscall-policy-trace-audit-hybrid/main.c
  • tests/syscall-policy-trace-audit-hybrid/makefile

Comment thread runner/process_linux.go
"golang.org/x/sys/unix"
)

const syscallStopSignal = syscall.Signal(syscall.SIGTRAP | 0x80)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 确认 syscall.SIGTRAP 的类型以及 unconvert 是否在 lint 配置中启用
rg -nP 'SIGTRAP\s+Signal' $(go env GOROOT 2>/dev/null)/src/syscall 2>/dev/null
fd -t f -e yml -e yaml '\.golangci' -H | xargs -r rg -n 'unconvert' 2>/dev/null

Repository: hustoj/runner

Length of output: 184


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- relevant source ---'
grep -nR "type Signal" "$(go env GOROOT)/src/syscall" | head -20
grep -nR "SIGTRAP" "$(go env GOROOT)/src/syscall" | head -20

echo '--- repo file context ---'
cat -n runner/process_linux.go | sed -n '1,30p'

echo '--- lint config references ---'
fd -t f -e yml -e yaml -e toml -e json -H . . | xargs -r rg -n "unconvert|golangci"

echo '--- type probe via go toolchain ---'
cat > /tmp/typeprobe.go <<'PY'
package main

import (
	"fmt"
	"go/parser"
	"go/token"
	"go/types"
	"os"
	"path/filepath"
)

func main() {
	src := `package p
import "syscall"
const x = syscall.Signal(syscall.SIGTRAP | 0x80)
const y = syscall.SIGTRAP | 0x80
`
	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "p.go", src, 0)
	if err != nil { panic(err) }
	conf := types.Config{
		Importer: types.DefaultImportPathToName,
		Error: func(err error) { fmt.Fprintln(os.Stderr, err) },
	}
	_ = conf
	_ = f
	_ = filepath.Separator
	fmt.Println("go/types probe placeholder")
}
PY
echo '--- go env ---'
go env GOROOT GOVERSION

Repository: hustoj/runner

Length of output: 3448


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- GOROOT definitions ---'
GOROOT="$(go env GOROOT)"
grep -RIn "type Signal" "$GOROOT/src/syscall" | head -20
grep -RIn "SIGTRAP" "$GOROOT/src/syscall" | head -20

echo '--- repo context ---'
cat -n runner/process_linux.go | sed -n '1,25p'

echo '--- lint config ---'
fd -t f -e yml -e yaml -e toml -e json -H . . | xargs -r rg -n "unconvert|golangci"

echo '--- type-check expression ---'
cat > /tmp/typeprobe.go <<'EOF'
package main

import (
	"fmt"
	"go/ast"
	"go/importer"
	"go/parser"
	"go/token"
	"go/types"
	"os"
)

func main() {
	src := `package p
import "syscall"
const x = syscall.Signal(syscall.SIGTRAP | 0x80)
const y = syscall.SIGTRAP | 0x80
`
	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "p.go", src, 0)
	if err != nil {
		panic(err)
	}

	info := &types.Info{
		Types: make(map[ast.Expr]types.TypeAndValue),
		Defs:  make(map[*ast.Ident]types.Object),
		Uses:  make(map[*ast.Ident]types.Object),
	}
	conf := types.Config{Importer: importer.Default(), Error: func(err error) { fmt.Fprintln(os.Stderr, err) }}
	_, err = conf.Check("p", fset, []*ast.File{f}, info)
	if err != nil {
		fmt.Fprintln(os.Stderr, "type-check error:", err)
		os.Exit(1)
	}

	ast.Inspect(f, func(n ast.Node) bool {
		e, ok := n.(ast.Expr)
		if !ok {
			return true
		}
		pos := fset.Position(e.Pos())
		if pos.Line == 3 || pos.Line == 4 {
			fmt.Printf("%s: %T => %s\n", pos, e, info.Types[e].Type)
		}
		return true
	})
}
EOF
go run /tmp/typeprobe.go

Repository: hustoj/runner

Length of output: 3910


移除多余的类型转换
外层 syscall.Signal(...) 是冗余的,syscall.SIGTRAP | 0x80 的结果已经是 syscall.Signal,会触发 unconvert。

🧰 Tools
🪛 golangci-lint (2.12.2)

[error] 11-11: unnecessary conversion

(unconvert)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runner/process_linux.go` at line 11, The syscallStopSignal declaration has a
redundant type conversion: syscall.SIGTRAP | 0x80 already yields a
syscall.Signal, so remove the outer syscall.Signal(...) cast to satisfy
unconvert. Update the constant in process_linux.go at syscallStopSignal and keep
the expression as a plain bitwise OR result.

Source: Linters/SAST tools

Comment thread runner/seccomp_linux.go
Comment on lines +1 to +14
//go:build linux

package runner

import (
"errors"
"fmt"
"runtime"
"syscall"
"unsafe"

"github.com/hustoj/runner/sec"
"golang.org/x/sys/unix"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

修复 goimports 格式问题。

golangci-lint 报告该文件导入块存在格式问题(goimports 检查失败),会导致 CI lint 阶段失败。建议在本地运行 goimports -w runner/seccomp_linux.go 后重新提交。

🧰 Tools
🪛 golangci-lint (2.12.2)

[error] 12-12: File is not properly formatted

(goimports)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runner/seccomp_linux.go` around lines 1 - 14, The import block in
seccomp_linux.go is not goimports-compliant and is causing the golangci-lint
check to fail. Reformat the imports in that file using goimports so the
standard/library and third-party groups are ordered correctly and any unused
imports are removed, then verify the package still builds cleanly.

Source: Linters/SAST tools

Comment on lines +10 to +12
assert:
@grep -q "passed!" test.log
@grep -q "audit syscall source=seccomp.*getppid" runner.log

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

补上 getpid 的 trace 断言。

当前只校验了 passed! 和 getppid 的审计日志,Trace: ["getpid"] 对应的 seccomp trace 路径并没有被验证;如果 trace 事件处理回退成“静默放行”,这个用例仍可能通过。建议再断言一条 getpid 的 seccomp trace 输出,确保 hybrid 的 trace 分支真的被覆盖。

🛠️ 建议补丁
 assert:
 	`@grep` -q "passed!" test.log
+	`@grep` -q "seccomp trace event.*getpid" runner.log
 	`@grep` -q "audit syscall source=seccomp.*getppid" runner.log
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assert:
@grep -q "passed!" test.log
@grep -q "audit syscall source=seccomp.*getppid" runner.log
assert:
`@grep` -q "passed!" test.log
`@grep` -q "seccomp trace event.*getpid" runner.log
`@grep` -q "audit syscall source=seccomp.*getppid" runner.log
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/syscall-policy-trace-audit-hybrid/makefile` around lines 10 - 12, The
assert target currently validates only the pass result and the getppid audit
log, so the getpid trace path in the hybrid seccomp flow is not being checked.
Update the assert rule to also verify a seccomp trace output for getpid, using
the existing runner.log checks alongside the current grep assertions, so the
trace branch in the syscall policy test is explicitly exercised.

@freefcw
freefcw merged commit 8bacc61 into master Jul 5, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant