fix(cli): redirect Bun's tempdir when /tmp is mounted noexec#26134
Open
LeaCoder0 wants to merge 1 commit intoanomalyco:devfrom
Open
fix(cli): redirect Bun's tempdir when /tmp is mounted noexec#26134LeaCoder0 wants to merge 1 commit intoanomalyco:devfrom
LeaCoder0 wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
On hardened Linux systems (CIS / STIG / Lynis baselines mount /tmp with noexec), Bun's extracted libopentui.so cannot be dlopen()ed and the TUI hangs silently with no visible error unless --print-logs --log-level DEBUG is used. Detect a noexec mount covering $TMPDIR (default /tmp) by parsing /proc/self/mounts and, if found, redirect Bun's extraction via BUN_TMPDIR to ~/.cache/opencode/tmp. The check is Linux-only, a no-op when /tmp is exec-allowed, and respects an existing user-supplied BUN_TMPDIR. Refs anomalyco#5175, anomalyco#3765, anomalyco#4605, anomalyco#6080.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #26136
Type of change
What does this PR do?
Fixes a silent hang when
/tmpis mountednoexec. This is fairly common on hardened Linux setups (CIS, STIG, Lynis baselines all setnoexec,nodev,nosuidon/tmp), and increasingly common on managed corporate workstations.The bundled Bun runtime extracts
libopentui.soto$TMPDIR(defaults to/tmp) anddlopens it. When the mount hasnoexec, mmap can't grant the EXEC perm on the segments and dlopen fails. The TUI swallows the error and the process just hangs — there's no user-visible output unless you remember to pass--print-logs --log-level DEBUG.Bun reads
BUN_TMPDIRto override its embedded-file extraction path. The Node launcher inpackages/opencode/bin/opencodealready runs before the Bun child is spawned, so it's the right place to set that env var when needed.The patch adds
ensureExecutableTmpdir()which, on Linux only:BUN_TMPDIR(if the user already set it, don't touch it)/proc/self/mountsto find the longest mountpoint covering$TMPDIR(or/tmpif unset)noexecoption, setsBUN_TMPDIRto$HOME/.cache/opencode/tmpandmkdir -ps itIf
/tmpis exec-allowed (the common case for everyone not on a hardened box), the function returns immediately and there's zero behavior change. If anything in detection or mkdir fails, it bails out silently so the original error still surfaces — never makes things worse.The same workaround was already documented as a user wrapper in
#5175. This just moves it inside the launcher so affected users don't need a wrapper script.Why this and not a Bun-side fix: a maintainer comment on
#5175notes the underlying issue is also being worked on in Bun. Once that lands this shim becomes a no-op and can be removed. Until then, this unblocks users.How did you verify your code works?
Tested on Ubuntu 24.04 (kernel 6.17) with
/tmpmountedrw,nosuid,nodev,noexec:Before the patch:
opencodehangs foreveropencode --print-logs --log-level DEBUGshowsFailed to initialize OpenTUI render library: ... failed to map segment from shared objectAfter the patch:
opencodebrings up the TUI normally; all internal plugins (home-footer,home-tips,sidebar-context, etc.) reportloaded~/.cache/opencode/tmp/is created on first run, libopentui.so lands thereAlso verified the no-op paths:
BUN_TMPDIR=/some/pathalready exported → function returns early, env var preserved/tmp(a separate VM) → function still returns early, no~/.cache/opencode/tmp/is createdRan
node --check packages/opencode/bin/opencodeto make sure the launcher still parses.Screenshots / recordings
N/A — not a UI change.
Checklist