Skip to content

Commit 66ef6a1

Browse files
authored
Merge pull request #1936 from microsoft/agents/issue-1614-aggregate-child-names
openvmm: refuse microVM file children whose names hold a colon or a backslash
2 parents 89e5f6a + 8fc7a8d commit 66ef6a1

8 files changed

Lines changed: 138 additions & 18 deletions

File tree

‎doc/design/3.6-host-filesystem.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ describes.
104104
An aggregate's root lists its children in declaration order and refuses every
105105
change with `EROFS`. A child is a host directory or a single regular file. The
106106
declared kind, not the host object, decides which, and the VMM refuses a host
107-
path of the other kind. A file child serves only its file, as the child
107+
path of the other kind. It also refuses a file whose name contains `\` or `:`,
108+
which the server refuses in every path of an export, so the guest could never
109+
reach it. A file child serves only its file, as the child
108110
itself: its volume is the file's parent directory, narrowed to the file's
109111
name, which the guest never reaches, so the guest cannot list or change
110112
anything beside the file, a lookup below it fails with `ENOTDIR`, and every

‎doc/openvmm-upstream-roadmap.md‎

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
- Mapped fork tip: `1e492803287f04b40bb7c17e8648c4b96af52ecc`, position 126. The graph, PR
1010
summary, and commit mapping below cover positions 001-126, the PR18 fixups at positions 302,
1111
333, and 342, and the PR13 fixup at position 340.
12-
- NVX's pinned OpenVMM revision: `5c82edac42ca480d546459e019860759a27c2211`, position 342, the head
13-
of microsoft/openvmm#5208, whose commit follows position 341, `ed2d7e3a1`, the head of
12+
- NVX's pinned OpenVMM revision: `afa0e9c20a7943d3ec556098d9272f4ee502bdd4`, position 343, the head
13+
of microsoft/openvmm#5209, whose commit follows position 342, `5c82edac4`, the head of
14+
microsoft/openvmm#5208, whose commit follows position 341, `ed2d7e3a1`, the head of
1415
`feature/microvm/dev`, where microsoft/openvmm#5207 landed position 341 on position 340,
1516
`32888344a`, where microsoft/openvmm#5206 landed position 340 on position 339, `b51f9156c`, the
1617
head of the `feature/microvm/release/v7.2` branch of microsoft/openvmm. The
@@ -19,9 +20,9 @@
1920
landed, so each later commit's position is one less than before, and it added five fixups at its
2021
tip, positions 335-339. Of the 334 replayed commits, 47 conflicted with upstream and 13 replayed
2122
with new context; see [Conflicts of the v7.2 rebase](#conflicts-of-the-v72-rebase). The pin is
22-
216 commits past the mapped tip on the same first-parent chain. Positions 127-301, 303-332, 334,
23-
and 341 are not yet assigned to PRs, positions 302, 333, and 342 are PR18 fixups, position 340
24-
is a PR13 fixup, and positions 316 and 335-339 are rebase fixups; see
23+
217 commits past the mapped tip on the same first-parent chain. Positions 127-301, 303-332, 334,
24+
341, and 343 are not yet assigned to PRs, positions 302, 333, and 342 are PR18 fixups, position
25+
340 is a PR13 fixup, and positions 316 and 335-339 are rebase fixups; see
2526
[Commits after the mapped tip](#commits-after-the-mapped-tip).
2627
- Upstream main: `bf353460ff70e4a65627bb7003bed2cad1ce121f` (2026-11-21), the fork base; see
2728
[Upstream main past the fork base](#upstream-main-past-the-fork-base).
@@ -1619,7 +1620,8 @@ bf353460f
16191620
-> PR13 fixup [340]
16201621
-> virtio-fs aggregate root reads bounded at 1 MiB [341]
16211622
-> PR18 fixup [342]
1622-
-> 5c82edac4 (NVX pin)
1623+
-> microVM file children whose names hold `\` or `:` refused [343]
1624+
-> afa0e9c20 (NVX pin)
16231625
```
16241626

16251627
For upstream review, PR01-PR03, PR05, PR06, and PR14 can be rebased independently onto current
@@ -1658,7 +1660,7 @@ the policy tests share the `request` helper that the tests call.
16581660

16591661
## Commits after the mapped tip
16601662

1661-
The NVX pin extends the chain past position 126 without merges. Of its 216 later commits, positions
1663+
The NVX pin extends the chain past position 126 without merges. Of its 217 later commits, positions
16621664
302, 333, and 342 are PR18 fixups, position 340 is a PR13 fixup, position 316 is the fixup of the
16631665
v7.1 rebase, positions 335-339 are the fixups of the v7.2 rebase, and the others are not yet
16641666
classified or assigned to PRs.
@@ -1669,15 +1671,15 @@ of the v4.0 reorganization, positions 201-206 followed it, positions 207-213 fol
16691671
reorganization, positions 214 and 215 followed the v5.1 rebase, positions 216-253 followed the
16701672
v6.0 reorganization, positions 254-296 followed the v6.1 rebase, positions 297-315 followed the
16711673
v7.0 reorganization, position 316 is the v7.1 rebase's fixup, positions 317-334 followed the
1672-
v7.1 rebase, positions 335-339 are the v7.2 rebase's fixups, and positions 340-342 followed the
1674+
v7.1 rebase, positions 335-339 are the v7.2 rebase's fixups, and positions 340-343 followed the
16731675
v7.2 rebase, so they combine none, apart from
16741676
position 215, which combines v5.1 positions 222 and 223, and the commits that the v7.0
16751677
reorganization folded into them. Each commit through position 316 has the position that it had in
16761678
v7.0 and v7.1, and each of positions 317-334 is its v7.1 position less one, since the v7.2 rebase
16771679
dropped v7.1 position 317, upstream's microsoft/openvmm#5160, which v7.1 had backported. Each
16781680
commit's v6.1 position is its v6.0 position less seven, the number of commits that the v6.1 rebase
16791681
dropped before it, and its v6.0 position is its v5.1 position through 147 and one less from v5.1
1680-
position 149 on, and positions 297-342 have no earlier position; see
1682+
position 149 on, and positions 297-343 have no earlier position; see
16811683
[Conflicts of the v7.2 rebase](#conflicts-of-the-v72-rebase),
16821684
[The v7.0 reorganization](#the-v70-reorganization),
16831685
[Conflicts of the v6.1 rebase](#conflicts-of-the-v61-rebase), and
@@ -1906,6 +1908,7 @@ whose first 220 commits are those of `feature/microvm/release/v6.0`, and a v4.0
19061908
| 340 | `32888344a` | - | - | - | - | - | - | virtiofs: keep node names when renaming a name onto itself (microsoft/openvmm#5206); fold into 048, its test into 166 |
19071909
| 341 | `ed2d7e3a1` | - | - | - | - | - | - | virtiofs: bound the buffer of an aggregate root's directory read (microsoft/openvmm#5207) |
19081910
| 342 | `5c82edac4` | - | - | - | - | - | - | virtiofs: bound microVM directory snapshots in total when listing (microsoft/openvmm#5208); fold into 083, its budget in `new_microvm_aggregate` and its tests into 164 |
1911+
| 343 | `afa0e9c20` | - | - | - | - | - | - | virtiofs: refuse a microVM file child that its volume cannot name (microsoft/openvmm#5209) |
19091912

19101913
The remarks that say whether commits apply to upstream main record what was found on upstream main
19111914
when each commit was mapped: the v3.0 reorganization's base, `b2676222b`, for the commits that it
@@ -1916,7 +1919,7 @@ and `c0694c4da`, upstream main on 2026-11-16, for positions 297-306, `c4419be15`
19161919
main on 2026-11-19, for positions 321-324, `78af54a51`, upstream main on 2026-11-20, for position
19171920
325, `d83f87209`, upstream main later that day, for position 326, `265f0a73f`, upstream main
19181921
later still, for positions 327 and 328, and `bf353460f`, upstream main on 2026-11-21 and the v7.2
1919-
fork base, for positions 329-334 and 340-342.
1922+
fork base, for positions 329-334 and 340-343.
19201923
They name the positions that the commits have now, but neither the v7.2 rebase on `bf353460f`, the
19211924
v7.1 rebase on `9a875b563`, nor the v7.0 reorganization on `e6b458cc0` checked them again, nor did
19221925
the v6.1 rebase check the earlier ones on `7d90c4104`.
@@ -4374,6 +4377,32 @@ since it lacks the microVM persistence. Replaying the commit there conflicts in
43744377
`lib.rs`, next to the code of positions 081, 083, and 158, and in the microVM's `file.rs`, `fs.rs`,
43754378
and `fs_tests.rs`, which upstream main lacks, so it follows PR18 upstream.
43764379

4380+
Position 343 has `open_microvm_volume` refuse the file of an aggregate's file child whose name holds
4381+
`\` or `:`, so that attaching the aggregate fails, at a cold boot or a restore, with an error that
4382+
names the file (microsoft/nvx#1614). Position 165 opens the file's host directory as a strict
4383+
volume whose root object is the file, at its name, and PR18's position 081 has a strict volume
4384+
refuse every path with `\` or `:`, in `validate_relative_path`, which the preflight of an insert
4385+
that position 081 adds, the confinement check that PR27's position 126 adds, and the save and
4386+
restore of PR18's position 083 apply to every name of a node. Nothing checked the file's name
4387+
when the child attached, since the profile's path rules cover only the policy paths that it
4388+
parses, so a file child whose name had one, common on Linux, as in timestamps or digests, and on
4389+
Windows the name of an alternate data stream of a file, attached, but every guest `LOOKUP` of it
4390+
failed with `EINVAL`, and so did a `READDIRPLUS` of the aggregate's root from the child on, while
4391+
a plain `READDIR` listed it as a regular file. The commit applies the same `validate_relative_path`
4392+
to the file's name; a directory's own name is never a path of its volume, so directory shares and
4393+
children are unchanged, and the saved state keeps its format. It changes the file branch of
4394+
`open_microvm_volume` in the microVM's `fs.rs`, which position 164 adds and position 165 extends
4395+
to files, and the rustdoc of `new_microvm_aggregate`, which position 164 adds and position 165
4396+
changes; PR18's positions 081, 083, and 085, PR22's position 102, PR27's position 126, and
4397+
positions 158, 160, 194, 332, and 342 also change the file. It adds tests to the microVM's
4398+
aggregate tests, which position 164 adds and positions 165, 194, and 341 also change, and a bullet
4399+
to the "Single files" part of the Guide's virtio-fs page, which position 165 adds. It fixes a
4400+
defect of position 165, which no PR maps, so it is not yet assigned to a PR either and follows
4401+
position 165. Upstream main lacks the defect, since it lacks the microVM profile and its file
4402+
children. Replaying the commit there conflicts in all three files, which upstream main lacks: the
4403+
microVM's `fs.rs` and `aggregate_fs_tests.rs` and the Guide's virtio-fs page, so it cannot go
4404+
upstream on its own.
4405+
43774406
## PR summary
43784407

43794408
Each count is of v7.2 commits, which include the fixups that the v3.0, v4.0, v5.0, v6.0, and v7.0

‎doc/run.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,11 @@ children are the outermost mapped directories and the mapped files outside
890890
them, so a `--mount` of a directory again, or of a path inside a mapped
891891
directory, maps a part of that directory's child rather than a child of its
892892
own. OpenVMM's `file` flag marks a child that is a shared file, so OpenVMM
893-
refuses a directory that replaced the file rather than export all of it. A
893+
refuses a directory that replaced the file rather than export all of it.
894+
OpenVMM refuses a colon or a backslash in every path of a share, and so a
895+
file child whose name contains one, such as a Windows path that names an
896+
alternate data stream, which the guest could never reach; NVX rejects such a
897+
file child before boot. A
894898
child is read-write only if it holds a read-write mapping, and OpenVMM then
895899
limits its writes to its read-write mappings, which NVX passes as
896900
`--mount-write` paths when they lie inside a read-only one. A read-only

‎nvx/src/host/filesystem/limits.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ pub(super) fn check_root(root: &Path) -> Result<()> {
3939
Ok(())
4040
}
4141

42+
/// Explains why OpenVMM cannot export the file `file` alone, as a child, or returns `None` if it
43+
/// can. OpenVMM reaches the file by its name, in which it refuses a colon or a backslash, as in
44+
/// every path of an export, such as a Windows path that names an alternate data stream of a file.
45+
pub(super) fn file_name_problem(file: &Path) -> Option<&'static str> {
46+
file.file_name()
47+
.is_some_and(|name| name.to_string_lossy().contains([':', '\\']))
48+
.then_some("has a colon or a backslash in its name")
49+
}
50+
4251
/// Applies OpenVMM's rules for the paths that it is to `action` in the exported directory `root`,
4352
/// so a policy that OpenVMM would refuse fails at provision rather than at every start: those of
4453
/// [`policy_limits`], and on the host, no link or reparse point below `root` and no other file

‎nvx/src/host/filesystem/mod.rs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(crate) use self::host_path::{canonicalize, is_reparse_point};
8787
#[cfg(feature = "cli")]
8888
use self::host_path::{identity, relative_text};
8989
#[cfg(feature = "cli")]
90-
use self::limits::{check_policy_paths, check_root};
90+
use self::limits::{check_policy_paths, check_root, file_name_problem};
9191
#[cfg(feature = "cli")]
9292
use self::policy::{
9393
Writable, allowed_paths, canonicals, check_allowed_paths, check_read_only, check_write_paths,
@@ -360,7 +360,8 @@ pub(crate) struct ExportRequest<'a> {
360360
/// target is mapped once, read-only if either mapping is. Two objects never share a target, and a
361361
/// target inside another mapping's must show the very object that the other mapping shows there.
362362
/// A whole volume cannot be mapped, and a policy that would need more children than OpenVMM
363-
/// offers is refused.
363+
/// offers is refused. A file that a child exports alone must not have a colon or a backslash in
364+
/// its name, which OpenVMM refuses in every path of an export.
364365
///
365366
/// A read-only path must not lie inside a writable part, where the host could not keep it
366367
/// read-only: inside a read-write directory, unless write paths narrow that directory's writes
@@ -496,6 +497,14 @@ pub(crate) fn plan(request: &ExportRequest<'_>) -> Result<Option<PlannedExport>>
496497
let child_allowed = inside(&allowed);
497498
let child_denied = needed_denied_paths(&inside(&denied), &child_allowed);
498499
check_root(root)?;
500+
if !own.directory
501+
&& let Some(problem) = file_name_problem(root)
502+
{
503+
return unsupported(format!(
504+
"OpenVMM cannot export {}, which {problem}",
505+
root.display()
506+
));
507+
}
499508
policy_bytes += check_policy_paths(root, &child_denied, "hide")?;
500509
policy_bytes += check_policy_paths(root, &child_allowed, "show again")?;
501510
policy_bytes += check_policy_paths(root, &part.write, "make writable")?;

‎nvx/src/host/filesystem/tests.rs‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,64 @@ fn policy_paths_follow_openvmm_rules() {
889889
}
890890
}
891891

892+
/// OpenVMM reaches a file that a child exports alone by its name, and refuses a colon or a
893+
/// backslash in every path of an export, so the planner refuses such a file, and a recorded plan
894+
/// that exports one fails its check, but not a file in a directory with such a name, which OpenVMM
895+
/// opens by its host path.
896+
#[cfg(feature = "cli")]
897+
#[test]
898+
fn files_named_with_colons_or_backslashes_are_not_exported_alone() {
899+
let directory = root();
900+
let base = directory.path();
901+
let names: &[&str] = if cfg!(windows) {
902+
// A Windows path with a colon in its last name names an alternate data stream.
903+
&["config.json:stream"]
904+
} else {
905+
&["colon:here.txt", "back\\slash.txt"]
906+
};
907+
let refused = |error: Error| {
908+
assert_eq!(error.kind(), ErrorKind::Unsupported, "{error}");
909+
assert!(
910+
error.message().contains("a colon or a backslash"),
911+
"{error}"
912+
);
913+
};
914+
for name in names {
915+
let file = base.join("work").join(name);
916+
fs::write(&file, b"notes").unwrap();
917+
let policy = FilesystemPolicy {
918+
readonly_paths: vec![file],
919+
..FilesystemPolicy::default()
920+
};
921+
refused(plan(&policy).unwrap_err());
922+
}
923+
// A plan recorded before the planner refused such a file is refused when it is read back.
924+
let plain = plan(&FilesystemPolicy {
925+
readonly_paths: vec![base.join("work").join("config.json")],
926+
..FilesystemPolicy::default()
927+
})
928+
.unwrap()
929+
.unwrap();
930+
plain.check(ReservedTargets::BLOCKLESS_ROOT).unwrap();
931+
for name in names {
932+
let mut recorded = plain.clone();
933+
recorded.children[0].root.set_file_name(name);
934+
refused(recorded.check(ReservedTargets::BLOCKLESS_ROOT).unwrap_err());
935+
}
936+
if !cfg!(windows) {
937+
let file = base.join("colon:dir").join("notes.txt");
938+
fs::create_dir(file.parent().unwrap()).unwrap();
939+
fs::write(&file, b"notes").unwrap();
940+
let policy = FilesystemPolicy {
941+
readonly_paths: vec![file.clone()],
942+
..FilesystemPolicy::default()
943+
};
944+
let mapping = plan(&policy).unwrap().unwrap();
945+
assert_eq!(mapping.children[0].root, canonical(&file));
946+
assert!(mapping.children[0].file);
947+
}
948+
}
949+
892950
#[cfg(feature = "cli")]
893951
#[test]
894952
fn openvmm_limits_are_checked_per_directory() {

‎nvx/src/host/filesystem/verify.rs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::PathBuf;
66

77
use super::guest_path::depth;
88
use super::host_path::{display_path, relative_text};
9-
use super::limits::policy_limits;
9+
use super::limits::{file_name_problem, policy_limits};
1010
#[cfg(feature = "cli")]
1111
use super::policy::Writable;
1212
use super::policy::{nearest_rule, policy_rule_problem};
@@ -30,8 +30,9 @@ impl ExportPlan {
3030
/// root that reserves `reserved`: at least one and at most [`MAX_CHILDREN`] children, none
3131
/// inside another, each an absolute host path below a volume's root, with its host paths
3232
/// resolved, without a NUL character or a `..` component, and, on Windows, on a local drive,
33-
/// without the verbatim prefix, whose policy paths lie inside it within OpenVMM's limits and
34-
/// keep its rules, and writable exactly when a bind maps a path of it read-write; and at least
33+
/// without the verbatim prefix, each file without a colon or a backslash in its name, whose
34+
/// policy paths lie inside it within OpenVMM's limits and keep its rules, and writable exactly
35+
/// when a bind maps a path of it read-write; and at least
3536
/// one and at most [`MAX_HOST_MAPPINGS`] binds, each of a known child, from a relative source
3637
/// that holds the host's names joined with `/`, that a guest path can hold, and that the child
3738
/// does not hide, unless it shows paths inside it again, to a free guest target, parents before
@@ -80,6 +81,14 @@ impl ExportPlan {
8081
"child {index} has the host path {path:?}, which {problem}"
8182
));
8283
}
84+
if child.file
85+
&& let Some(problem) = file_name_problem(&child.root)
86+
{
87+
return invalid(format!(
88+
"child {index}, {}, is a file that {problem}, which OpenVMM cannot export",
89+
child.root.display()
90+
));
91+
}
8392
if let Some(path) = [&child.denied, &child.allowed, &child.write]
8493
.into_iter()
8594
.flatten()

0 commit comments

Comments
 (0)