Skip to content

uefi: roll back env changes when start_image fails - #164958

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Web4everyone32:uefi-env-rollback-on-spawn-failure
Oct 26, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Web4everyone32:uefi-env-rollback-on-spawn-failure

Conversation

@Web4everyone32

@Web4everyone32 Web4everyone32 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #164949

On UEFI, process::output applies the child's environment changes to the process-global UEFI environment and rolls them back after start_image. If start_image returned an error, the ? returned early before the rollback ran, so the child's variables (notably path, which later resolve_program lookups depend on) leaked permanently into the parent.

This keeps the start_image result, restores the environment unconditionally, and only then propagates the error.

Tested with ./x check library --target x86_64-unknown-uefi, ./x fmt --check and ./x test tidy. I have not run it on UEFI hardware or under QEMU.

cc @dvdhrm @nicholasbishop (UEFI target maintainers)

`process::output` on UEFI applies the child's environment changes to the
process-global UEFI environment and restores them after `start_image`.
If `start_image` returned an error, the `?` returned early before the
rollback ran, leaking the child's variables (e.g. `path`) into the parent.

Restore the environment unconditionally and only then propagate the error.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 26, 2026
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @Mark-Simulacrum (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 37 candidates
  • Random selection from ChrisDenton, JohnTitor, Mark-Simulacrum, aapoalas, thomcc

@joboet

joboet commented Oct 26, 2026

Copy link
Copy Markdown
Member

Thanks!
@bors r+

@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 60196fa has been approved by joboet

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 26, 2026
@joboet joboet assigned joboet and unassigned Mark-Simulacrum Oct 26, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 26, 2026
…n-spawn-failure, r=joboet

uefi: roll back env changes when `start_image` fails

Fixes rust-lang#164949

On UEFI, `process::output` applies the child's environment changes to the process-global UEFI environment and rolls them back after `start_image`. If `start_image` returned an error, the `?` returned early before the rollback ran, so the child's variables (notably `path`, which later `resolve_program` lookups depend on) leaked permanently into the parent.

This keeps the `start_image` result, restores the environment unconditionally, and only then propagates the error.

Tested with `./x check library --target x86_64-unknown-uefi`, `./x fmt --check` and `./x test tidy`. I have not run it on UEFI hardware or under QEMU.

cc @dvdhrm @nicholasbishop (UEFI target maintainers)
rust-bors Bot pushed a commit that referenced this pull request Oct 26, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #164955 (Use the updated buffer length in UEFI locate_handles)
 - #164958 (uefi: roll back env changes when `start_image` fails)
 - #164968 (thread_local::guard: update comments a bit)
 - #164303 (Remove the 'sub' method from 'At' and migrate to 'sub_raw')
 - #164674 (Use a NoSpan marker for region constraints without spans)
 - #164856 (Switch from `insta` to `expect-test` in bootstrap)
 - #164934 (Remove redundant vec and duplicate indexing in find_noop_landing_pads)
 - #164954 (Reduce `SpanData` use)
rust-bors Bot pushed a commit that referenced this pull request Oct 26, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #164955 (Use the updated buffer length in UEFI locate_handles)
 - #164958 (uefi: roll back env changes when `start_image` fails)
 - #164968 (thread_local::guard: update comments a bit)
 - #164303 (Remove the 'sub' method from 'At' and migrate to 'sub_raw')
 - #164674 (Use a NoSpan marker for region constraints without spans)
 - #164934 (Remove redundant vec and duplicate indexing in find_noop_landing_pads)
 - #164954 (Reduce `SpanData` use)
 - #164970 (`rust-analyzer` subtree update)
@rust-bors
rust-bors Bot merged commit 88a5415 into rust-lang:main Oct 26, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 26, 2026
Rollup merge of #164958 - Web4everyone32:uefi-env-rollback-on-spawn-failure, r=joboet

uefi: roll back env changes when `start_image` fails

Fixes #164949

On UEFI, `process::output` applies the child's environment changes to the process-global UEFI environment and rolls them back after `start_image`. If `start_image` returned an error, the `?` returned early before the rollback ran, so the child's variables (notably `path`, which later `resolve_program` lookups depend on) leaked permanently into the parent.

This keeps the `start_image` result, restores the environment unconditionally, and only then propagates the error.

Tested with `./x check library --target x86_64-unknown-uefi`, `./x fmt --check` and `./x test tidy`. I have not run it on UEFI hardware or under QEMU.

cc @dvdhrm @nicholasbishop (UEFI target maintainers)
ettolrach pushed a commit to ettolrach/rustfmt that referenced this pull request Nov 4, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#164955 (Use the updated buffer length in UEFI locate_handles)
 - rust-lang/rust#164958 (uefi: roll back env changes when `start_image` fails)
 - rust-lang/rust#164968 (thread_local::guard: update comments a bit)
 - rust-lang/rust#164303 (Remove the 'sub' method from 'At' and migrate to 'sub_raw')
 - rust-lang/rust#164674 (Use a NoSpan marker for region constraints without spans)
 - rust-lang/rust#164934 (Remove redundant vec and duplicate indexing in find_noop_landing_pads)
 - rust-lang/rust#164954 (Reduce `SpanData` use)
 - rust-lang/rust#164970 (`rust-analyzer` subtree update)
weirdsmiley pushed a commit to weirdsmiley/rust-analyzer that referenced this pull request Nov 9, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#164955 (Use the updated buffer length in UEFI locate_handles)
 - rust-lang/rust#164958 (uefi: roll back env changes when `start_image` fails)
 - rust-lang/rust#164968 (thread_local::guard: update comments a bit)
 - rust-lang/rust#164303 (Remove the 'sub' method from 'At' and migrate to 'sub_raw')
 - rust-lang/rust#164674 (Use a NoSpan marker for region constraints without spans)
 - rust-lang/rust#164934 (Remove redundant vec and duplicate indexing in find_noop_landing_pads)
 - rust-lang/rust#164954 (Reduce `SpanData` use)
 - rust-lang/rust#164970 (`rust-analyzer` subtree update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UEFI: failed Command::output skips environment rollback, permanently altering the parent environment

4 participants