d3d12 lua: a link to nothing is not written through (D3D12-LUA-WRITE-FILE-DANGLING-LINK) #3189
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3189"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by RussianSanta12 on 2026-12-02T17:44:14Z.
Claimed in the coordination issue as: D3D12-LUA-WRITE-FILE-DANGLING-LINK (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7353400606), from @imShangLi's finding.
What and why
manifest::inside()(d3d12/crates/leonida-lua/src/manifest.rs) found the deepest part of a mod's path that is there withPath::exists, which follows links. A link inside the mod's folder whose target is missing therefore counted as absent: the walk went on to the folder holding it (inside, so allowed), andleonida.write_filethen ended instd::fs::write, which created the link's target, possibly outside the mod's folder.The walk now uses
symlink_metadata, so a link is found as itself whether or not its target exists; canonicalising a link to nothing fails, and that failure is a refusal naming the path (`name` cannot be resolved inside the mod's folder (...)). This covers a dangling link as the last part of the path and as a folder part (lib/x.txtwithlibdangling). Lua has no way to make a link today, so this is hardening, not a hole a mod can reach.Behaviour notes:
docs/lua-modding.mdnow says a link that leads "out of it, or to nothing" is refused.requirethrough such a link reports the refusal instead of "module not found" (init.luais still tried next).Tested
a_link_to_nothing_is_not_written_through(src/tests.rs): a file linkout.txt-> missingoutside.txt, and a junction/symlink folderlib-> missinggone; both writes must be refused and neither target created. The file link is the case that escaped; it needs symlink rights on Windows (it ran here). The junction case runs without rights and pins thatinside()itself refuses it (before the fix it failed later, increate_dir_all).manifest.rsreverted tomain, new test kept):cargo test -p leonida-lua --locked a_link_to_nothingfails with["file true", ...]- the write went through the dangling link and createdoutside.txtoutside the mod's folder. Reproduced independently by the reviewer agent in a throwaway worktree.cargo test -p leonida-lua --locked- 45 passed.cargo build --workspace --all-targets --locked;cargo clippy -p leonida-lua --all-targets --locked -- -D warningsclean;rustfmt --checkclean on the added lines.python -I scripts/check_no_game_data.pypasses;python -m unittest discover -s tests -p "test_docs_*.py"57 OK.mainand with the other openleonida-luapull requests (#3179, #3125), which touch the same test file and doc.d3d12/rust-toolchain.toml. No game files used.GPUs tested: n/a (no GPU code; CPU-only crate tests)
AI-assisted: yes. Implementation: Claude Opus 5.5 (Claude Code). Independent read-only reviewer agent: Claude Opus 5.5 - verdict approve, no blockers; its two comment nits are applied in the second commit.
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T17:54:05Z.
Verified here: it applies on the current
mainand its own test passes - and one flake in the crate, which is not this pull request.The change is the security-relevant kind: a mod path that ends in a symlink to nothing could be written through it -
manifest::inside()resolved the deepest existing part and stopped there, so a dangling link looked like a valid place to put a file. The new test is inmanifest, and it passes.And the flake, which I chased first and should not be blamed on this:
tests::a_scan_without_a_size_reaches_the_end_of_the_imagefailed once in 7 runs with the pull request, which looked like a regression - then 0 in 20 with it and 1 in 20 onmainalone, so it is pre-existing and roughly one run in twenty. I am reporting it separately rather than on this pull request.One disclosure about my own numbers: my first attempt at that A/B counted 20 failures in 20 runs on both sides, because
-match 'FAILED'also matches "0 failed" in the success line. The corrected counts are the ones above - I would rather say that than have someone repeat the broken measurement.What it does not cover: a real mod with a real dangling link. The test builds the manifest and path by hand; whether Windows and Linux resolve a dangling link the same way is the part a test cannot settle, and this is one OS.
AI-assisted: yes - DeepSeek v4.1 (flash).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:04:34Z.
Third-party verification of #3189 (D3D12-LUA-WRITE-FILE-DANGLING-LINK)
c182fc3929367ff67df91930517d961adb8b5d56, merge base45dc41f95(= currentorigin/main). Merges cleanly (git merge-tree --write-tree origin/main pr/3189). GitHubmergeable_state: blocked(review required); no check runs or statuses reported on the head sha yet.claiming: D3D12-LUA-WRITE-FILE-DANGLING-LINKby the author in #2570 (comment 7353400606), from imShangLi's finding (7336235812);done: ... -> #3189(7353600281). Claimed: yes.Tested here: Linux, Rust 1.98.1 (the pinned toolchain).
leonida-luabuilds on Linux, and the test makes real unix symlinks there (#[cfg(unix)]inlink/dir_link), so both cases ran.So the dangling-link escape (a write through
out.txt -> ../outside.txtcreating the file outside the mod's folder) reproduces onmainon Linux too. The pull request closes it, and the other 44 crate tests are unchanged.Review of
d3d12/crates/leonida-lua/src/manifest.rs:83-89symlink_metadatastops the walk at the link itself.canonicalizeof a dangling link then fails and becomes a refusal naming the path. Missing plain files and folders still walk up to an existing parent, sowrite_fileinto a new subfolder andread_fileof a missing file behave as before.read_file/write_file(api.rs:492, 515, 520) and the manifest script (runtime.rs:255) just propagate the error.require(api.rs:88) records the first refusal and still triesinit.lua, as the body says.Defects: none found.
Verdict: ready. Claimed, one topic, red then green reproduced here on Linux, clean-room check passes. Windows was not run here; the author and fiestorra report 45 passed there.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T18:53:01Z.
Ran natively on Windows 11, head
c182fc392merged into currentmain(f1a559851, clean merge).The thread has Linux red/green and a Windows pass. This adds what Windows actually exercises, because that turned out to be less than the test suggests.
Results (measured)
cargo test -p leonida-lua --lib --lockedon the mergemanifest.rsback tomain, new test kepta_link_to_nothing_is_not_written_through)cargo clippy -p leonida-lua --all-targetscargo fmt --checkapi.rsdiffs that are already onmain, nothing from this PROn Windows the escape itself is not what the test checks here. Without Developer Mode or admin,
symlink_fileandsymlink_dirboth fail with os error 1314 (privilege not held), solink()returns false and only the junction half runs. The red above comes from the junction case, and onmainit readsdir false lib/x.txt: Cannot create a file when that file already exists. (os error 183). That's a different error message, not a write outside the folder. The file-symlink case, which is the one that escapes, only runs on Linux in this thread (MoonEyes) or on a Windows box that has the symlink right. Unless the earlier Windows run had that right, it only ran the junction half too, so "passes on Windows" doesn't cover the escape by itself.Junction cases (measured, throwaway tests, same on PR and
mainexcept for the message)mainwrite_file("lib/sub/x.txt"),liba junction to a missing folderwrite_file("lib"), the dangling junction itselfread_file("lib/x.txt")through itrequire("lib.x")through it"script": "lib/main.lua"through itnew/deeper/x.txtIn none of these did anything get created outside the mod's folder, on either side. So on Windows without the symlink right, the PR only changes the message. What it actually protects against is a dangling file symlink, and that was shown on Linux in this thread. A dangling directory symlink on Windows should take the same path through
symlink_metadata, but I couldn't make one here, so that's not run.Checked by grep, not by running: the only filesystem calls in
api.rsaremetadata,read,create_dir_allandwrite. So a mod can't make a link at runtime, and only a link that was already in the folder matters.Merge
mainRuntime::newto returnRuntime, and the new test here calls.unwrap()on it (E0599). Dropping that.unwrap()gives 46 passed. Whichever lands second needs the one-word fixgit merge-tree), not builtFlake.
a_scan_without_a_size_reaches_the_end_of_the_imagefailed 4 times in 40 named runs on the merge (--test-threads=4) and 1 in 20 onmainalone. Every failure wasleft: ["tail 1 0"]. That's the same pre-existing flake fiestorra reported, and it doesn't go throughmanifest.rs. An earlier unnamed loop of 20 had 5 failures, and I didn't record which test those were.Not checked: file or directory symlinks on Windows (no symlink right here), relative symlinks, Linux or Wine, a real mod in the game.
GPUs tested: n/a (CPU-only tests).
AI-assisted: yes (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T20:26:38Z.
VERIFY-3189 — Windows nativo, con enlaces de fichero permitidos (Developer Mode), y la escapada reproducida
c182fc39245dc41f95mainb41763227—git merge-tree --write-treeclean,git merge --no-ffcleanRan
Negative control (
manifest.rsreverted tomain, the PR's test kept), with--nocapture:That is the escape, named:
"file true"means the oldinside()walked past the dangling file link to the folder that holds it,write_filethen wrote through the link and returned success — the file landed outside the mod's folder. The junction was refused, but only later, with the raw OS error (os error 183) rather than a reason. With this PR both read`out.txt` cannot be resolved inside the mod's folder, and the test's final!outside.exists() && !gone.exists()holds.Both link kinds were really exercised here, not skipped: this machine has Developer Mode on (
AllowDevelopmentWithoutDevLicense = 1), and a probe created a file symlink and a junction without elevation.The valid-link cases still hold —
inside()keeps thecanonicalize(probe).starts_with(canon_root)check after the walk, so a link that resolves outside is still refused with`{name}` leads out of the mod's folder, and one that resolves inside is still allowed; the 45 tests include those.What I could not test
if !made_file && !made_dir { return; }branch): not exercised here, since both links could be created.Verdict: red then green, with the escape itself reproduced on the old code.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-12-02T21:01:20Z.
RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch) — PASS covering exact head
c182fc3929367ff67df91930517d961adb8b5d56.git merge --no-ffontomainb41763227(diagnostics,dlss,mimalloc,exe_sha16 = c47eeb717f761d9d; changed-file clean-room scan exit0; workspace test targets compiled).14PRs):#3200d1a91afd1,#319880a627bb1,#319193b47ac9d,#3189c182fc392,#3176ae0075d9a,#3168337388052,#31641065952da,#3146ebc0253ff,#312464600ef0c,#3069311d33a40,#30318df1bfce7,#3029e49404808,#3054ff53fd8b9,#3010d645712a3.610.88, Series X profile,2560x1440,-NoFrameGen,scripts/game-gate.ps1(301.3 sin world) with downtown street-level teleport + 8-leg dynamic sprint/turn/strafe Lua mod (GATE CONTROL moved=2.51 m,max_from_ctrl=5,053.9 m).c47eeb717f761d9d)mainb41763227baseline (cf499737bf684f6a)clean,0reasons,0warnings)clean,0reasons,0warnings)301.3 s(4,504frames)305.6 s0/0/00/0/020.10 FPS/69.76 ms19.13 FPS/74.01 ms8,048/5.222 s7,983/2.358 sVerdict: PASS for the 300 s in-game stability gate on
c182fc392(note: this batch check confirms runtime stability with an active Lua mod, not the dangling-link unit assertion itself).(AI-assisted verification:
gemini-4-neon+gpt-6.2-astra.)