Skip to content

Commit cadca32

Browse files
author
Dongkeun Lee
committed
test(azure): pin that the verified guest bytes are the bytes returned
1 parent 544538c commit cadca32

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/fm-azure-validation.test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,21 @@ saved=json.loads((env["state_dir"]/"azv-aaaaaaaaaaaa.json").read_text())
16281628
assert "unbound_view_since" not in saved, \
16291629
"a new attempt inherited the previous attempt's settle stamp"
16301630
1631+
# N-2: the bytes VERIFIED must be the bytes RETURNED. Digesting one read and
1632+
# returning a second read is a TOCTOU: a writer landing between them passes the
1633+
# check while different content is handed back, and that content is uploaded as
1634+
# the Run Command script and executes as root on the cell. A race cannot be
1635+
# observed by waiting for it, so the second read is instrumented to differ - if
1636+
# the implementation reads twice, it returns the instrumented bytes.
1637+
saved_read_text=m.Path.read_text
1638+
m.Path.read_text=lambda self,*a,**k:"#!/bin/sh\nEVIL\n"
1639+
try:
1640+
returned=m.sealed_guest_text(env,seed())
1641+
finally:
1642+
m.Path.read_text=saved_read_text
1643+
assert returned==sealed_text, \
1644+
"sealed_guest_text returned bytes it never verified: "+repr(returned)
1645+
16311646
# The recorded stamping flag comes from the bytes that are about to run.
16321647
assert saved["guest_stamps_attempt"] is False, saved.get("guest_stamps_attempt")
16331648
stamping=sealed_text+"printf 'FM_AZURE_VALIDATION_RESULT %s boot=%s outcome=%s attempt=%s\\n'\n"

0 commit comments

Comments
 (0)