sharpemu/tests/SharpEmu.Libs.Tests
Slick Daddy e01092aa38
Kernel FS: close guest→host sandbox escapes in the path resolver (#478)
* Kernel FS: default-deny unmapped guest paths (fixes absolute-path host escape)

ResolveGuestPath returned any unrecognized guest path verbatim as the host
path. Because absolute paths ("/etc/passwd", "C:\Windows\...") are already
fully qualified, they skipped the relative-path app0 fallback and were handed
straight to FileStream/File.Delete/etc., giving a malicious game arbitrary
host-file read/write/delete outside the sandbox.

Return string.Empty (deny) on fallthrough instead. Most callers already treat
a nonexistent host path as NOT_FOUND; open/truncate/rename get an explicit
empty-path guard so a denied path can't reach FileStream and throw an
ArgumentException their catch blocks don't cover.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Kernel FS: contain built-in mounts (fixes Windows drive-letter injection)

The built-in mount branches (app0/temp0/download0/hostapp/devlog) combined
the mount-relative guest path onto the host root without re-checking
containment. NormalizeMountRelativePath clamps ./.. but splits only on
separators, so a drive-qualified token like "C:" survives as a segment and
Path.Combine then discards the mount root, yielding a raw host path such as
"C:\Windows\..." (arbitrary host read/write).

Route every built-in branch through a new CombineWithinMount helper that
re-resolves with Path.GetFullPath and verifies the result stays under the
mount root -- the same guard TryResolveRegisteredGuestMount already applied.
Denied paths return string.Empty, which callers treat as unresolved.

AprStreamingContractTests passed a raw Path.GetTempFileName() as the guest
path, relying on the now-removed absolute-path passthrough; updated it to
address the file through a registered mount.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Kernel FS: reject reparse points inside mounts (fixes symlink escape)

Lexical containment (Path.GetFullPath + StartsWith) proves the textual
path stays under the mount root but does not follow symlinks/junctions.
A malicious game dump could plant a reparse point inside app0/temp0/etc.
pointing outside it, so a contained-looking path resolved onto the host
filesystem. Walk each existing component from the mount root to the
candidate and refuse any reparse point, in both the built-in and
registered-mount resolution paths. Mirrors AvPlayer's existing defense.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Kernel FS: fail closed when path containment cannot be verified

The reparse-point and drive-letter containment guards call Path.GetFullPath
and File.GetAttributes on untrusted guest paths. Both throw on crafted
over-long or invalid-char input, and ResolveGuestPath runs outside the file
syscalls' try blocks, so such a path was a guest-triggerable crash rather
than a denial.

Wrap the GetFullPath calls in CombineWithinMount and the registered-mount
path, and widen the GetAttributes catch, to treat any access/format failure
as an escape (deny) instead of propagating. Also tighten the ".." fallback
check so a legitimate file named "..foo" is not falsely rejected, and hoist
the repeated Path.GetFullPath(mountRoot) into a local.

Adds a regression test asserting the resolver returns without throwing for
an over-long and a NUL-embedded path under a mount.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Kernel FS: assert malformed paths resolve to empty, not just no-throw

The fail-closed regression test asserted only Assert.NotNull, which a
non-nullable string return can never violate via its value (only a throw,
which aborts the test earlier anyway). Tighten to Assert.Equal(string.Empty)
so it also locks in fail-CLOSED: a regression where a malformed path resolved
to a non-empty host path would now be caught.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Kernel FS: route new AMPR batch tests through a registered mount

Merging main brought in three AprStreamingContractTests that pass raw
Path.GetTempFileName()/temp host paths as guest paths. The default-deny
resolver from this branch rejects absolute host paths, so MissingMidBatch
failed at index 0 instead of the intended index 1. Address the present
file through a registered mount (as ResolveStatAndReadFile already does)
so entries 0 and 2 resolve and the batch fails at the genuinely-missing
entry. The two all-missing tests were unaffected but share the fix's intent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Kernel FS: make a matched-mount denial terminal; fix Unix-only test asserts

A registered mount that claims a path by prefix but denies it (failed
containment or a reparse point inside the mount) now short-circuits in
ResolveGuestPath instead of falling through to the built-in mount branches.
The fall-through let an overlapping prefix (a registered "/app0" vs the
built-in SHARPEMU_APP0_DIR branch, which resolves against a cached root)
re-resolve a denied path and turn the denial back into a resolution -- the
reparse-point escape reappeared on Linux CI through exactly this path.

Also fix two tests that asserted Windows-specific behavior unconditionally:
a "C:\..." path is not absolute on Unix (it resolves contained under the
mount there), and that case is now pinned to Windows only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: slick-daddy <slick-daddy@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 00:58:34 +03:00
..
Agc Shader: lower VOP3P V_FMA_MIX_F32/LO/HI (was dropping Unity HDR shaders) (#466) 2026-07-20 14:37:40 +03:00
Ampr Kernel FS: close guest→host sandbox escapes in the path resolver (#478) 2026-07-21 00:58:34 +03:00
Audio [AJM] Track registered codec instance lifecycle (#352) 2026-07-18 03:02:19 +03:00
AvPlayer Prevent AvPlayer movie startup failures across supported hosts (#456) 2026-07-20 15:27:37 +03:00
Cpu cpu: emulate AMD-only Zen 2 instructions in software (#449) 2026-07-19 21:57:42 +03:00
Fiber test: add Fiber exports contract tests (13 tests) (#428) 2026-07-19 13:53:33 +03:00
Font [HLE] Stub ContentExport, Font, and Pad calls Astro Bot needs to boot (#298) 2026-07-17 04:34:48 +03:00
GUI PerGameSettings Null toggles (#453) 2026-07-20 01:30:13 +03:00
HLE Prevent invalid SaveData writes from damaging guest memory (#444) 2026-07-19 20:27:17 +03:00
Json [SourceGenerators] Compile-time SysAbi export registry, analyzers, and build-generated aerolib.bin (#204) 2026-07-16 00:00:32 +03:00
Kernel Kernel FS: close guest→host sandbox escapes in the path resolver (#478) 2026-07-21 00:58:34 +03:00
LibcInternal Add libc heap trace contract tests (#409) 2026-07-19 03:25:42 +03:00
Loader test: add Kernel/Loader unit tests (22 tests) (#373) 2026-07-18 20:19:55 +03:00
Logging Reject undefined numeric LogLevel values (#390) 2026-07-18 15:47:19 +03:00
Memory memory: back the free pages of a partially-overlapping fixed mapping (#458) 2026-07-20 09:08:29 +03:00
Network Fix sceNetHtonl/Htons/Ntohl/Ntohs discarding their converted result (#211) 2026-07-16 16:24:34 +03:00
Pad [HLE] Stub ContentExport, Font, and Pad calls Astro Bot needs to boot (#298) 2026-07-17 04:34:48 +03:00
PlayGo [PlayGo] Reject authoritative unknown chunk loci (#242) 2026-07-16 19:22:33 +03:00
Pthread Prevent AvPlayer movie startup failures across supported hosts (#456) 2026-07-20 15:27:37 +03:00
Random [HLE] Add RandomExports HLE (#413) 2026-07-18 23:44:57 +03:00
Rtc Fix sceRtcConvertLocalTimeToUtc failing on non-UTC hosts (#210) 2026-07-16 00:04:35 +03:00
SaveData Prevent invalid SaveData writes from damaging guest memory (#444) 2026-07-19 20:27:17 +03:00
ShaderCompiler [ShaderCompiler] Fix VReadlane scalar destination field (#344) 2026-07-18 02:41:07 +03:00
SystemService [SystemService] Write notice skip flag as byte (#346) 2026-07-18 02:41:38 +03:00
Tls [AGC/Vulkan] Extend PS5 runtime and rendering compatibility (#216) 2026-07-16 02:02:34 +03:00
VideoOut Encode linear-float flips to sRGB at present (#448) 2026-07-20 01:29:38 +03:00
AerolibCatalogTests.cs [SourceGenerators] Compile-time SysAbi export registry, analyzers, and build-generated aerolib.bin (#204) 2026-07-16 00:00:32 +03:00
FakeCpuMemory.cs [Json] Implement sce::Json::Value and String (construct / set / destroy) (#169) 2026-07-15 01:49:33 +03:00
SaveDataStorageTests.cs [Gpu] Metal backend: complete IGuestGpuBackend implementation on AppKit + Metal (#283) 2026-07-18 20:32:00 +03:00
SharpEmu.Libs.Tests.csproj Gui Settings Null list Entries (#430) 2026-07-19 13:53:56 +03:00
Sse4aExtrqBlendPatchTests.cs [Gpu] Metal backend: complete IGuestGpuBackend implementation on AppKit + Metal (#283) 2026-07-18 20:32:00 +03:00
SysAbiRegistryTests.cs [SourceGenerators] Compile-time SysAbi export registry, analyzers, and build-generated aerolib.bin (#204) 2026-07-16 00:00:32 +03:00