Formally verifying exceptions in low-level code with Separation Logic
Marco Paviotti and Jesper Bengtson IT University of Copenhagen
22nd October Nordic Workshop on Programming Theory (NWPT) Reykjavik, Iceland
1
Formally verifying exceptions in low-level code with Separation - - PowerPoint PPT Presentation
Formally verifying exceptions in low-level code with Separation Logic Marco Paviotti and Jesper Bengtson IT University of Copenhagen 22nd October Nordic Workshop on Programming Theory (NWPT) Reykjavik, Iceland 1 Verification of low-level
Marco Paviotti and Jesper Bengtson IT University of Copenhagen
22nd October Nordic Workshop on Programming Theory (NWPT) Reykjavik, Iceland
1
kernels)
When an interrupt fires the CPU:
Save Restore IRET
handler in the IDT table
top of the stack
It is the handler responsibility to restore the state and return from the interrupt
IDT Register Typical Handler Structure
IDT table
3
mov ESI, info; mov EDI, [ESI]; mov [EDI], 0; add EDI, 4; mov [ESI], EDI.
Unmapped Store
[ESI] EDI= EDI
4
mov ESI, info; mov EDI, [ESI]; mov [EDI], 0; add EDI, 4; mov [ESI], EDI.
Unmapped Store
[ESI] EDI=
!!
5
example
6
We rely on an existing Coq formalisation of the assembly x86[1,2]
1Andrew Kennedy, Nick Benton, Jonas Braband Jensen, and Pierre-Evariste Dagand. Coq: the world’s best macro assembler? In PPDP 2013.
thus Verification of Device Drivers and Schedulers (Concurrency)
7
list 32 bool * list 32 bool
` (safe ⌦ EIP 7! j ? Q) ! (safe ⌦ EIP 7! i ? P) ↵ i..j 7! c
Precondition Post-Condition Code
Meaning
9
when ‘c’ is a code block
“If the code is safe to run from then it is safe to run from the state ”
Q P
` (safe ⌦ EIP 7! i) ↵ i 7! JMP i It is safe to sit in a tight loop forever:
It suffices to show that if the loop is safe for k-1 steps (“later”) then it is safe for k steps (“now”)
Proof.
The “later” modality is due to [Nakano, 2000]
Löb Induction
10
` . safe ⌦ EIP 7! i ↵ i 7! JMP i
safe ⌦ EIP 7! i ↵ i 7! JMP i
safe ⌦ EIP 7! i ↵ i 7! JMP i `
.S ` S ` S
safe ⌦ (EIP 7! j? safe ⌦ (EIP 7! i?
ptr
r1
v1
r2
v2
)
ptr
r1
v2
r2
v2
)
11
safe ⌦ (EIP 7! i? )
ptr
ESP
j
r2
v2
)
Unmapped location
safe ⌦ (EIP 7! fail?
Invariant
ptr
ESP
? ptr
r1
!!
12
mov ESI, info; mov EDI, [ESI]; mov [EDI], 0; add EDI, 4; mov [ESI], EDI.
Invariant
Unmapped
Store
fail
IDT GP Exception
ESI? ?
Q2 Q1
safe ⌦ EIP 7! fail ? INTL 7! 1 ? ESP 7! s 4 ? 9ret.s 4..s 7! ret
safe ⌦ EIP 7! j ? INTL 7! 0 ? ESP 7! s ? s 4..s 7! sv ? 9p.EDI 7! p + 49unk.p..(p + 4) 7! unk
P
safe ⌦ EIP 7! i ? EDI 7! ? ESP 7! s ? s 4..s 7! sv
` ((safe ⌦ Q1 ^ safe ⌦ Q2) ! safe ⌦ P) ↵ i..j 7! c ⌦ R Theorem
Exception occurs Success IDT Precondition
14
Coq code
programs with exceptions
Tianks!