Differential testing of the `code-verification` TCB

Aberta
#4 2 comentários 1 reação 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
Meio dia
Facilidade para iniciantes
50/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
c, linux

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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).

Linguagem predominante
Lean
Estrelas
283
Forks
43
Merge médio
36min
PRs com merge (30d)
1

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de google-deepmind/code-verification

Todas as issues de google-deepmind/code-verification

Issues semelhantes

Mais issues de Operating Systems

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.