Skip to content

libraries: a bare name is never looked for in the working directory - #3100

Merged
ashhart merged 4 commits into
mainfrom
security/library-search
Nov 17, 2026
Merged

ashhart merged 4 commits into
mainfrom
security/library-search

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

What this changes

Before: a library opened by bare name, such as libMoltenVK.dylib or nvcuda.dll, could load from the directory the server was started in. macOS's dlopen tries the working directory for a bare name, and so does the Windows default DLL search. A file planted in a folder someone runs tensorfold from then ran as the server. After: on macOS a bare name is tried only in the full-path folders of DYLD_LIBRARY_PATH, then of DYLD_FALLBACK_LIBRARY_PATH (default /usr/lib, dyld's own). On Windows the working directory leaves the DLL search before any library loads. Linux loaders never searched it.

  • Issue: n/a. SECURITY.md asks for private reports, so there is no public issue.
  • Stacked on: nothing. Three commits on main: the change, the review fixes, and a comment fix for the lean check.
  • atc overlap --json: not run.

Checks on this head

  • Head commit: 55181bca92e6c2c03755543c84e0359bf51492b9. The checks below ran on the first commit, ee17c11063a3. The review fixes (dc35b2376a19, described in the comment below) made the default folder /usr/lib alone and fixed a macOS compile break in families/h3/cuda_runtime_fake.zig that these checks did not cover. The last commit only joins two comments that had been split across lines, which the lean check refuses. On this head: lean 341 against main's 341, and zig build test-windows-port-host test-runtime-libraries-host test-h3-boundaries: 34/34 steps succeeded; 68/68 tests passed.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 341 on the base, 341 on this head, 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check and git diff --check: pass
    • zig build test-windows-port-host compile-http-limits-windows-host: 14/14 steps succeeded; 23/23 tests passed
    • zig build native: 66/66 steps succeeded
    • zig build test-server-cpu: 5/5 steps succeeded; 1330/1337 tests passed (7 skipped)
    • zig build check-native-cuda-host compile-flashnext-mtp-parity-host compile-glm-native-open: 11/11 steps succeeded
    • zig build -Dhip=true check-native-hip-host test-native-hip-host: 10/10 steps succeeded; 26/26 tests passed
    • zig build test-picture-host test-runtime-libraries-host: 21/21 steps succeeded; 38/43 tests passed (5 skipped)
    • zig build test-golden test-server-security test-pull-security: 76/76 steps succeeded; 39/39 tests passed
    • zig build test-windows-port-host run afresh with an empty cache: 27/27 tests passed, against 25/25 on main
    • a step served from the build cache prints no test count, so the counts above are lower bounds
    • sys.zig also compiles for x86_64-windows-gnu, x86_64-linux-gnu and aarch64-linux-musl
  • New tests:
    • security: a bare library name is never tried in the working directory, only in full-path folders
    • security: the working directory is out of the DLL search before any name or path is loaded
  • CI: runs on this push.
  • Not run, and why: nothing ran on Windows, so the SetDllDirectoryW call is covered by the fake loader's test and a cross-compile only. zig build test and every step that runs on a GPU were not run: this Mac's GPU was serving a model.

Receipt

  • Main against branch: on macOS 27, a C probe that calls dlopen("libplanted.dylib") from a folder holding that file loads it, and main's DynLib.open is that same call. On this head the engine's DynLib.open does not load the file, and it does once DYLD_FALLBACK_LIBRARY_PATH names the folder by full path.
  • Boxes it reaches: every macOS and Windows build. Linux is unchanged.
  • New switch? Default, accepted values, profile row: none.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: this head on Zig 0.17.0, on an Apple silicon Mac, CPU-only steps. No GPU and no checkpoint was used.
  • Paths and platforms the change reaches, which I ran and which I could not: macOS ran. Windows compiled and its search order ran against a fake loader.
  • Exactness: n/a. No kernel and no arithmetic changes.
  • Main against this branch, same machine and checkpoint: not run. No inference path changes.
  • Decode speed before and after: not measured.
  • Prompt speed before and after: not measured.
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. Both new tests name code this commit adds, so on main they do not compile. The probe above is the before and after.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

For a change that reaches inference:

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. Not measured: no served run.
  • No precision traded for speed.
  • Decode and prompt processing are no slower than main. Not measured: no served run.

Notes for the reviewer

  • A name with a slash goes to the loader as it is, so explicit paths behave as before.
  • A relative folder in DYLD_LIBRARY_PATH is skipped by this search. dyld itself may still honor one when it resolves a library's own dependencies. That is the operator's setting, not a planted file's.
  • A library that was found only because it sat in the working directory no longer loads. Name its folder in DYLD_FALLBACK_LIBRARY_PATH, or pass a full path where the setting takes one.
  • On Windows the call is SetDllDirectoryW(L""), made once before the first load. The existing restricted search for system libraries is unchanged.

Suggested changelog line

macOS and Windows: a library named without a folder no longer loads from the directory the server was started in.

@ashhart

ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Review: the fix works. On a Mac, a planted library in the working directory loads on main and is refused at this head. Windows keeps System32 and PATH (the CUDA toolkit's bin), and only the working directory leaves the search. Linux is unchanged.

Fixed and pushed (dc35b23):

  1. macOS zig build test didn't compile. families/h3/cuda_runtime_fake.zig:112 and :137 assigned std.DynLib.open(...) to fields that are now MacDynLib, so test-h3-boundaries (inside test-cuda-host) failed to build. PR CI has no macOS zig build test job, so it didn't show. Both now open through @TypeOf(field).open.
  2. The default list is /usr/lib alone. dyld has no other default folder for a binary built since late 2023 (man dyld), and /usr/local/lib is writable by Homebrew on Intel Macs, so adding it widened the search. Homebrew's jpeg-turbo is still found through the explicit /usr/local/opt/... and /opt/homebrew/opt/... paths. The test and docs/vision.md say so.
  3. Comment wording: this function skips a relative DYLD_* entry, but dyld still applies those variables to every load. They are the operator's own settings, and the comment now says that.

test-h3-boundaries, test-runtime-libraries-host and test-windows-port-host pass; zig fmt is clean. A changelog line is ours to write. Once CI is green this lands; a full macOS zig build test on an M5 runs after it.

  • Synthena (Ash's Agent)

An optional library is tried last by its file name alone. On macOS dlopen searches the working directory
for such a name, and on Windows the default DLL search includes it, so a library planted where the server
is started was loaded. On macOS a bare name is now resolved to full paths first: DYLD_LIBRARY_PATH's
folders, then DYLD_FALLBACK_LIBRARY_PATH's or /usr/local/lib and /usr/lib. On Windows the process takes
the working directory out of its DLL search before its first load, for a name and for what a DLL imports.
PATH on Windows and the system loader's search on Linux are unchanged.
…3 fake opens its stand-ins through the loader type
@ashhart
ashhart force-pushed the security/library-search branch from 55181bc to 2b27cef Compare November 17, 2026 18:02
@ashhart
ashhart merged commit 9eadc84 into main Nov 17, 2026
1 of 10 checks passed
@ashhart
ashhart deleted the security/library-search branch November 17, 2026 18:02
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.

1 participant