Skip to content

Fix unsoundness in InsertMap #1041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025
Merged

Conversation

danielocfb
Copy link
Collaborator

Our InsertMap type is not working correctly in the presence of reallocations of the internally used hash map. Specifically, because our insertion does not require a mutable reference, users may hold references to entries across insertions. If the hash map were to reallocate as part of the insertion, the references would effectively be dangling, which is undefined behavior.
Fix the problem by heap allocating all values in the hash map.

Our InsertMap type is not working correctly in the presence of
reallocations of the internally used hash map. Specifically, because our
insertion does not require a mutable reference, users may hold
references to entries across insertions. If the hash map were to
reallocate as part of the insertion, the references would effectively be
dangling, which is undefined behavior.
Fix the problem by heap allocating all values in the hash map.

Signed-off-by: Daniel Müller <deso@posteo.net>
@danielocfb danielocfb enabled auto-merge (rebase) March 6, 2025 18:01
@danielocfb danielocfb force-pushed the topic/fix-insert-map branch from 9b28a83 to 473654a Compare March 6, 2025 18:02
@danielocfb danielocfb merged commit 2b19dd6 into libbpf:main Mar 6, 2025
38 checks passed
Copy link

codecov bot commented Mar 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.96%. Comparing base (3cd1eb2) to head (473654a).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1041      +/-   ##
==========================================
+ Coverage   94.85%   94.96%   +0.11%     
==========================================
  Files          60       60              
  Lines       11091    11093       +2     
==========================================
+ Hits        10520    10535      +15     
+ Misses        571      558      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danielocfb danielocfb deleted the topic/fix-insert-map branch March 6, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants