Skip to content

fix(driver): stage the WSL ROCDXG package in a root-only directory - #975

Open
rominf wants to merge 8 commits into
mainfrom
fix/rocdxg-root-only-staging
Open

rominf wants to merge 8 commits into
mainfrom
fix/rocdxg-root-only-staging

Conversation

@rominf

@rominf rominf commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

On WSL2, rocm install driver downloaded the ROCDXG .deb to a fixed, predictable path in /tmp: /tmp/rocdxg-roct_<version>_amd64.deb. Any local user can write to that directory. The plan checked the file's SHA-256 there and then ran sudo apt-get install on the same path, so another local user could create or replace the file between the digest check and the install. The package whose maintainer scripts then ran as root was not necessarily the one that passed the check. The manual steps in docs/wsl.md had the same layout, and also ran sha256sum -c and sudo apt install as separate lines, so a pasted block printed FAILED on a mismatch and installed the package anyway.

Fix

The WSL ROCDXG plan (apps/rocm/src/driver_plan/rocdxg.rs) now:

  1. Runs install -d -m 0755 -o root -g root on /var/cache/rocm-cli and /var/cache/rocm-cli/rocdxg on every run. This also resets the owner and mode of either directory if it already exists. The parent matters too: whoever can write it could rename the staging directory and put their own in its place.
  2. Downloads the package without sudo into a private mktemp -d directory (unpredictable name, mode 0700, removed on exit), then copies it into the root-only directory with sudo install -m 0644. This is a single shell line, because each plan step runs as its own sh -c.
  3. Checks the pinned or supplied digest against that root-owned copy.
  4. Runs apt-get install on that same file, then removes it.

The executor stops at the first failing step. A package rejected by the digest check or by apt-get therefore stays in the root-only directory, out of other users' reach, until the next run of the same version replaces it. When the CLI already runs as root, the plan leaves out sudo as before. Bare metal and native Windows are unchanged.

User-visible changes:

  • Plan output. The rocm install driver --dry-run and review plan on WSL shows the new steps.
  • /var/cache/rocm-cli. It is reserved for root-owned driver staging. Each WSL driver install resets it and its rocdxg subdirectory to root:root 0755, leaving their contents alone.
  • Fix notes. The fix-wsl-3-rocdxg-missing notes in rocm fix and rocm diagnose now say the digest is checked on the root-placed copy that gets installed. The rocm-doctor eval fixture that records this rocm fix output is regenerated to match.
  • Docs. docs/wsl.md describes the root-only staging. Its manual steps follow the same layout, as one && chain from the download to ldconfig inside a subshell that removes the private download directory on exit. A failed download stops the block before the digest check, so a copy an earlier run left staged is never checked or reinstalled, and the block's exit status is the chain's, so a failed download, check or install does not report success. docs/release-trust.md, docs/testing.md and the docs/architecture.md row for driver_plan/rocdxg.rs are updated too.

Tests

  • wsl_rocdxg_plan_never_installs_from_a_path_another_user_can_write (unit). For both the sudo plan and the already-root plan, it checks that:

    • no command uses /tmp, and the staged package sits under an allowlisted root-only system directory (/var/cache/), so moving it to another world-writable location such as /dev/shm or /var/tmp also fails;
    • the exact install -d command for the staging directory and its parent comes first;
    • the download goes through a private mktemp -d, and only a root install places the package;
    • the digest is checked on the exact path apt-get installs;
    • the staged package is removed with the plan's own escalation (sudo rm -f, or rm -f when already root), because the file is root-owned and an unprivileged rm would stop the plan before ldconfig;
    • the steps run in that order.

    It also checks the rendered --dry-run plan.

  • wsl_rocdxg_generated_steps_install_exactly_the_verified_file (unit, Unix). It runs every generated step, each in its own sh -c as the CLI does, against stand-in sudo, curl, install, apt-get and ldconfig. The curl stand-in fails if it runs under sudo or writes anywhere other than a 0700 directory directly under $TMPDIR. Both staging directories start at 0777, so the 0755 the test asserts can only come from the plan resetting them. The test covers:

    • a genuine install;
    • a tampered download, which stops the plan before apt-get;
    • an apt-get failure, which leaves the package staged;
    • a later run, which replaces that leftover;
    • cleanup of the private and staged copies;
    • the 0755 directory modes.
  • wsl_doc_manual_steps_stop_before_the_check_when_the_download_fails (unit, Unix). It extracts the manual block from docs/wsl.md with include_str! and runs it against stand-ins. With a good copy already staged and a failing download, nothing is installed and the block exits non-zero; a failed install also exits non-zero; a good download installs once and exits zero; the private download directory is gone after each.

  • Wording tests for the rocm fix and rocm diagnose notes. They only pin the text, and each one's comment names the test above as the one that proves the behaviour.

  • Scenario @id:driver-install-wsl-dry-run-plan (driver-install-01) gains the step "the driver plan installs only a package no other local user could have replaced". It checks the same layout on the real rocm install driver --dry-run output, including that the package is staged under /var/cache/. The scenario is tagged @requires-wsl, so it runs on the E2E tests (Strix Halo, WSL2) lane rather than in default CI.

Each new unit test was shown to fail when the code it covers is broken. Seven mutations each turned at least one of them red:

  • the install path put back to /tmp
  • the staging directory moved to /dev/shm
  • the parent dropped from the install -d step (each of the two tests catches this on its own)
  • curl run under sudo
  • the cleanup step removed
  • sudo dropped from the cleanup step
  • the whole plan restored to main (the tests no longer compile)

The docs test fails against the earlier unchained manual block, against a chained block that ends in a separate rm -rf line (exit status always 0), and against a block that swallows only the install's failure.

The e2e step was not mutated, because it needs a WSL host. The swap itself was not staged on a real WSL host. The unit tests prove the layout and that the checked file is the installed file, not a timed race.

Verified locally (Linux, not WSL)

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings and cargo clippy -p e2e-cucumber --test e2e -- -D warnings
  • cargo test -p rocm --bin rocm rocdxg and cargo test -p rocm --bin rocm wsl_doc, on the tree with main merged in, and cargo test -p rocm-core rocdxg_missing_note
  • cargo xtask eval-fixtures --check, cargo xtask check-architecture-doc and cargo xtask check-module-size
  • cargo test --workspace --all-targets --no-fail-fast, run with TMPDIR on an exec filesystem because this host's /tmp is noexec. The only failures were the eval-fixture check (since fixed and re-run green) and three tests in files this change does not touch: two build_metadata tests that create scratch git commits, which this host's global commit signing rejects, and service_control::stop_of_a_container_engine_is_unconfirmed_when_the_engine_stop_fails, which depends on the host's docker.

Not verified

  • @id:driver-install-wsl-dry-run-plan was not run locally, because no WSL host was available. The WSL2 CI lane runs it.
  • A real rocm install driver --yes on WSL2 was not run.
  • cargo xtask smoke was not run to completion. It stops at the bubblewrap sandbox step, which this host can't run.
  • The owner reset (-o root -g root) is pinned as text only. The stand-in run cannot be root, so it proves the mode reset but not the ownership change.

Out of scope

rocm uninstall doesn't mention /var/cache/rocm-cli/. After a successful install that directory is empty, but a rejected package can stay there until the next run of the same version. docs/wsl.md gives the one-line cleanup. Teaching uninstall about root-owned driver leftovers is a separate change. Two installs of the same version racing on the fixed staged name are a non-goal too: only root can write that directory, so both racers would already have root.


  • If this PR fixes a bug, searched tests/e2e-cucumber/expectations.toml for the fixed ticket ID and removed/narrowed any now-stale xfail rows. (No ticket ID; no xfail row covers the ROCDXG plan.)
  • If this PR adds a new subcommand or subsystem, its domain implementation lives in its own file per docs/architecture.md. (No new subcommand or subsystem.)
  • If this PR adds, renames or removes a production source file, docs/architecture.md has the matching entry, and the prose of any entry whose file changed role still describes it. (No files added or removed; the driver_plan/rocdxg.rs row now describes the root-only staging.)
  • Every new or changed user-facing message was read against the code path that runs after it, and its test asserts the resulting state — not only the wording — per AGENTS.md §3. (The two note-wording tests name wsl_rocdxg_generated_steps_install_exactly_the_verified_file, which executes the plan.)

On WSL2, `rocm install driver` downloaded the ROCDXG .deb to a fixed,
predictable name in the world-writable /tmp, checked its SHA-256 there,
then ran `sudo apt-get install` on that same path. Another local user
could create or replace that file between the digest check and the
install, so the package whose maintainer scripts run as root was not
necessarily the one that was checked.

The plan now makes /var/cache/rocm-cli/rocdxg root-owned and 0755 on
every run, downloads without sudo into a private `mktemp -d` directory
that is removed on exit, copies the file into the root-only directory
with `sudo install -m 0644`, checks the digest of that root-owned copy,
installs that same file and removes it afterwards. A package rejected
by the check or by apt-get stays in the root-only directory until the
next run of the same version replaces it.

New unit tests check the plan text for both the sudo and the
already-root plan, and run every generated Execute step, each in its
own `sh -c`, against stand-in sudo, curl, install and apt-get. The WSL
dry-run scenario gains a step asserting the same layout on the rendered
plan. The `rocm fix` and `rocm diagnose` notes and the WSL,
release-trust and testing docs, including the manual steps, now
describe the root-only staging.

Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
…in the staging location

The manual WSL steps ran `sha256sum -c` and `sudo apt install` as
separate lines, so a pasted block printed FAILED on a digest mismatch
and then installed the rejected package as root anyway. The check, the
install, the removal and `ldconfig` are now chained with `&&`, and the
prose says the copy that is checked is the root-owned one.

The plan-text test now asserts the staged package sits under an
allowlisted root-only system directory rather than only "not /tmp",
since /dev/shm or /var/tmp would pass that check while being just as
world-writable; the WSL dry-run scenario asserts the same. It also
pins the removal step to the plan's escalation, because the staged
file is root-owned and an unprivileged `rm` would fail and stop the
plan before `ldconfig`. A comment records that /var/cache/rocm-cli is
reserved for root-owned driver staging, since the plan resets its
owner and mode on every run.

Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
The plan runs `install -d -m 0755 -o root -g root` on both
/var/cache/rocm-cli and its rocdxg subdirectory, because whoever can
write the parent can rename the staging directory away and put their
own in its place. Dropping the parent from that command left every test
green: the plan-text test only matched a prefix and the staging
directory, and the stand-in run let `install -d` create both
directories under the default umask, which already gives 0755.

The plan-text test now pins the whole command, and the stand-in run
starts both directories at 0777 so the 0755 it asserts can only come
from the plan resetting them. Each assertion fails on its own when the
parent is dropped.

Also give ROCDXG_STAGING_DIR its own doc comment (it sat on the parent
constant), stop the module header claiming the plan's behaviour is
unchanged since the relocation, and narrow the comment on the reset to
what `install -d` actually resets: the two directories, not their
contents.

Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
The `fix-wsl-3-rocdxg-missing` note now says the digest is checked on
the root-placed copy that gets installed. The rocm-doctor eval fixture
records `rocm fix` output for a WSL host and still held the old
wording, so `cargo xtask eval-fixtures --check` failed. Regenerated
with `cargo xtask eval-fixtures`; only the two note strings change.

Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
@rominf
rominf force-pushed the fix/rocdxg-root-only-staging branch from 75b204f to ec42a59 Compare November 16, 2026 19:10
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor
Security scan found no critical or high findings on lines changed by this pull request

View the security scan run for complete reports.

“New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta.

@rominf
rominf marked this pull request as ready for review November 17, 2026 11:58
@rominf
rominf requested a review from a team as a code owner November 17, 2026 11:58
@rominf
rominf requested a review from fredespi November 17, 2026 11:58

@juhovainio juhovainio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing here is a security or correctness blocker: the checked file is now the installed file, the staging directory and its parent are reset to root-only on every run, and the test runs each generated step separately with a curl shim that rejects sudo and non-0700 download dirs. CI is green. I'm requesting changes only for one docs fix that is the same "pasted block keeps going after a failure" problem this PR fixes a few lines lower, plus a couple of notes.

Worth fixing

  • In the manual steps in docs/wsl.md, the curl, sudo install and rm -rf lines are not chained, while the check/install/rm/ldconfig lines below them are. If the download fails, a pasted block carries on to sudo install on a missing file and then runs sha256sum -c against whatever an earlier run left in the staging directory. The digest still gates apt, so it is not a hole, but chain the download/copy lines with && as well (see the inline comment).

Non-blocking

  • The root:root owner reset (install -d -m 0755 -o root -g root) is only pinned by string match: the test stand-in drops -o/-g, so ownership is not actually exercised. The PR body discloses this; fine to leave, but worth a comment next to the assertion saying so.

For the author to decide

  • A package that fails the check or that apt fails to install stays in /var/cache/rocm-cli/rocdxg until the next same-version run, and rocm uninstall doesn't know about the directory. The PR discloses this and the docs give a one-line cleanup. A trap or || cleanup step on failure would be the alternative if you want it self-cleaning.
  • The staged file keeps a fixed, versioned name rather than a per-run unique one. That's sound given the directory is root-only and reset each run.

I did not re-run the mutation list or the unit tests locally; this is from reading the diff plus the CI results.

Comment thread docs/wsl.md Outdated
d="$(mktemp -d)"
curl -L --fail -o "$d/${ROCDXG_DEB}" \
"https://github.com/ROCm/librocdxg/releases/download/v${ROCDXG_VERSION}/${ROCDXG_DEB}"
sudo install -m 0644 "$d/${ROCDXG_DEB}" "${ROCDXG_STAGED}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chain the curl, this sudo install and the rm -rf "$d" cleanup with &&, as the check/install lines below are. As written, a failed download stops nothing in a pasted block: it falls through to sudo install on a missing file, and sha256sum -c then checks whatever a previous run left staged.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bcfe9b1 and 152b497. The whole block, from mktemp -d through ldconfig, is now one && chain, so a failed download stops before sha256sum -c and a copy an earlier run left staged is never checked or reinstalled. The chain runs in a subshell with trap 'rm -rf "$d"' EXIT, as the generated plan does, so the private directory is removed on every path and the block's exit status is the chain's: a failed download, check or install no longer reports success.

The new test wsl_doc_manual_steps_stop_before_the_check_when_the_download_fails extracts this block from docs/wsl.md with include_str! and runs it against stand-ins. With a good copy already staged and a failing download, nothing is installed and the block exits non-zero. A failed install also exits non-zero, and a good download installs once. It fails against the previous block, and against a block that swallows only the install's failure.

@juhovainio juhovainio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atom# Review — needs work

Full review of the whole change (base 778c970f…head ec42a59d). No ticket named; the PR's own checklist states there is none (purely a direct fix with no referenced issue).

Blocking

  • docs/wsl.md's manual download/stage steps are not chained, unlike the check/install/rm/ldconfig block right below them — docs/wsl.md:112-116
    Read directly from the file: d="$(mktemp -d)", the curl download, the sudo install copy into the root-only directory, and rm -rf "$d" are four separate statements with no && between them, while the following block (sha256sum -c - / apt install / rm -f / ldconfig) is correctly chained with &&. If curl fails, a pasted block falls through to sudo install on a missing source (also fails, noisily) and rm -rf "$d" (harmless), then reaches the digest check. On a first run this still fails closed since there's nothing staged yet to check. But if a .deb for the same version is already staged from an earlier successful run, the check re-passes against that leftover and the script quietly reinstalls it instead of surfacing that the download failed. The digest still gates apt install, so this is not the TOCTOU race the PR closes a few lines below — but it is the identical "pasted block keeps going after a failure" defect class the rest of this same PR (and the generated plan in apps/rocm/src/driver_plan/rocdxg.rs:374-379, which chains the equivalent download+copy line with && and a trap 'rm -rf "$d"' EXIT) is built to prevent.
    Confidence 85 · mechanical · Fix: chain these lines with && (and consider a trap for the private dir cleanup) to match the generated plan and the block beneath them.

Non-blocking

None

Decisions for the author

  • Ownership reset (-o root -g root) is pinned only as a string, not exercised by root-owned behavior — answered-by-intent
    PR body, "Not verified": "The owner reset (-o root -g root) is pinned as text only... The stand-in run cannot be root, so it proves the mode reset but not the ownership change." Would otherwise be a test-strength finding (the executable test's install stand-in strips -o/-g before delegating to the real install). The disclosure is accurate and the mode-reset half is genuinely exercised (0777→0755 is asserted). Confirm this is still an accepted gap rather than something to close before merge.
  • A package rejected by the digest check or by apt-get stays in /var/cache/rocm-cli/rocdxg/ until the next run of the same version; rocm uninstall does not know about the directory — answered-by-intent
    PR body, "Out of scope": "a rejected package can stay there until the next run of the same version... docs/wsl.md gives the one-line cleanup. Teaching uninstall about root-owned driver leftovers is a separate change." A trap/|| self-cleaning step would be the alternative; the current choice (manual sudo rm -f .../*.deb, documented) is reasonable given the directory is root-only and inert between runs.
  • Fixed, version-keyed filename in the staging directory rather than a per-run unique name — tradeoff
    A unique name per run would remove any chance of two concurrent installs of the same version colliding on the same path; the current choice is simpler and is safe specifically because the directory is root-only and its permissions/ownership are reset on every run, so the fixed name costs nothing against the TOCTOU threat model this PR addresses. Worth the author confirming concurrent-install collision is an accepted non-goal.

Positive signals

  • apps/rocm/src/driver_plan/rocdxg.rs:374-379 chains the private download and the privileged copy into one &&-joined sh -c line with a trap 'rm -rf "$d"' EXIT, so the private mktemp -d directory is cleaned up even on a curl failure mid-step — exactly the robustness the doc's manual steps (above) are missing.
  • wsl_rocdxg_generated_steps_install_exactly_the_verified_file (apps/rocm/src/driver_plan/rocdxg.rs:1002-1197) actually executes every generated Execute-phase step through sh -c against sudo/curl/install/apt-get/ldconfig stand-ins — including a curl stand-in that fails the test if invoked under sudo or asked to write outside a private 0700 directory — rather than asserting on substrings of the plan text. This is the stronger of the two kinds of test this PR adds, and it would fail if, for example, the digest-check target were quietly pointed back at the private download directory instead of the staged copy.

Deployment notes

  • /var/cache/rocm-cli and its rocdxg subdirectory are now reserved, root-owned staging paths that this plan resets (owner and mode, not contents) on every WSL driver install; nothing else should write there.
  • CI for this PR (head ec42a59d) is fully green across the required jobs (clippy/test, E2E consolidated reports for Linux/Windows/WSL2/MI300X, security scans); no failing or pending required check at review time.

What this covered

Every file in the diff, read completely at pr-975-head via git show (never checked out): apps/rocm/src/driver_plan.rs, apps/rocm/src/driver_plan/rocdxg.rs (full file, including its test module), crates/rocm-core/src/diagnose/wsl.rs, crates/rocm-core/src/fix/catalog.rs, docs/architecture.md, docs/release-trust.md, docs/testing.md, docs/wsl.md (full file), skills/rocm-doctor/evals/fixtures/rocm-no-vendor-wsl-host-gpu-hidden-asks-which-gpu/replies.json, tests/e2e-cucumber/features/driver_install.feature, tests/e2e-cucumber/tests/e2e/driver_steps.rs; plus apps/rocm/src/driver_install.rs (not itself changed) to verify the executor actually stops at the first failing command rather than trusting the code comment that says so. Diff reviewed: 778c970f…ec42a59d.

Two of four code-pass groups (core driver_plan/rocdxg.rs logic; the diagnose/fix::catalog note wording) ran as independent background fan-out workers and returned clean (no findings). The other two groups (the docs bundle including docs/wsl.md's shell chaining; the e2e/unit test and fixture coverage) could not get a worker slot — the environment's concurrent-subagent limit was already saturated by unrelated sessions, and a retry also failed — so, per this method's rule for a failed spawn, I ran those two passes myself in this same context rather than silently absorbing the loss; they are not independent passes, and the blocking finding above came from one of them. A short design-review pass (concurrent-install collision, fixed-vs-unique filename, whether the opted-out-verification path still stages correctly) ran inline rather than as separate workers; its outputs are the three items under Decisions for the author. History and prior-review passes were minimal: git log on rocdxg.rs shows only the prior module-split refactor (#844), no rocdxg-specific history to review; no separate search of prior PR review comments on these files was performed. CI status pulled live via the GitHub API rather than assumed. Not reconciled against the PR's existing review thread during the blind pass; that thread (raising the same docs/wsl.md chaining point, among other non-blocking notes) was read only afterward, as this method requires, and is consistent with the independently-derived finding above.


🤖 Automated by an AI agent

Comment thread docs/wsl.md Outdated
Comment on lines +112 to +116
d="$(mktemp -d)"
curl -L --fail -o "$d/${ROCDXG_DEB}" \
"https://github.com/ROCm/librocdxg/releases/download/v${ROCDXG_VERSION}/${ROCDXG_DEB}"
sudo install -m 0644 "$d/${ROCDXG_DEB}" "${ROCDXG_STAGED}"
rm -rf "$d"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (mechanical): These five lines (mktemp, curl, sudo install, rm -rf) are not chained with && to each other or to the sha256sum -c - block that follows, unlike that block's own internal chaining. Verified directly from the file text (not from any other review): if curl fails, the pasted script falls through to sudo install on a missing source (that also fails, noisily), then unconditionally rm -rf "$d", then starts the && chain at the digest check. On a first-time run this still fails closed (no file yet to check), but if a previously-verified .deb for the same version is already staged from an earlier successful run, the check re-passes against that leftover and the script proceeds to reinstall it — silently papering over the fact that this run's download never happened. The digest still gates apt install, so this isn't the TOCTOU hole the PR fixes a few lines below, but it's the same "pasted block keeps going after a failure" defect class this PR's own commands/tests guard against elsewhere (the generated plan's equivalent step in apps/rocm/src/driver_plan/rocdxg.rs chains download+copy with && and a trap ... EXIT). Suggest chaining these lines with && (and/or adding a trap 'rm -rf "$d"' EXIT for the private dir) to match the generated plan and the chained block below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bcfe9b1 and 152b497. This is the same change as in the thread above. The download, the copy into the root-only directory, the check, the install, the removal and ldconfig are one && chain inside a subshell with trap 'rm -rf "$d"' EXIT. A failed curl therefore stops the block before the digest check, so a leftover staged copy cannot pass it and be reinstalled. wsl_doc_manual_steps_stop_before_the_check_when_the_download_fails runs the documented block and covers exactly that case: a good copy already staged plus a failed download means no install and a non-zero exit.

@rominf
rominf requested a review from juhovainio November 17, 2026 13:37
The manual steps chained the digest check, install, removal and
ldconfig, but not the download and the copy into the root-only
directory before them. Pasted into a shell, a failed download carried
on to the check, and a copy an earlier run had left staged then passed
it and was reinstalled as though this run had downloaded it.

Every step up to ldconfig is now one `&&` chain, and the private
download directory is removed by a last line that runs either way.
A new test runs the documented block against stand-ins: with a good
copy left staged and a download that fails, nothing is installed and
the download directory is gone; a good download installs once. It
fails against the previous block.

Also note beside the plan-text assertion that the root:root owner
reset is pinned there only, since the stand-in run cannot be root.

Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
The chained manual steps ended with a separate `rm -rf "$d"` line, so
the block's exit status was always the cleanup's, and a failed
download, digest check or install reported success to anything that
ran the block as a script.

The chain now runs in a subshell that removes the private download
directory from an EXIT trap, as the generated plan does, so the block's
status is the chain's. The test asserts that status for a failed
download, a failed install and a good run, and the private directory's
removal on each; it fails against the previous block, and against a
block that swallows only the install's failure.

Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
@rominf

rominf commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks for both reviews. The blocking point (the unchained download in the docs/wsl.md manual steps) is fixed in bcfe9b1 and 152b497; details are in the inline threads. On the other items:

  • Owner reset pinned only as a string. bcfe9b1 adds a comment beside that assertion in wsl_rocdxg_plan_never_installs_from_a_path_another_user_can_write. It says the -o root -g root reset is pinned there only, because the test does not run as root and the stand-in install drops -o/-g, so the stand-in run proves the mode reset (0777 to 0755) and not the ownership. That remains an accepted gap. Closing it needs a lane that runs as root.
  • Rejected package left in /var/cache/rocm-cli/rocdxg. Kept as is. Each plan step is its own sh -c and the executor stops at the first failing step, so self-cleaning on failure would mean folding the check and install into one long line. That would give up the separately reviewable digest-check step. The leftover is root-only, the next same-version run replaces it, and docs/wsl.md gives the cleanup. Teaching rocm uninstall about that directory stays out of scope, as the PR body says.
  • Fixed, versioned file name. Kept. Only root can write the directory, so two installs racing on the same name need two sudo-capable users running the install at once. Either of them can already act as root, so a per-run name would not protect anything here. Concurrent installs of the same version are a non-goal.

main is merged in (7d14870) rather than rebased, since this PR has reviews.

The test embedded docs/wsl.md with `include_str!`, which put the doc
under the embedded-data ASCII contract, and its licence header is not
ASCII. Read it from the repository at run time instead; `docs/` already
selects the rocm tests in the pre-push hook.

Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>

@juhovainio juhovainio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — no blocking findings

Full review of the whole change at the current head (base bfff5216…head 16e5f64e), re-reviewed from scratch rather than narrowed, since the head advanced well past the last-reviewed commit (ec42a59d) through several commits including a merge of main. No ticket named; the PR's own checklist confirms there is none.

The previously-flagged blocking issue is fixed. docs/wsl.md's manual steps now wrap the whole download→check→install→cleanup sequence in one ( … ) subshell, every command &&-chained, with trap 'rm -rf "$d"' EXIT for the private download directory. Traced it line by line: a failed curl now stops the block before sha256sum -c runs, so a leftover from an earlier run is never silently rechecked and reinstalled, and the subshell's own exit status reflects the failure rather than reporting success. This matches the layout of the already-chained check/install/rm/ldconfig block below it.

Blocking

None

Non-blocking

  • PR description's test explanation is stale on one mechanism — wsl_doc_manual_steps_stop_before_the_check_when_the_download_fails is described in the PR body as extracting docs/wsl.md "with include_str!", but the final commit (test(driver): read docs/wsl.md at run time in the manual-steps test) replaced that with a runtime fs::read_to_string(...) call, specifically to keep the doc's non-ASCII copyright header out of the embedded-data ASCII contract. The behavior the description claims (extracting and executing the manual block against stand-ins) is still accurate — only the stated mechanism is now wrong, and the body wasn't re-read after that last commit.
    Confidence 85 · mechanical · Fix: a one-line wording update to the test's own bullet in the PR body.

Decisions for the author

  • Ownership reset (-o root -g root) is pinned only as a string, not exercised by root-owned behavior — answered-by-intent
    PR body, "Not verified": "The owner reset (-o root -g root) is pinned as text only... The stand-in run cannot be root, so it proves the mode reset but not the ownership change." Confirmed independently: the mode-reset half (0777→0755) is genuinely exercised by wsl_rocdxg_generated_steps_install_exactly_the_verified_file, and the exact -o root -g root substring is pinned by == equality (not contains) in the other test, so a dropped flag would still be caught even though real ownership-changing behavior isn't. Reasonable, disclosed gap.
  • A package rejected by the digest check or apt-get stays in /var/cache/rocm-cli/rocdxg/ until the next same-version run; rocm uninstall doesn't know about the directory — answered-by-intent
    PR body, "Out of scope": "a rejected package can stay there until the next run of the same version... Teaching uninstall about root-owned driver leftovers is a separate change." Reasonable given the directory is root-only and inert between runs.
  • Fixed, version-keyed filename rather than a per-run unique one — answered-by-intent
    PR body, "Out of scope": "Two installs of the same version racing on the fixed staged name are a non-goal too: only root can write that directory, so both racers would already have root." Sound given the directory's permissions are reset every run.

Positive signals

  • The TOCTOU fix is real, not just claimed: the digest check and apt-get install operate on the exact same root-owned path (ROCDXG_STAGING_DIR/deb name) in rocdxg.rs, and install unconditionally overwrites that destination before the check runs, so a stale or planted file there is never what gets checked.
  • wsl_rocdxg_generated_steps_install_exactly_the_verified_file actually executes every generated step through sh -c against stand-in sudo/curl/install/apt-get/ldconfig binaries, including a curl stand-in that fails if invoked under sudo or asked to write outside a private 0700 directory — this is a materially stronger test than asserting on substrings of the plan text, and would catch a regression that quietly pointed the digest check back at the private download directory.
  • Shell-injection guards on the interpolated version/digest strings (rocdxg_version_is_well_formed, sha256_digest_is_well_formed) are backed by an adversarial test exercising ;, &&, backticks, $(...), path traversal, and embedded newlines.

Deployment notes

  • /var/cache/rocm-cli and /var/cache/rocm-cli/rocdxg become reserved, root-owned staging paths that this plan resets (owner and mode, not contents) on every WSL driver install.
  • CI for this head (16e5f64e) was still mostly pending at review time — the clippy/test gate and the WSL2 E2E lane (which exercises the new --dry-run scenario step) had not yet reported a result. Not a failure, but not yet confirmed green either; worth a final check before merge.

What this covered

Every file in the diff (11 files, bfff5216…16e5f64e), read completely. Code passes were split by coupling: (1) apps/rocm/src/driver_plan.rs + driver_plan/rocdxg.rs (plus driver_install.rs for executor fail-stop semantics) ran as an independent background worker, clean; (2) crates/rocm-core/src/diagnose/wsl.rs + fix/catalog.rs + the eval fixture ran as a second independent background worker, clean. Two further groups — the docs bundle (docs/wsl.md, architecture.md, release-trust.md, testing.md) and the e2e test/feature files — could not get a worker slot (the environment's concurrent-subagent limit was already saturated), so, per this method's rule for a failed spawn, I ran both myself in this same context; they are not independent passes. The agent-instruction-adherence pass (against this repo's AGENTS.md) and a history pass (git log/blame on rocdxg.rs, docs/wsl.md, fix/catalog.rs — no relevant prior history beyond a routine module-split refactor) were also run inline for the same reason, both clean.

Midway through, the shared git clone this review started in was found checked out to an unrelated branch by a different concurrent session; every finding above was verified (or re-verified) via content-addressed git show <sha>:path / git diff <sha> <sha> against the exact base and head commits, which is immune to that, rather than trusted from working-tree reads.

CI status pulled live rather than assumed. Not reconciled against the PR's existing review thread during the blind passes; that thread (which raised the same docs/wsl.md chaining point this review independently re-verified as fixed, plus the same three disclosed items above) was read only afterward, as this method requires, and is consistent with what was independently found here.


🤖 Automated by an AI agent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants