Differential testing of the `code-verification` TCB

未關閉
#4 2 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

google-deepmind/code-verification 的其他 Issue

查看 google-deepmind/code-verification 的全部 Issue

相似的 Issue

更多 Operating Systems Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。