Repository navigation
# FileManager: take a mount off the list before releasing it (use-after-free), and run the filemanager suite under ASan in CI - #1062
Merged
chrisgleissner merged 3 commits intoNov 10, 2026
Conversation
FileManager::invalidate() released a mount while it was still listed in mount_points. Closing its backing file can delete that file (delete_on_last_close), and the delete walks mount_points through discard_mounts_of_file(), reading the freed file of the mount being released. Unlist the mount before releasing it and rescan. The filemanager host test is built with AddressSanitizer so the existing CountCleanupDefersOpenMountedTempUntilBackingHandleCloses case fails on the old code instead of depending on allocator behaviour. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…test target evict_mount_points() had the same release-before-unlist order as invalidate(). A cached mount of a temp file whose deletion was deferred is deleted while it is released, and the delete walked a mount_points list that still held it. New test covers it. Move AddressSanitizer out of the default filemanager test build into 'make -C software/filemanager/tests asan' (env -u LD_PRELOAD, detect_leaks=0, as the image mount step in build.yml). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
chrisgleissner
self-requested a review
November 10, 2026 12:30
Collaborator
|
@JC-000 thanks for the fix, now merged. Review: unlisting a mount before releasing it matches the existing remove-then-release pattern in One open point, not blocking: |
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.
Fixes #1050
Problem
On #1041 a maintainer reported that
make host_testsstops atsoftware/filemanager/tests/temp_auto_cleanup_test.cppwith SIGSEGV, so the suites listed after filemanager never run in CI. It does not crash on every machine (it passes here on macOS and on Ubuntu 24.04 / gcc 13.3, aarch64), because it reads freed memory and only faults depending on the allocator. Under AddressSanitizer it is a deterministic heap-use-after-free.The maintainer's bisect on #1041 points at #931 (94a5f62). It is not only a test problem. The same code runs on the device (by code inspection; not reproduced on a device): detaching a root entry (
remove_root_entry) or mounting a ninth image (cache eviction) can read a freedFilewhen the mounted image is a managed temp file whose deletion was deferred.Cause, on current master:
Two places release a mount while it is still in
mount_points:FileManager::invalidate(software/filemanager/filemanager.cc:415) callsrelease_mount_point(m)and only thenmark_for_removal(i)(:416).FileManager::evict_mount_points(:1110) callsrelease_mount_point(mount_points[victim])and only thenmark_for_removal(victim)(:1111).release_mount_point(:298) callsfcloseon the mount's backing file.fclosecloses and frees the file (:1006), and when the temp had a pending delete-on-last-close it then callsdelete_file(:1013). That reachesin_use_for_writing(:1165) anddiscard_mounts_of_file, which walksmount_pointsand callsmp->get_file()->get_path()(:1154) on the mount being released, whose file was just freed.What changed and why
Remove the mount from
mount_pointsbefore releasing it, in both places, and rescan from the start since the release can drop other mounts. The branch also adds amake -C software/filemanager/tests asantarget (ASan,env -u LD_PRELOAD ASAN_OPTIONS=detect_leaks=0, as the existing image mount step) and a CI step that runs it — that CI step has only been run locally (make asan), not yet in GitHub Actions, so it guards nothing until it has run there. The defaultmake host_testsbuild is unchanged.Products. the code is shared by the Ultimate 64, Ultimate 64 Elite II, C64 Ultimate and the Ultimate-II cartridges (U2+, U2+L). Host only.
How I tested it
Host: macOS, with the device-free tests run in an Ubuntu 24.04 container (g++ 13.3). The hardware runs used the test harness from the same machine.
Host tests (device-free, run before and after the change):
make -C software/filemanager/tests asandiscard_mounts_of_file; each of the two fixes alone leaves the other test failingHardware.
None: host only. The AddressSanitizer report is in the issue.
Standard profile (
./run-tests --profile standard), red = master, green = a build carrying this landing set of fixes (this change included), report frompython3 tools/e2e_report.py:iec-partition-config: it stops at a key-send step because the upstream test's REST backend has noF2key alias (rest_backend.py:556), a test-side limitation, not an app difference.iec-partition-config, here at a "menu screen unavailable" step that also fails on master, so it is not from these changes.Soaks pass on both devices: mount-cache-leak — the soak that exercises exactly this mount-after-mount release path — plus listener-soak and network-connection.
Untested
make asan), not in GitHub Actions; it assumesmy_docker_imagedoes not force anLD_PRELOAD.make host_testsstill stops later atrecoverymanifestin my container (no ESP-IDF there); unrelated.Written with Claude Opus 5.5 in Claude Code.