Repository navigation
Commit 770bc61
virtiofs: restore microVM handles opened with access mode 3
A microVM guest that opened a virtio-fs file with access mode 3 and
held it open could save the VM's state, but its restore failed with
"saved handle has invalid access mode", on read-write and read-only
shares alike (microsoft/nvx#2125). Linux's open(2) reserves access
mode 3 to check for read and write permission and return a descriptor
that can neither read nor write, and the guest's FUSE client sends
that access mode to FUSE_OPEN, which accepts it.
The restore disagreed with FUSE_OPEN about such a handle twice.
reopen_flags rejected access mode 3 outright, and
validate_microvm_state took every access mode other than O_RDONLY for
one that writes, so a read-only share or child, or a node outside the
writable paths, could not restore the handle even without that
rejection. FUSE_OPEN gives the handle there, since check_open_readonly
refuses only the opens that opens_for_writing names: those for
O_WRONLY or O_RDWR, or with O_TRUNC.
reopen_flags now keeps every access mode, and the validation takes a
handle for one that writes as opens_for_writing takes the open that
reopens it, which drops O_TRUNC, so only O_WRONLY and O_RDWR need a
writable node. A restored handle keeps access mode 3, so it still
neither reads nor writes. The format of the saved state is unchanged.
a_handle_that_neither_reads_nor_writes_survives_save_and_restore opens
a file with access mode 3 on a read-write share, on a read-only share,
and outside the writable paths of a read-write share, saves and
restores the state, and expects the restored handle to serve its node
and to fail reads and writes with EBADF. At feature/microvm/dev
1633b37, the restore fails with "saved handle has invalid access
mode" on Windows 11 (NTFS) and Azure Linux 3 (kernel 6.18, tmpfs).
Without that check alone, it fails with "read-only microVM profile
cannot restore a writable handle" on the read-only share, and with
"microVM access policy cannot restore a writable handle outside its
writable paths" outside the writable paths. With the fix, the test
passes on both hosts, and so do the other tests of the virtiofs
package.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 350018c commit 770bc61
2 files changed
Lines changed: 67 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| |||
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| 47 | + | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
| |||
1200 | 1204 | | |
1201 | 1205 | | |
1202 | 1206 | | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
1203 | 1266 | | |
1204 | 1267 | | |
1205 | 1268 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
526 | 527 | | |
527 | 528 | | |
528 | 529 | | |
529 | | - | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
530 | 533 | | |
531 | 534 | | |
532 | 535 | | |
| |||
610 | 613 | | |
611 | 614 | | |
612 | 615 | | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | 616 | | |
618 | 617 | | |
619 | 618 | | |
| |||
0 commit comments