python: fail fast when the --oom-foreign shim is shadowed (no-op injection)#195
Merged
Merged
Conversation
…ction) `--oom-foreign` preloads a malloc-failure shim (fusil_malloc_shim.c) to inject allocation failures at the C malloc() layer, reaching foreign C libraries (HDF5, ...). But against a **statically-linked AddressSanitizer** target this silently does nothing: ASan defines/exports its own malloc in the executable, which sits ahead of LD_PRELOAD in the global symbol scope and shadows the shim. The emitted harness only checks that the *control symbol* resolves (it does), not that interposition actually happens -- so the whole run injects zero failures with no error. An h5py ASan fleet ran thousands of sessions this way, finding nothing, because no OOM was ever injected. Add a startup self-check: `probe_shim_effective(python, shim)` runs a tiny probe in the *target* interpreter (arm the shim, malloc, read the shim's own allocation counter). A nonzero count proves the shim is on the allocation path; zero proves it's shadowed. The --oom-foreign setup aborts with a loud, actionable `ShimShadowedError` (use a non-ASan target, or -shared-libasan + verify_asan_link_order=0) instead of running a no-op campaign. An inconclusive probe (couldn't run / no marker) is non-fatal -- it only blocks on a definitive count==0. Verified: aborts on the ASan target, prints "interception verified" and proceeds on a non-ASan target. +5 tests (pure parse + skip-guarded probe). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
--oom-foreignpreloads a malloc-failure shim (fusil_malloc_shim.c) to inject allocation failures at the Cmalloc()layer, reaching foreign C libraries (HDF5, zstd, ...). Against a statically-linked AddressSanitizer target this silently does nothing: ASan defines/exports its ownmallocin the executable, which sits ahead ofLD_PRELOADin the global symbol scope and shadows the shim. The emitted harness only checks that the shim's control symbol resolves (it does), not that interposition actually happens — so the whole run injects zero failures with no error.This bit us for real: an h5py ASan fleet ran thousands of sessions finding nothing, because no OOM was ever injected. Proven empirically — on the ASan target the shim's
malloccounter stays0(never called); on a non-ASan python the identical shim works (4/8 injected failures).Fix
Add a startup self-check.
probe_shim_effective(python, shim)runs a tiny probe in the target interpreter (arm the shim,malloca few times, read the shim's own allocation counter, which only increments from inside the shim's malloc):TrueFalseNone(inconclusive, non-fatal)The
--oom-foreignsetup aborts with a loud, actionableShimShadowedErroron a definitiveFalse, instead of running a no-op campaign:An inconclusive probe is non-fatal (only a definitive
count==0blocks), so probe flakiness can't cause a false abort.Verification
Foreign-OOM: shim interception verifiedand proceeds on a non-ASan target._parse_probe_count+ skip-guardedprobe_shim_effective):test_foreign_oomgreen (8 tests). Full OOM group green (24).ruff check(whole tree) +ruff format --checkclean.🤖 Generated with Claude Code