Skip to content

stdbuf: fix tmpdir leak - #14059

Open
Ecordonnier wants to merge 4 commits into
uutils:mainfrom
Ecordonnier:stdbuf-fix-tmpdir-leak
Open

stdbuf: fix tmpdir leak#14059
Ecordonnier wants to merge 4 commits into
uutils:mainfrom
Ecordonnier:stdbuf-fix-tmpdir-leak

Conversation

@Ecordonnier

Copy link
Copy Markdown
Collaborator

Two security/correctness issues reported in #13939:

  1. Leaked temporary directories: using exec() replaced the stdbuf process before TempDir's destructor could run, leaving one .tmp* directory per invocation in $TMPDIR forever.
    Fix: use spawn() + wait() so the parent process survives to drop the TempDir after the child exits.

  2. World-readable temporary directory: the tmpdir was created with default permissions, making libstdbuf.so writable by any user on a multi-user system (privilege-escalation risk).
    Fix: call set_permissions(0o700) immediately after creation, bypassing the umask.

Both fixes apply only when feat_external_libstdbuf is not set (i.e. the embedded .so path).

sylvestre and others added 4 commits August 20, 2026 15:39
Two security/correctness issues reported in uutils#13939:

1. Leaked temporary directories: using exec() replaced the stdbuf
   process before TempDir's destructor could run, leaving one
   .tmp* directory per invocation in $TMPDIR forever.
   Fix: use spawn() + wait() so the parent process survives to drop
   the TempDir after the child exits.

2. World-readable temporary directory: the tmpdir was created with
   default permissions, making libstdbuf.so writable by any user on
   a multi-user system (privilege-escalation risk).
   Fix: call set_permissions(0o700) immediately after creation,
   bypassing the umask.

Both fixes apply only when feat_external_libstdbuf is not set
(i.e. the embedded .so path).
Use tempfile::Builder::permissions so the directory is never world-accessible
between tempdir() and chmod, closing a TOCTOU window on permissive umasks.

Co-authored-by: Cursor <cursoragent@cursor.com>
Open the injected shared library with an explicit mode so umask 0 cannot
leave a world-writable .so in the private temp directory.

Co-authored-by: Cursor <cursoragent@cursor.com>
Point at rust-lang/cargo#8317 as the still-open request for cargo install
to support installing shared libraries, since that's the root cause of
the /tmp fallback described in the comment above.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI lite review requested due to automatic review settings August 21, 2026 08:45
@Ecordonnier Ecordonnier changed the title Stdbuf fix tmpdir leak stdbuf: fix tmpdir leak Aug 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/retry (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/cp/link-heap is now passing!

@codspeed-hq

codspeed-hq Bot commented Aug 21, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 5.48%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 356 untouched benchmarks
⏩ 50 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation du_summarize_balanced_tree[(5, 4, 10)] 16.9 ms 16 ms +5.48%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Ecordonnier:stdbuf-fix-tmpdir-leak (3a8ae04) with main (3d09364)

Open in CodSpeed

Footnotes

  1. 50 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@oech3

oech3 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Can we reuse a directory named libstdbuf-XXXXXX and avoid spawn instead?

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.

4 participants