Skip to content

user-forgeable __RUBASH_BACKGROUND_WRAPPER env var imposes PDEATHSIG semantics on every spawned child #866

Closed

Description

@caomengxuan666

child_pre_exec_reset() (src/builtins/kill.rs, gate at ~line 1965 at e6a54457bedb) enables prctl(PR_SET_PDEATHSIG, SIGKILL) for every spawned child whenever std::env::var("__RUBASH_BACKGROUND_WRAPPER") == "1". That variable is a plain, user-guessable name inserted verbatim by the background-wrapper spawn path (src/executor/compound_exec.rs ~line 520).

Consequence: any script that runs export __RUBASH_BACKGROUND_WRAPPER=1 makes every process the shell subsequently spawns — including ordinary third-party programs that never went through the wrapper spawn path — adopt the background-wrapper pdeathsig semantics (killed when their parent dies, plus the orphan self-check). Third-party process behavior is altered by an ambient variable the shell never sanctioned. Same class as #735: a user-spellable name colliding with a reserved space.

Repro sketch:

export __RUBASH_BACKGROUND_WRAPPER=1
rubash -c 'sleep 5 & kill %1; wait'

With the forged value the inner sleep (not spawned through the wrapper path) still gets PR_SET_PDEATHSIG.

Fix options, in preference order:

  1. Before respawning the wrapper, env_remove the name from the inherited user env, then insert our own value — forged values then cannot be inherited, only constructed by our own spawn sites. Must verify no overlay path re-merges the parent env afterwards.
  2. Namespace the name (__RUBASH_BGW_<pid>_<nonce>) and pass the nonce via the wrapper argv, so guessing the name is not enough.
  3. Move the flag out of the environment entirely (spawn args / handle table).

Acceptance: a probe exercising the forged-env corner, pinning current-or-fixed behavior with a scripts/regression-catalog case id; no behavior change for clean environments.

Activity

  1. added 2 commits that reference this issue on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions