WIP: fix: security hardening passes (update offer, builder and release downloads, setup lists, shared env file, files the game reads and writes, game folders from elsewhere, HLE guest ranges) #2326
Closed
hckrman101 wants to merge 34 commits from
security/hardening-passes into main
pull from: security/hardening-passes
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:github/pr/2876
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2859
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2759
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:perf/astc-opaque-bc1
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!2326
Loading…
Reference in a new issue
No description provided.
Delete branch "security/hardening-passes"
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?
Some files that players run, download or pass around are still trusted more than they should be. A game folder's text file can pick the program the update offer starts. A shared
hookshot_env.txtcan still set switches that write files or change how an update builds. A game folder unpacked from an archive can hold links that the game or the builder writes through. This PR closes those gaps and adds tests so they stay closed. None of it changes what a normal player sees.What changes
Update offer and builders
Update offer (host/hos_update.c). The update offer now uses
builder=/builder_args=fromhookshot_version.txtonly when they look like what our builders write:HookshotBuilder.exe, or topython(w).exewith-I <path>\hookshot_builder_start.py;AppRun.Anything else counts as "no builder", and the offer opens the download page instead. Only the shape of the path is checked, not where it is, so a builder unpacked anywhere still works.
"Skip this version" no longer writes through a
userfolder or skip file that is a link. On Linux it uses lstat and O_NOFOLLOW. On Windows it refuses symbolic links and junctions but still allows OneDrive's own reparse points.The builder an update starts no longer gets the switches that the game's
hookshot_env.txtset. It inherits the rest of the game's environment, but the builder reads some of the same names for its build (RX_MARCH,RX_VK_ONLYand others). On Linux the builder is started withexecveand an environment built before the fork. On Windows those switches are cleared beforeShellExecuteW, and put back if the builder does not start.One tag rule for every builder. A tag may use
[0-9A-Za-z._+-], be at most 128 characters, and not be.or... The WPF, Python and Linux builders apply it to--tagand to every tag they read from GitHub. Before, the WPF builder's nightly lookup passed the list's tag line, unchecked, into a release API link. The WPF builder's patterns end in\z, because .NET's$also matches before a final line break.Windows Python builder downloads (setup_parts.py, updater.py).
Setup lists' parts (builder/setup/setup.c, setup_parts.py, builder/linux/linux_update.py). A part's link must now be under this project's GitHub releases, or llvm-mingw's for the Windows lists (the one part that is not ours). The rest of the link must have no
..step, escape, query or other host. Before, the checksums pinned each part's bytes, but a link could name any https host. A list given for testing (HOOKSHOT_SETUP_LIST) and the Linux updater's lists from this PC still take any https (or file) link.WPF builder downloads (Updater.cs). A download now stops as soon as it passes GitHub's size for the file. Before, a body with no Content-Length was written to disk in full and only then compared.
Shared
hookshot_env.txt(host/hos_main.c)_DUMPin its name is now refused as a group.RX_SCREENSHOT,RX_FLASH_LOG,HOS_SCAN_DTandRX_VK_FRAME_TRACEare refused by name.*_SAVE_FRAMESswitches (a picture each frame) and thediskaudio driver. OtherSDL_switches still work.HOOKSHOT_names: only the game's own are taken:HOOKSHOT_NO_UPDATE_CHECK,HOOKSHOT_NO_AV1_NOTICEandHOOKSHOT_OCCLUSION_OFF. The rest are the builder's.RX_VK_DLSS_DIRis still the one path the file may set, but only as a full local path (C:\...or/...) with no..step. Before, a relative value was resolved against whatever folder the game was started from.tests/test_env_file.pyscanshost/andgpu/for switches whose value is used as a path, and the builder's sources forHOOKSHOT_names. It fails if the shared file could set one of them. The readme says the same.HOS_ENV_FILEstill set anything.Files the game writes, and game folders from elsewhere
Files the game writes by itself (new host/hos_fopen_write.h). This covers
hookshot_options.ini, the pipeline caches, the state lists and their markers, the button-prompt textures,mouse_sens.txt,language.txtand the moved-saves note. A game folder unpacked from an archive can hold links, and before, the game wrote through a link at one of these names, emptying the file it pointed to.Files the game reads from its folder at start-up. These are now read only when they are regular files. Before, a FIFO under one of their names (an archive can carry one) made the game wait forever before its window opened. The files covered:
hookshot_env.txt,hookshot_options.ini,language.txtandmouse_sens.txt, through the newhos_fopen_read;hos_fopen_read_binary;This applies on Linux. On Windows the read is plain
fopen.Mouse sensitivity (host/nn_hid.c). A value from
mouse_sens.txtorHOS_MOUSE_SENSis taken only when it is a finite number, and it is kept to the menu's 10-500%. Before, a value likeinfwent into the menu's option as an undefined number.Saves moved from an old
user/folder (Linux). The game movesuser/into$XDG_DATA_HOME/hookshotand copies an entry when it cannot rename it. Moving, copying and the clean-up afterwards no longer go through a link. A link with a full path is moved as a link, so a save folder kept elsewhere still works. A relative link, a link that cannot be moved, or a folder that holds a link or a FIFO stays where it is, and the saves stay inuser/.Rebuilding or updating an existing game folder (nx2/make_game.py, nx2/nup.py).
.hookshot_romfs_headshas to name a.zsfile inside the romfs, under the same path rule the extraction uses. If any line does not, the list is dropped and every file is checked instead.<name>.part..hookshot_exefs, or inside the romfs the build hard-links into, stops the build and asks for an empty folder. On Windows only symbolic links, junctions and WSL links count, so a folder under OneDrive still updates.language.txt,hookshot_version.txt,bin,prompts, the staged.newfiles and so on) stops the build before anything is written. Links at other names, such as a cache moved to another drive, are left alone. A test checks that every name the builder writes is on the list.Pipeline cache (gpu/vk/vk_draw.cpp).
mkw_vk_pipelines.binand the play caches are now checked by their header before the rest is read, and a file over 4 GB is not read. Before, the whole file was loaded into memory first.Button-prompt files (host/prompts.c). A file is read only when its magic is right, and never past 256 MB. Before, the whole file was loaded into memory first.
Pipeline notes and state lists (gpu/vk/vk_draw.cpp). A record is used only with a sample count the GPU supports, vertex strides up to 2048 (Vulkan's least limit) and divisors up to 65535. Before, any power of two up to 64 and any stride or divisor were handed to the driver.
Contributed pipeline state lists (nx2/pipeline_states.py).
add,tourandcheck(which CI runs) now stop on a record with a value no pipeline has: a count past its array, a sample count or topology Vulkan does not have, a yes/no value other than 0 or 1, non-zero padding, or a stride or divisor past those limits. They name the record and the reason.A refused write is logged. The first time a file stops at a link or a non-file in
hos_fopen_write, it writesfiles: <path> is a link or not a plain file: the game does not write through itto the game's log. That gives a setting that does not stick a visible reason.Host functions the game calls (HLE)
GP()turns a guest address into a host pointer without checking it. Before, a size the game passed could carry a copy past the guest window into the host's own memory. These functions now usehos_guest_rangeon the whole span, as nn::fs and the libc copy hooks already do:hos_main.candoot_menu.c.nvnDeviceGetProcAddressandnvnBootstrapLoadernow copy the name the game passes, at most 255 characters and only from inside guest memory. Before, they read it in place to its end.Release and CI
--require-hashes, from a newrequirements-lock.txt.python -I scripts/python_lock.pywrites it after a pin changes.tests/test_python_lock.pyfails when the lock and the pins differ.<name>.part. Each file is hashed while it downloads, and a download stops past 1 GB. The pinned commits and SHA-256s are unchanged..zsyncinto thercrelease only when GitHub gives a SHA-256 digest for each file. This is checked before the tag moves or anything uploads. Before, a file without a digest was copied unchecked.requirements.txt,nx2/prompt_requirements.txt) weekly, with the same 7-day cooldown as the actions. After it changes a pin,scripts/python_lock.pymust write the lock again;tests/test_python_lock.pyfails until it does. The builder's .NET project has no NuGet packages, so there is no NuGet entry.fetchwith SHA-256 pins, like every other download there.persist-credentials: false(except the release record job's);${{ }}of event data or inputs inside arun:script;pull_request_targetworkflow.Tested
Linux, RTX 3090. The branch merges main@origin
ebbba2ea, which carriesscripts/release_rc.shand the setup-list code changed here; the merge had no conflicts. Testing used merges with main as it moved (e19d9693,d7a73062,ebbba2ea,49f75dc8), all without conflicts. The link and env game runs used thee19d9693merge, the FIFO run and the last game build thed7a73062merge, and the last full suite the49f75dc8merge.python -I -B tests/run_all.py). 373 passed, 1 failed, 12 skipped. The failure,tests/test_wayland_libdecor_hint.py, also fails on main on this PC.--require-hashesfor Linux x86_64 / Python 3.12 (with dependencies) and for Windows x64 / Python 3.12, 3.13 and 3.14 (as the Windows part installs them): 10 of 10 each time.host/hos_update.ccompiles with no warnings (-Wall -Wextra) under gcc (Linux) and llvm-mingw clang (Windows).hookshot_vk.dll) cross-built with llvm-mingw before the last round. After it,vk_draw.cppandvk_main.cpppass a syntax check for both Linux and Windows.host/nvn_native.c,builder/setup/setup.cand the host files that includehos_fopen_write.hpass one for both too.language.txtlink planted in the folder, the build stopped at the start and named it, and the link's target was left as it was.HOS_HEADLESS=1 HOS_NO_SDL=1, separate data folder, links planted in the game folder; final run on the branch head):hookshot_options.inior at the pipeline marker;user/was moved to the saves folder, and itsuser/savelink was moved as a link with its target left alone;RX_VK_DLSS_DIRwas left out ofhookshot_env.txt;RX_VK_FRAME_TRACE,HOOKSHOT_MEM_LIMIT_GB,HOOKSHOT_JOBSandHOOKSHOT_PREPARE_ONLYwere left out, and nosdlaudio.raworhookshot_frames.csvappeared;language.txt,hookshot_env.txtandhookshot_options.ini. On a build that had moved only the host's reads, the game hung after listing the GPUs, on the renderer's own read ofhookshot_options.ini. With every start-up read moved over, it started and ran as usual and never waited on the FIFOs.tests/test_updater_asset_digest.pybuilds the wholeUpdater.cswith its fixture: 22 of 22 cases pass. Its two new cases fail on the code before the fix.tests/test_builder_dlss_update.pypasses (57 checks).EnableWindowsTargeting=true, with no warnings.Not tested
hos_fopen_write, which was only tested with a stand-inwindows.h. The Windows host files were only syntax-checked.Looked through CI on the current head. One real failure, the rest is the runners.
1.
tests/test_oot_menu_mouse.pyfails to build on Windows (part 2/2):The game itself is fine, since
host/hos.hdeclares it. The test compilesoot_menu.cagainst its ownHOS_Hstand-in, which hasGP()but nothos_guest_range. The test skips anywhere but Windows, which is why your Linux suite didn't catch it. Adding this toHOS_Hshould do it (I couldn't run it here, since it skips on Linux):2. Not this PR: the Linux AppImage, both Linux source-check jobs and the SPIR-V fixtures stopped at installing packages (
Temporary failure resolving 'azure.archive.ubuntu.com'). A re-run should clear them. The AppImage job also failed on main at49f75dc8.For context, a few of these close things Syntak's pentest flagged on Hookshot this week (
builder_argsinhookshot_version.txt, the urllib/redirect handling in the builder). I'd rated those not exploitable under a local-trust model, but closing them anyway is welcome.Integration heads-up for #2367: the portable Windows Builder records a game-relative
builder_portableassociation, resolves it after relocation, and deliberately refuses a missing portable association rather than falling back to another installed Builder. Yourbuilder_okpath validation is important; whichever lands second should validate the resolved portable path through that policy rather than accepting arbitrary relativebuilder=values. Let's preserve both behaviors, including your symlink/junction and environment filtering checks. #2406 also touches the Linux update entry points but keeps explicit version switching; I can help reconcile those handlers once the merge order is known.