fix(rocthrust): harden HIPSTDPAR allocation interposition - #11498
Draft
sstamenk wants to merge 2 commits into
Draft
fix(rocthrust): harden HIPSTDPAR allocation interposition#11498sstamenk wants to merge 2 commits into
sstamenk wants to merge 2 commits into
Conversation
Validate allocation arithmetic and alignment, preserve libc and C++ allocation contracts, and clean up failed allocations in both interposer versions. Add behavioral coverage for calloc, reallocarray, aligned allocation, new/delete, mmap, and forced-v0 execution. JIRA: SWSPLAT-24312
Keep null free, zero-size new, and sized delete calls visible under optimization, and clarify zero-size calloc expectations.
❌ PR Check — Action Required
📖 Need help? See the Policy FAQ for details on every check and how to fix failures. |
|
🚫 Please fix the failed policies before requesting reviews. The following policy checks failed:
The |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #11498 +/- ##
===========================================
+ Coverage 69.65% 69.72% +0.07%
===========================================
Files 2753 2783 +30
Lines 453403 455349 +1946
Branches 66800 67109 +309
===========================================
+ Hits 315806 317479 +1673
- Misses 117321 117558 +237
- Partials 20276 20312 +36
*This pull request uses carry forward flags. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
Validate allocation arithmetic and alignment, preserve libc and C++ allocation contracts, and clean up failed allocations in both interposer versions.
Add behavioral coverage for
calloc,reallocarray, aligned allocation,new/delete,mmap, and forced-v0 execution.JIRA: SWSPLAT-24312
Motivation
HIPSTDPAR allocation interposition did not check
callocmultiplication overflow and could pass a null allocation tomemset. This could cause undersized allocations, memory corruption, or crashes when allocation sizes are attacker-controlled.The surrounding allocation shims also had incomplete libc, POSIX, and C++ allocation semantics. This PR hardens both the current v1 interposer and the legacy v0 fallback while adding behavioral regression coverage.
Technical Details
callocandreallocarraysize calculations withENOMEM.reallocarrayrejects an overflowing request.hipMallocManagedfailures safely through the PMR allocation boundary.std::align.posix_memalignbehavior:0on success;EINVALfor invalid alignment;ENOMEMon allocation failure;errnoand the output pointer on failure.operator newrequests;std::new_handler;std::bad_alloc;nullptrfrom nothrow overloads.free(nullptr)a no-op.hipMemAdvisefails.MAP_FAILEDsemantics and clean up mappings on v1 setup failure.freeandmunmapstill execute when HIP un-advice fails.__HIPSTDPAR_INTERPOSE_ALLOC_V1__.Test Plan
test_interposetest_calloctest_reallocdevelop.Test Result
MALLOC_CHECK_=3andMALLOC_PERTURB_=165passed.developbuilt and tested without conflicts.git diff --checkpassed.Submission Checklist