diff --git a/build/build.rs b/build/build.rs index e7830d06881..39f23f978fb 100644 --- a/build/build.rs +++ b/build/build.rs @@ -208,6 +208,9 @@ struct ProgramConfig { /// and puts it in its view beside the session's `HOME`. A service's is /// implied. No row's view holds another's (`toyos_manifest::Program::view`). state: bool, + /// The installer: `/apps` is read-write in its view and read-only in + /// every other row's (`toyos_manifest::Program::installs`). + installs: bool, /// The file-server roles this binary serves, one process each /// (`toyos_manifest::Program::roles`). roles: Vec, @@ -918,6 +921,7 @@ fn render_manifest(config: &SystemConfig) -> Vec { authorize: cfg.authorize.clone(), service: cfg.service, state: cfg.state, + installs: cfg.installs, roles: cfg.roles.clone(), restart: cfg.restart, pager: cfg.pager, @@ -3340,6 +3344,30 @@ mod tests { } } + /// **Only the installer's view holds `/apps` read-write**: `pkg` in the + /// shipped image, and in no config a shell. A test image's writer is the + /// row its job installs through. + #[test] + fn only_the_installer_s_view_writes_apps() { + let root = Path::new(env!("CARGO_MANIFEST_DIR")); + for config in ALL_CONFIGS { + let rendered = render_manifest(&parse_config(&root.join(config))); + let manifest = toyos_manifest::parse(std::str::from_utf8(&rendered).unwrap()); + let writers: Vec<&str> = manifest + .programs + .iter() + .filter(|row| row.view().iter().any(|v| v.dir == toyos_manifest::package::DIR && v.write)) + .map(|row| row.name.as_str()) + .collect(); + let installers: &[&str] = match *config { + "images/system.toml" | "tests/images/hostedclangcase.toml" => &["pkg"], + "tests/images/proctreecase.toml" => &["test-runner"], + _ => &[], + }; + assert_eq!(writers, installers, "{config}"); + } + } + /// One prefix and no other, so a doc naming `/etc/logkeeper` or `/apps/logkeeper` is a /// token the filter below drops and an assertion that reds. const LOG_DOC_BIN: &str = "/system/bin/"; diff --git a/docs/src/architecture/files.md b/docs/src/architecture/files.md index 8700e7ebd7c..beae25f3c2c 100644 --- a/docs/src/architecture/files.md +++ b/docs/src/architecture/files.md @@ -22,8 +22,8 @@ prefix. An empty view names nothing. reaches it only through the file picker, which hands over that one file. - **No special cases.** The boot partition is in the updater's view and nobody else's; login data is in the login authority's view alone; `/apps` is - writable only in the installer service's view, and every other program sees - it read-only. + writable only in the installer's view, and every other program sees it + read-only. The working directory is the client's: a spawn states the child's starting directory, which the child resolves in its own view. diff --git a/images/system.toml b/images/system.toml index 71ad6532f05..b03619e1ca9 100644 --- a/images/system.toml +++ b/images/system.toml @@ -32,9 +32,9 @@ memory-floor-mib = 96 start = ["logkeeper", "uart", "diskserver", "fileserver", "compositor", "soundserver", "netstack", "filepicker", "acpiserver", "ps2server", "wlan", "vdagent"] # What every program launched out of `/apps` holds, whatever its own directory -# says. A package is unpacked by `/system/bin/pkg` into a writable directory, so -# a row read out of one would be a directory deciding what the machine hands -# out; this is the image's answer, one for all of them. Connectors only — +# says. A package is what an archive carried, so a row read out of one would +# be a directory deciding what the machine hands out; this is the image's +# answer, one for all of them. Connectors only — # `devices` and `syscap` have no spelling here, so nothing installed claims # hardware or enters the RT band — and no directory: a package sees its own # `/apps/` read-only and its own `/home/toy/Apps/`, its `HOME`. @@ -52,10 +52,13 @@ folder = "read-write" # with the session user's home, and `state = true` gives it a `/state/` # beside it. No row's view holds any other part of `/state`. [programs] -# The installer. It writes under `/apps` because `/apps` is writable to it. +# The installer: `installs = true` makes `/apps` read-write in its view, and +# it is read-only in every other row's, so `launch pkg install ` installs +# and a shell's own writes and its helpers' are refused, a `pkg` it spawns as +# one among them. Who may install is the `starts` that list it. # `/state/pkg` is where the machine's copy of the repository metadata it last # accepted belongs (`toyos_update::repo::Holder::Machine`). -pkg = { state = true } +pkg = { state = true, installs = true } # **Every image that carries a `TOYOS-LOG` partition runs this**, and every # image does. The kernel keeps the record ring, writes the console only before diff --git a/issues/a-package-is-a-directory-under-apps-and-the-installer-is-a-program.md b/issues/a-package-is-a-directory-under-apps-and-the-installer-is-a-program.md index a04b61768e5..8ab290b28b8 100644 --- a/issues/a-package-is-a-directory-under-apps-and-the-installer-is-a-program.md +++ b/issues/a-package-is-a-directory-under-apps-and-the-installer-is-a-program.md @@ -37,9 +37,13 @@ the binary in a ToyOS guest is this track's harness's job, not gbae's. stay for crates, `rust/` and LLVM. Recipes and patches live in this repository, where `NOTICE` and the licence gate carry them, not in a ports repository. -- **The installer** is `/system/bin/pkg`. Who may write `/apps` (owner - ruling, 2026-11-05) is staged in stage 2 of - `issues/every-program-sees-only-the-files-it-was-given.md`. `pkg` +- **The installer** is `/system/bin/pkg`, and only its row's view holds + `/apps` read-write (owner ruling, 2026-11-05; stage 2 of + `issues/every-program-sees-only-the-files-it-was-given.md`): it installs + and removes launched, `launch pkg install `, and a `pkg` spawned as + a helper lists and refuses the rest by name. A caller that can launch + `pkg` answers its question itself, by `--yes` or the stdin it supplies, so + who decides an install is the `starts` that list `pkg`. `pkg` fetches, verifies, unpacks and commits, and it asks the user before it installs — at install, the moment the user typed the command, never at first run, so a refusal leaves nothing on disk and no answer has @@ -72,7 +76,7 @@ The storage track's users and mount-protocol stages do not block this one. `issues/the-guest-suite-runs-only-what-no-cheaper-tier-reaches.md` owes. **What a package holds is the image's `[apps]` row, never its own `manifest.toml`** — that file names which of the directory's - binaries a launch starts and nothing else, so a writable `/apps` cannot name + binaries a launch starts and nothing else, so no file under `/apps` can name a device or a right. The stage-then-commit above amends it: `pkg` writes `/apps//` in place today, its `manifest.toml` last (`system/pkg/src/main.rs`). It streams an archive of any size that fits diff --git a/issues/every-program-sees-only-the-files-it-was-given.md b/issues/every-program-sees-only-the-files-it-was-given.md index cfb1edc80c5..ab53cffe92b 100644 --- a/issues/every-program-sees-only-the-files-it-was-given.md +++ b/issues/every-program-sees-only-the-files-it-was-given.md @@ -63,17 +63,37 @@ other, with the same per-session isolation (owner, 2026-11-05). `/system` read-only, its own `/tmp` (`toyos_manifest::app_temporary`, a directory of the machine's), and nothing else a file server serves (`toyos_manifest::Program::view`). Every row the image declares still sees - the whole tree, `/system` read-only and the rest read-write but `/state`, - of which each row holds only its own directory where it keeps state - (`service = true` or `state = true`: the daemons' own state is built). - `/apps` is included, so a shell and everything it starts can - rewrite an installed package. Only the installer service writes `/apps` - (owner ruling, 2026-11-05): this stage gives that one row `/apps` - read-write and every other row, the shell included, - `/apps` read-only. Whether `pkg` becomes that service or its client is - this stage's brief. **Its exit**: a shell's write under `/apps` is refused - by the file server, and an install through the installer service still - commits; granting the shell's row `/apps` read-write reds the first. + the whole tree but `/state`, of which each row holds only its own + directory where it keeps state (`service = true` or `state = true`: the + daemons' own state is built); `/system` is read-only, `/log` and `/apps` + are read-only to all but one row each, and the rest is read-write. The + storage rows are started outside that + (`issues/storage-rows-start-holding-the-supervisors-whole-tree.md`), + which this stage's exit closes. + Only the installer service writes `/apps` (owner ruling, 2026-11-05). + Built: `/apps` is read-only in every declared row's view but the row + that declares `installs = true` (`toyos_manifest::Program::installs`), + which in the image is `pkg`'s. `pkg` is that service and not a client of + one: a launch already gives a row its own view, and who may launch it is + the `starts` that list it, so the authority is `images/system.toml`'s + alone and no port, protocol or daemon was added. `launch pkg install + ` installs; a `pkg` a shell spawns as a helper holds the shell's + view and refuses by name. Judged on the host: + `toyos_manifest`'s `only_the_installer_writes_apps`, red with the view + ignoring `installs`, and the build's + `only_the_installer_s_view_writes_apps` over every committed config, red + with that and with the shell's row granted `installs`. **Its exit**: a + shell's write under `/apps` is refused by the file server, and an install + through the installer service still commits. The first's check is the + metal `app_view` row's shell arm, in place of a boot with the shell's row + granted `/apps` read-write (orchestrator, 2026-11-11): the shell's + redirect into `/apps` is refused with the file server's read-only reason + while the same redirect into `/home` writes, and the two are one volume + and one server differing only in the grant, so the grant is what + refused. That row is green on the T14, both lines in its log (#1203). + Owed on a machine: the second, which is `pkg_install_gbae`'s + (`issues/the-guest-suite-runs-only-what-no-cheaper-tier-reaches.md`, + stage D), whose client launches `pkg`. `/dev/null` is a name only libc's `open` knows, answered with a kernel null handle (`SYS_NULL`): no view holds it, so `stat` of it and a program that does not open through libc find nothing. Whether views name it is diff --git a/issues/process-trees-metal-judge-waits-for-a-kernel-line-no-spawn-prints.md b/issues/process-trees-metal-judge-waits-for-a-kernel-line-no-spawn-prints.md new file mode 100644 index 00000000000..7b65fbfe35e --- /dev/null +++ b/issues/process-trees-metal-judge-waits-for-a-kernel-line-no-spawn-prints.md @@ -0,0 +1,33 @@ +--- +status: open +kind: tooling +opened: 2026-11-11 +--- + +# process_tree's metal judge waits for a kernel line no spawn prints + +The metal `process_tree` row's judge (`process_tree` in `tests/toyos.rs`) +requires the kernel's log to say `spawn: /tmp/process_tree_invalid_elf: ` +twice, once per B: the kernel loader refusing the 64 zero bytes the job +writes there. Since the spawner lays a program out itself +(`toyos::elf::program::lay_out` in `Helper::spawn`, `sdk/toyos/src/spawn.rs`), +an image that is no ELF is refused in the caller before any syscall, so the +kernel never sees it and never prints the line. The job still passes: B +asserts only that the spawn failed. + +Evidence: the T14's `proctreecase` boot of #1203 at e78085e47. The job ended +`===TEST_END test_rs_process_tree exit=0===`, the kernel's log holds no line +naming `/tmp/process_tree_invalid_elf`, and the judge answered `the loader +refused the invalid executable 0 times, not once per B`; the row's other +three tests passed. #1203 changes no kernel, spawn or `process_tree` code. +https://github.com/ToyOSOrg/evidence/tree/eff6d9e767dc90c4472908660613872f68f76dbb/r3. + +So the row is red on every bench, and what it meant to hold, a spawn refused +after admission under B releasing what admission took, is no longer reached +by this job. + +Exit: the job reaches a kernel refusal after admission again, with an image +that lays out and the kernel refuses, and the judge counts that line; or the +arm and the judge's count go, if a cheaper test holds that release. + +Owner: the guest-suite track. diff --git a/issues/storage-rows-start-holding-the-supervisors-whole-tree.md b/issues/storage-rows-start-holding-the-supervisors-whole-tree.md new file mode 100644 index 00000000000..f70b24beb81 --- /dev/null +++ b/issues/storage-rows-start-holding-the-supervisors-whole-tree.md @@ -0,0 +1,36 @@ +--- +status: open +kind: defect +opened: 2026-11-11 +--- + +# Storage rows start holding the supervisor's whole-tree namespace + +By inspection, and unverified on a machine: `diskserver` and the file servers +for the `memory` and `system` roles are started holding a duplicate of the +supervisor's own namespace, every directory of the tree read-write but +`/system`; `/apps` and `/log` are among them. + +The supervisor gives a storage row no view (`Grants::view` in +`system/supervisor/src/main.rs`), since a file server resolving a path +through itself waits for ever. Where such a row has no other name either, +`build_namespace` answers no namespace at all, and a spawn that names none +endows a duplicate of the spawner's own (`Helper::spawn`, +`sdk/toyos/src/spawn.rs`). The supervisor's own is the whole tree +(`toyos_manifest::whole_tree`). + +All three are the signed image's storage stack and open no path, so no +boundary between a session's programs and `/apps` or `/log` depends on it. +But "a storage row sees none" is not what happens, and no other row is +started this way. + +Evidence owed: `names.open("fs:/apps")` from one of those processes, which +answers a connection if this is right; if not, the process holds no +namespace, or one without `fs:/apps`. + +Exit: a storage row is started with an empty namespace where its row names +nothing, the check above refused on a machine, as part of stage 2 of +`issues/every-program-sees-only-the-files-it-was-given.md`, whose exit is +that nothing still sees the global tree. + +Owner: the file-isolation track. diff --git a/issues/the-guest-suite-runs-only-what-no-cheaper-tier-reaches.md b/issues/the-guest-suite-runs-only-what-no-cheaper-tier-reaches.md index a0e36c6be16..91e730f895c 100644 --- a/issues/the-guest-suite-runs-only-what-no-cheaper-tier-reaches.md +++ b/issues/the-guest-suite-runs-only-what-no-cheaper-tier-reaches.md @@ -120,7 +120,7 @@ and NVMe. Exit: as stage A. `Gone` and reconnect, and the supervisor's restart, its bound and its refusal by name of a restart whose claim is held, as module tests. - metal `layout_fresh_boot`: `/home`'s layout on the disk. -- metal `pkg_install_gbae`: `pkg install` lands a package that runs. +- metal `pkg_install_gbae`: a launched `pkg install` lands a package that runs. - metal `kernel_log_file`, `log_partition_layout`, `log_partition_identity`: `/log` on the stick and its layout. - metal `file_mtime_survives_a_reboot`: a file's mtime survives a reboot. diff --git a/lib/manifest/src/lib.rs b/lib/manifest/src/lib.rs index 8ea5ba6787f..a9b29397af3 100644 --- a/lib/manifest/src/lib.rs +++ b/lib/manifest/src/lib.rs @@ -27,6 +27,7 @@ //! authorize a disk authorization the supervisor mints at its start ([`authorize`]) //! service a system service: its `HOME` is `/state/`, not the session's //! state it keeps machine state of its own in `/state/` +//! installs the installer: `/apps` is read-write in its view //! role a file server for ``: one process of it per role //! restart the supervisor starts it again when it ends //! pager started as a pager: it may make the paged objects its files are read through @@ -365,6 +366,9 @@ pub struct Program { /// It keeps machine state of its own in [`STATE`]`/` beside the /// session's `HOME`: pkg's accepted repository metadata, say. pub state: bool, + /// The installer: [`package::DIR`] is read-write in its view and + /// read-only in every other row's ([`Self::view`]). + pub installs: bool, /// The file-server roles this row serves, one process each: the supervisor starts /// the binary once per role, with the role as its argument and the /// acceptor of the role's port ([`role_dirs`] are the grants on it). @@ -443,6 +447,8 @@ impl Program { /// **`/log` is read-only but to the row that keeps the log** /// ([`Self::keeps_the_log`]): what is there proves a boot to the next /// loader pass (`toyos_logstream::STOPPED`). + /// **`/apps` is read-only but to the installer** ([`Self::installs`]): a + /// shell's own writes and its helpers' are refused. pub fn view(&self) -> Vec { match self.package() { Some(name) => { @@ -456,9 +462,10 @@ impl Program { None => whole_tree() .into_iter() .filter(|view| view.dir != STATE) - .map(|view| match view.dir == LOG { - true => View { write: self.keeps_the_log(), ..view }, - false => view, + .map(|view| match view.dir.as_str() { + LOG => View { write: self.keeps_the_log(), ..view }, + package::DIR => View { write: self.installs, ..view }, + _ => view, }) .chain(self.state_dir().map(|dir| data_dir(&dir, true))) .collect(), @@ -475,8 +482,8 @@ pub struct Manifest { /// key, so these have no declaration to come from. pub supervisor_serves: Vec, /// The connectors every program launched from `/apps` is given beside its - /// view ([`Program::view`]), and nothing else. `/apps` is writable to - /// the installer, so this row is the image's rather than the package's — + /// view ([`Program::view`]), and nothing else. A package is what an + /// archive carried, so this row is the image's rather than the package's — /// which is why a device class and a `syscap` right have no spelling on /// the package side at all. pub apps: Vec, @@ -653,6 +660,9 @@ pub fn render(manifest: &Manifest) -> Result, RenderError> { if program.state { out.push_str("state\n"); } + if program.installs { + out.push_str("installs\n"); + } for role in &program.roles { if role_dirs(role).is_none() { return Err(RenderError::NoSuchRole { program: program.name.clone(), role: role.clone() }); @@ -836,6 +846,7 @@ pub fn parse(text: &str) -> Manifest { "authorize" if authorize::Authorization::parse(rest).is_some() => program.authorize.push(rest.to_string()), "service" => program.service = true, "state" if rest.is_empty() => program.state = true, + "installs" if rest.is_empty() => program.installs = true, "role" => program.roles.push(rest.to_string()), "restart" if rest.is_empty() => program.restart = true, "pager" if rest.is_empty() => program.pager = true, @@ -883,6 +894,7 @@ mod tests { slots: true, holds: vec![toyos_logstream::CONSOLE_INPUT.into()], state: true, + installs: true, authorize: vec!["tables".into(), "designate:data".into(), "format:data".into()], ..Program::default() }, @@ -1050,15 +1062,15 @@ mod tests { } } - /// **Every row the image declares sees the whole tree read-write but - /// `/system` and `/state`, and of `/state` only its own directory**: a - /// service's and a row's that declares state, none for any other. The - /// installer and the shell are alike: neither has authority over `/apps` - /// the other lacks, nobody writes the signed image, and nobody reads or - /// rewrites another program's machine state, the supervisor's included. + /// **Every row the image declares sees the whole tree but `/state`, and of + /// `/state` only its own directory**: a service's and a row's that + /// declares state, none for any other. `/system`, `/log` and `/apps` are + /// read-only and the rest read-write: nobody writes the signed image, and + /// nobody reads or rewrites another program's machine state, the + /// supervisor's included. #[test] fn a_declared_row_sees_the_whole_tree_but_state_and_of_state_its_own() { - let m = parse("program pkg /system/bin/pkg\nstate\nprogram shell /system/bin/shell\n"); + let m = parse("program files /system/bin/files\nstate\nprogram shell /system/bin/shell\n"); let whole_but_state = |own: Option<&str>| -> Vec<_> { std::iter::once(system()) .chain( @@ -1066,7 +1078,7 @@ mod tests { .iter() .zip(["apps", "config", "home", "", "", ""]) .zip(["data", "data", "data", "log", "boot", "memory"]) - .map(|((dir, root), role)| (role, dir.to_string(), root.to_string(), *dir != "/log")), + .map(|((dir, root), role)| (role, dir.to_string(), root.to_string(), !["/log", "/apps"].contains(dir))), ) .chain(own.map(|name| ("data", format!("/state/{name}"), format!("state/{name}"), true))) .collect() @@ -1074,13 +1086,13 @@ mod tests { let s = sample(); for (row, own) in [ (m.program("shell").unwrap(), None), - (m.program("pkg").unwrap(), Some("pkg")), + (m.program("files").unwrap(), Some("files")), (s.program("compositor").unwrap(), Some("compositor")), ] { assert_eq!(views(row), whole_but_state(own), "{}", row.name); } // A row that keeps state keeps its session `HOME`; a service's is its state. - assert_eq!(m.program("pkg").unwrap().home(), session_home()); + assert_eq!(m.program("files").unwrap().home(), session_home()); assert_eq!(s.program("compositor").unwrap().home(), "/state/compositor"); assert_eq!(m.program("shell").unwrap().state_dir(), None); } @@ -1106,6 +1118,31 @@ mod tests { assert_eq!(log(&named, "logkeeper"), Some(false)); } + /// **Only the installer writes `/apps`**: the row that declares it, and + /// neither the shell that starts it nor a row named like it. The rest of + /// its view is the shell's. + #[test] + fn only_the_installer_writes_apps() { + let m = parse( + "program pkg /system/bin/pkg\ninstalls\nprogram shell /system/bin/shell\nstarts pkg\n\ + program compositor /system/bin/compositor\nservice\n", + ); + let apps = |m: &Manifest, row: &str| { + views(m.program(row).unwrap()).into_iter().find(|v| v.1 == package::DIR).map(|v| (v.2, v.3)) + }; + assert_eq!(apps(&m, "pkg"), Some(("apps".into(), true))); + assert_eq!(apps(&m, "shell"), Some(("apps".into(), false))); + assert_eq!(apps(&m, "compositor"), Some(("apps".into(), false))); + let but_apps = |row: &str| views(m.program(row).unwrap()).into_iter().filter(|v| v.1 != package::DIR).collect::>(); + assert_eq!(but_apps("pkg"), but_apps("shell")); + // Named like the installer and declaring nothing. + let named = parse("program pkg /system/bin/pkg\n"); + assert_eq!(apps(&named, "pkg"), Some(("apps".into(), false))); + // Even declaring it, a package's own directory stays read-only. + let package = Program { installs: true, ..m.app_row("gbae", "/apps/gbae/gbae").unwrap() }; + assert!(views(&package).iter().all(|v| !v.1.starts_with(package::DIR) || !v.3)); + } + #[test] fn the_same_manifest_renders_to_the_same_bytes() { assert_eq!(render(&sample()), render(&sample())); diff --git a/lib/manifest/src/package.rs b/lib/manifest/src/package.rs index 278b6543b9c..403c247d1bb 100644 --- a/lib/manifest/src/package.rs +++ b/lib/manifest/src/package.rs @@ -4,8 +4,8 @@ //! to resolve a launch, so the format lives beside [`crate::Manifest`] for the //! same reason: one renderer, one parser, one round-trip test. //! -//! **Nothing here is a grant.** `/apps` is writable to every row the image -//! declares, so a manifest is a peer's claim about itself: it says which binary +//! **Nothing here is a grant.** A package is what an archive carried, so a +//! manifest is the package's claim about itself: it says which binary //! *of its own directory* a launch starts. A device, a right and another //! package's binary have no spelling in this file at all. //! diff --git a/system/pkg/src/main.rs b/system/pkg/src/main.rs index 126ce12a3c0..a1d2634d4ab 100644 --- a/system/pkg/src/main.rs +++ b/system/pkg/src/main.rs @@ -1,8 +1,9 @@ -//! `/system/bin/pkg` — the installer, and an ordinary program. +//! `/system/bin/pkg` — the installer. //! -//! **It holds no authority a shell does not.** It claims no device, receives no -//! service and is endowed nothing; it writes under `/apps` because `/apps` is -//! writable to it. What it does is verify an archive against the release's own +//! **Its one authority is `/apps` read-write**, which its row's view holds and +//! no other row's does (`toyos_manifest::Program::installs`): launched, it +//! installs and removes; spawned as a helper it holds its parent's view, and +//! lists. What it does is verify an archive against the release's own //! `SHA256SUMS`, ask, unpack, and write the `manifest.toml` that records which //! binary the directory launches. //! @@ -71,7 +72,7 @@ fn install(file: &Path, assume_yes: bool) -> Result<(), String> { .map_err(|e| format!("pkg: cannot read {}: {e}", beside.display()))?; let want = sums::digest_for(&sums_text, &name)?; - let mut apps = apps()?; + let mut apps = writable_apps()?; let room = apps.room().map_err(|e| format!("pkg: {} answers no room: {e:?}", package::DIR))?; let (planner, got) = survey(file, Planner::new(&name, room.free, room.unit))?; if got != want { @@ -101,11 +102,17 @@ fn install(file: &Path, assume_yes: bool) -> Result<(), String> { /// `/apps`'s own capability, for what std has no word for: the room on its /// volume, and a sync of the whole volume that answers for every file in it. -fn apps() -> Result { +/// Refused where it is read-only, which it is to every row but the +/// installer's. +fn writable_apps() -> Result { let names = toyos::endow::namespace() .ok_or_else(|| String::from("pkg: this process holds no directory capabilities"))?; let name = format!("{}{}", toyos::fs::CAPABILITY_PREFIX, package::DIR); - toyos::fs::Dir::connect(names, &name).map_err(|e| format!("pkg: cannot reach {}: {e:?}", package::DIR)) + let apps = toyos::fs::Dir::connect(names, &name).map_err(|e| format!("pkg: cannot reach {}: {e:?}", package::DIR))?; + match apps.writable() { + true => Ok(apps), + false => Err(format!("pkg: {} is read-only to this process; run it with `launch pkg`", package::DIR)), + } } /// The first read: every header through `planner`, and the whole file's @@ -259,6 +266,7 @@ fn remove(name: &str) -> Result<(), String> { if package::package_of(&format!("{}/x", Package::dir(name))) != Some(name) { return Err(format!("pkg: {name:?} is not a package name")); } + writable_apps()?; let dir = Package::dir(name); let manifest = Package::path(name); let installed = fs::read_to_string(&manifest).ok().and_then(|t| Package::parse(&t).ok()); diff --git a/tests/guest/rust-tests/src/bin/app_view.rs b/tests/guest/rust-tests/src/bin/app_view.rs index 222caed8c7c..a99e4b934e6 100644 --- a/tests/guest/rust-tests/src/bin/app_view.rs +++ b/tests/guest/rust-tests/src/bin/app_view.rs @@ -24,6 +24,12 @@ //! Every arm runs, so one run names each one that is red. The job then holds //! the package to what it installed. //! +//! The job writes `/apps` because test-runner's row is this image's installer +//! (`installs = true`). The shell's row is not: a shell launched in the login +//! session redirects the same line into `/home`, which writes, and into the +//! package, which the file server refuses as read-only. Both are DATA's, one +//! volume and one server, and differ only in the grant. +//! //! Then it grants the package a folder of the home, `/home/toy/Games` holding //! a ROM, through `/system/bin/grants`: refused `Apps/appview` by name, from //! the login session test-runner, its login authority, opened for its jobs. Granted it there, the package run as `game` browses @@ -63,6 +69,12 @@ const TEMPORARY: &str = "/tmp/apps/appview"; const MACHINE_TMP_FILE: &str = "/tmp/app_view_machine"; const OTHER_TMP_FILE: &str = "/tmp/apps/other/kept"; const TEMPORARY_KEPT: &[u8] = b"what the app wrote in its own /tmp"; +/// What the shell's line copies, and where its redirects go. +const SHELL_SOURCE: &str = "/system/etc/system.manifest"; +const SHELL_HOME_FILE: &str = "/home/toy/app_view_shell"; +const SHELL_PACKAGE_FILE: &str = "/apps/appview/planted"; +/// What std says of a file server's `ReadOnly`, which the shell prints. +const READ_ONLY: &str = "the directory is read-only to this process"; const APP: &str = "app"; const GAME: &str = "game"; const GAMES: &str = "/home/toy/Games"; @@ -143,11 +155,14 @@ fn job() { Ok(bytes) if bytes == TEMPORARY_KEPT => println!(" the app's /tmp write is in {TEMPORARY}"), other => red.push(format!("what the app wrote in its /tmp is not in {TEMPORARY}/kept: {other:?}")), } + shell_writes(&mut red); granted(&mut red); for dir in [PACKAGE, ROW_PACKAGE, "/apps/other", "/home/toy/Apps/other", HOME, GAMES, TEMPORARY, "/tmp/apps/other"] { let _ = fs::remove_dir_all(dir); } - let _ = fs::remove_file(MACHINE_TMP_FILE); + for file in [MACHINE_TMP_FILE, SHELL_HOME_FILE] { + let _ = fs::remove_file(file); + } if !red.is_empty() { panic!("app_view: {red:#?}"); } @@ -281,6 +296,24 @@ fn in_login(line: &str) -> std::process::Output { Command::new("/system/bin/shell").independent().args(["-c", line]).current_dir("/").output().expect("launch a shell") } +/// A shell's redirect writes `/home` and is refused as read-only in a package. +fn shell_writes(red: &mut Vec) { + let _ = fs::remove_file(SHELL_HOME_FILE); + let wrote = in_login(&format!("/system/bin/cat {SHELL_SOURCE} > {SHELL_HOME_FILE}")); + match fs::metadata(SHELL_HOME_FILE) { + Ok(file) if file.len() > 0 && wrote.status.success() => println!(" a shell's redirect into /home: written"), + other => red.push(format!("a shell's redirect into /home wrote {other:?}: {wrote:?}")), + } + let refused = in_login(&format!("/system/bin/cat {SHELL_SOURCE} > {SHELL_PACKAGE_FILE}")); + let said = String::from_utf8_lossy(&refused.stderr).into_owned(); + match fs::symlink_metadata(SHELL_PACKAGE_FILE) { + Err(e) if e.kind() == ErrorKind::NotFound && !refused.status.success() && said.contains(READ_ONLY) => { + println!(" a shell's redirect into a package: refused ({})", said.trim()) + } + other => red.push(format!("a shell's redirect into a package left {other:?}: {refused:?}")), + } +} + /// What the package saw as `game`: its working directory, the ROMs gbae's /// menu lists there, and whether its save beside the first was written. fn played(red: &mut Vec, when: &str) -> Option { diff --git a/tests/guest/rust-tests/src/bin/hosted_clang_hello.rs b/tests/guest/rust-tests/src/bin/hosted_clang_hello.rs index cb79eb15d23..8d2d34b25d2 100644 --- a/tests/guest/rust-tests/src/bin/hosted_clang_hello.rs +++ b/tests/guest/rust-tests/src/bin/hosted_clang_hello.rs @@ -1,4 +1,4 @@ -//! clang built for ToyOS, installed by `pkg`, compiles a C program here, and +//! clang built for ToyOS, installed by a launched `pkg`, compiles a C program here, and //! its driver links one, starting `ld.lld` as a child; the program runs, and //! what each wrote is the host's clang's bytes. //! @@ -7,6 +7,7 @@ //! `src/hello.c`, and what the host's clang made of it at `host/hello.o` and //! `host/a.out`. +use std::os::toyos::process::CommandExt; use std::path::{Path, PathBuf}; use std::process::Command; @@ -21,8 +22,10 @@ fn main() { let mut args = std::env::args().skip(1); let staged = PathBuf::from(args.next().expect("the staged directory, as the first argument")); let package = staged.join(args.next().expect("the package's file name, as the second argument")); + // Launched, and no helper: `/apps` is read-write in the installer's own + // view and read-only in this job's. let mut install = Command::new("/system/bin/pkg"); - install.arg("install").arg(&package).arg("--yes"); + install.independent().arg("install").arg(&package).arg("--yes"); run(install, "pkg install"); let out = Path::new(OUT); diff --git a/tests/images/hostedclangcase.toml b/tests/images/hostedclangcase.toml index 3e2752141b0..f1661221650 100644 --- a/tests/images/hostedclangcase.toml +++ b/tests/images/hostedclangcase.toml @@ -16,10 +16,15 @@ holds = ["console-input"] receives = ["log-wire"] restart = true +# `starts` because the job launches the installer: `/apps` is read-write in +# that row's view alone. [programs.test-runner] +starts = ["pkg"] -# The installer the job runs, as `images/system.toml` declares it. +# The installer the job launches, as `images/system.toml` declares it. [programs.pkg] +state = true +installs = true # The block service, the NVMe driver for the disk DATA is on, and the file # servers. diff --git a/tests/images/proctreecase.toml b/tests/images/proctreecase.toml index e2d8937e7f9..271d3374f75 100644 --- a/tests/images/proctreecase.toml +++ b/tests/images/proctreecase.toml @@ -10,6 +10,8 @@ # And `app_view`: test-runner's row lists `/apps`, so a job launches the # package it installed under the image's `[apps]` row and the view an # installed package is minted, and is refused one named after the `shell` row. +# The job writes its packages under `/apps` itself and rewrites one, which no +# installer does, so test-runner's row is this image's installer. # It grants that package a folder through `grants`, which test-runner's row # and the shell's list, in the login session test-runner opens for its jobs: # test-runner is a login authority, so its jobs launch in that session and @@ -43,6 +45,7 @@ restart = true syscap = ["dup", "roster"] starts = ["toybox", "shell", "grants", "/apps"] login = true +installs = true # `roster`, which a child the job spawns itself never holds: a child holding # it ran under this row, and `launch_toctou` asks which bytes that child was.