Differential testing of the `code-verification` TCB
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 半天
- 新手友好度
- 50/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- c, linux
调研方向
Start with execSchedGetaffinity in arm64-semantics/Arm64/Trusted/Syscalls/Kernel/Sys.lean, where the cpusetsize check is, and compare it with the kernel's 32-bit len * BITS_PER_BYTE test described in the report. Build elf_run with lake -d Arm64/Testing build elf_run and run the poc.S reproducer, which should exit 234 natively and currently exits 8 in the model. Extend Arm64/Testing/SyscallDiff/src/cases/sched_getaffinity_einval.c with a wrapping length such as 0x80000000. Done means the model returns -EINVAL for those lengths, the probe covers them, and the PoC matches native Linux.
由索引模型根据 Issue 内容生成。
描述
Hi,
I've been testing the Linux process model in the TCB against actual Linux process semantics on AArch64 using a new testing library I'm working on (Ephyra), I locally have 4 findings where the trusted semantics diverge from the real semantics, so I wanted to reach out by filing one of them and asking for the best course of action for filing the other ones.
Note: As far as I can tell, none of the 4 issues affect the Signal theorems, they are bugs in the model that libsignal-cli binary currently does not trigger.
Below is the AI-generated triage report that I received from the fuzzer run, I've reviewed the file level facts and claims, but I haven't reproduced the results on the Graviton machine:
Summary
execSchedGetaffinity returns -EINVAL only when cpusetsize < 8 or cpusetsize % 8 != 0.
Linux also returns -EINVAL when cpusetsize is a nonzero multiple of 2^29 (0x20000000,
0x40000000, 0x80000000, 0xc0000000). For those sizes the model returns 8 and writes the
mask to memory, while Linux returns -22 and writes nothing. So both X0 and memory differ from
what the kernel produces.
Tested at 808b4b7 (paper) and b0f729a (HEAD). Syscalls/Kernel/Sys.lean is byte-identical
in the two commits.
Model
arm64-semantics/Arm64/Trusted/Syscalls/Kernel/Sys.lean, execSchedGetaffinity:
let cpusetsize := (s.readReg32 Reg.x1).toNat
...
if cpusetsize < 8 || cpusetsize % 8 != 0 then (-EINVAL) ...
Linux
kernel/sched/syscalls.c:
SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
unsigned long __user *, user_mask_ptr)
{
...
if ((len * BITS_PER_BYTE) < nr_cpu_ids)
return -EINVAL;
len is unsigned int, so the product len * 8 is computed in 32 bits. When len is a
multiple of 2^29 the product wraps to 0, and 0 is less than nr_cpu_ids.
Reproducer
poc.S is a static no-libc program that exits with the low byte of the return value:
.global _start
.text
_start:
mov x0, #0 // pid 0 = calling thread
mov x1, #0x80000000 // cpusetsize = 2^31
adrp x2, buf
add x2, x2, :lo12:buf // mask buffer
mov x8, #123 // __NR_sched_getaffinity
svc #0
mov x8, #93 // __NR_exit, status = x0 & 0xff
svc #0
.bss
.balign 8
buf: .skip 64
Build it, then run it natively and in the model:
clang --target=aarch64-linux-gnu -nostdlib -static -fuse-ld=lld -Wl,--no-pie -o poc.elf poc.S
./poc.elf; echo $? # Linux: 234
echo '{"argv": ["prog"], "dirs": [], "max_steps": 1000}' > req.json
elf_run run --trusted poc.elf req.json # model: "exit_code":8
elf_run comes from lake -d Arm64/Testing build elf_run in arm64-semantics. The "dirs": [] field
is needed: without it elf_run defaults to ["/", "/tmp"], which the loader rejects.
| result | |
|---|---|
| Linux 7.0 (arm64, Neoverse N1, 16 CPUs) | exit 234 (-EINVAL), buffer untouched |
model (elf_run run --trusted) |
exit 8, mask written |
If the mask pointer is not writable, the model returns -EFAULT, while Linux still returns
-EINVAL.
The regression probe Arm64/Testing/SyscallDiff/src/cases/sched_getaffinity_einval.c tests only
len 0, 4, 7 and 9, so it never reaches a length whose 32-bit product wraps.
Suggested fix
let len32 := s.readReg32 Reg.x1
if len32.toNat < 8 || len32.toNat % 8 != 0 || len32 * 8#32 == 0#32 then (-EINVAL) ...
This matches the kernel for any nr_cpu_ids < 64, including the model's single CPU. With the fix,
the PoC exits 234 on both sides.
Found by differential testing of elf_run --trusted against native execution on AWS Graviton2
(Linux 7.0.0-1017-aws).
- 主要语言
- Lean
- 星标
- 283
- 派生
- 43
- 平均合并
- 36 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google-deepmind/code-verification 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 45/100
google-deepmind/code-verification#1 · 1 条评论 ·
查看 google-deepmind/code-verification 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 86/100
itsfatduck/optimizerDuck#110 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 2 天内回复
-
riscv64
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
llm-assisted
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
egoist/mygo#2126 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复