Skip to content

Post-merge review triage of #790/#789/#791: user-reachable wrapper flag, getppid() race in PID namespaces, carrier-blind quote simulation #794

Closed

Description

@caomengxuan666

Triaged from post-merge review of #790/#789/#791 (three items)

1. __RUBASH_BACKGROUND_WRAPPER is user-reachable (#790 followup)

src/executor/compound_exec.rs:428 sets a plain, user-guessable env var to
flag background-job wrappers, and src/builtins/kill.rs:1965 re-checks it
via std::env::var inside the spawned child. Any script that does
export __RUBASH_BACKGROUND_WRAPPER=1 makes every process it spawns
behave as a background wrapper (adoption of the PDEATHSIG prctl path and
whatever else keys off the flag).

This is the E400-class problem again (rubash#735): a user-spellable name
colliding with a reserved space. Options, in order of preference:

  • Before respawning the wrapper, do env_remove of the name from the
    inherited user env first, then insert ours — forged values cannot be
    inherited, only constructed by our own spawn sites. (Verify no overlay
    path re-merges the parent env afterwards.)
  • Or namespace it (__RUBASH_BGW_<pid>_<nonce>) and pass the nonce via the
    wrapper argv, so guessing the name is not enough.
  • Or move the flag out of the environment entirely (args/handle table).

Repro sketch (no build needed to spec): __RUBASH_BACKGROUND_WRAPPER=1 rubash -c 'sleep 5 & kill %1; wait' — with a forged value the inner
sleep (not spawned through the background-wrapper spawn path) still gets
prctl'd, i.e. third-party program behavior is altered by an ambient
variable we never sanctioned.

2. getppid() == 1 orphan race check misfires under PID namespaces (#790 followup)

kill.rs (post-#790): after prctl(PR_SET_PDEATHSIG, SIGKILL), the
post-fork race is patched with if getppid() == 1 { kill(self) }. Inside
PID namespaces (containers, sandboxed CIs, Termux-style harnesses) a
perfectly healthy child of PID 1 starts with getppid() == 1 before the
prctl race is even possible
— the child self-SIGKILLs at spawn time. Any
shell run directly under a pid-1-launched service (docker --init minus tini,
most CI runners looping in the container) hits this deterministically.

Fix sketch: compare against the expected parent captured pre-fork before
the prctl (pass the parent's actual pid into the closure; kill only if it
changed), not against the constant 1. Cost: one u32 through the pre_exec
closure.

3. raw_word_has_unquoted_parameter_expansion simulation cannot see carrier bytes (#789 followup)

mark_quoted_ifs_from_raw (naturalization for #743) re-parses the raw
word with its own single/double/\\/${} state machine and
** bail-without-marking on mismatch** — the safety net is good. But the
simulator treats every non-ASCII char (and thus every E3xx carrier byte:
$'...' decoded quotes, protected backslashes, sequential IFS guards) as
an ordinary data character. Two consequences today, both silent-degrade,
neither wrong-output:

  • A raw word containing carrier bytes can never match the cooked word
    when the cook dropped/kept them differently — mark pass silently
    skipped, we fall back toU+E302 sentinel previous (split-everything-or-nothing)
    behavior for exactly the words that most need the per-char rule.
  • Pure-carrier raw words ($'...' only) skip the new path entirely.

Both are correctness-preserving fallbacks, so this is a fidelity gap, not
a bug — but it makes #743's fix a layer shallower than its tests which all
use plain-ASCII raw words. Worth a follow-up that either maps cook↔raw via
the authoritative quote remover, or extends the simulator to recognize
markers.rs ranges explicitly (one rune class, five minutes of code).

Acceptance criterion for all three

No behavior change for plain-ASCII, non-namespace, non-adversarial-env
runs. Each item ships with a probe that exercises the adversarial corner
(forged env / pid-1-parent shell / carrier-laden raw word) and pins current
-or-fixed output with a #746 case id.

Activity

  1. caomengxuan666 commented on Oct 19, 2026

    @caomengxuan666
    MemberAuthor

    Dispositions — all three items verified still present on master at e6a54457bedb and now carried by dedicated issues (one concern each):

    1. User-forgeable __RUBASH_BACKGROUND_WRAPPER → user-forgeable __RUBASH_BACKGROUND_WRAPPER env var imposes PDEATHSIG semantics on every spawned child #866. Verified: plain env_map.insert at src/executor/compound_exec.rs ~520 (no env_remove/namespacing) and std::env::var gate at src/builtins/kill.rs ~1965; only these two files reference the name.
    2. getppid() == 1 orphan check under PID namespaces → getppid() == 1 orphan-race check self-kills healthy children under PID namespaces #867. Verified: constant-1 comparison at src/builtins/kill.rs ~1974, no expected-parent capture.
    3. Carrier-blind quote simulation → mark_quoted_ifs_from_raw simulator is carrier-blind: carrier-laden raw words silently lose per-char IFS marking #868. Verified: mark_quoted_ifs_from_raw at src/executor/command_prepare.rs ~4040 has no carrier/marker recognition in its state machine and bails without marking on mismatch (the \'→DATA_SQUOTE guard from #789 splitting rework: two field-splitting regressions vs GNU 5.3.0 (nested-quote guard + ${$+<nl>}) #795 is in, but the carrier-family gap is unchanged).

    No behavior of this triage is being silently dropped.

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