DAOS-19017 gurt: fix d_aligned_alloc size constraint violation#18423
Open
knard38 wants to merge 3 commits into
Open
DAOS-19017 gurt: fix d_aligned_alloc size constraint violation#18423knard38 wants to merge 3 commits into
knard38 wants to merge 3 commits into
Conversation
C11 requires size passed to aligned_alloc() to be a multiple of alignment. When it is not, behavior is undefined: ASAN aborts and must returns NULL, preventing DAOS from running under sanitizers. Round size up inside d_aligned_alloc() using D_ALIGNUP before forwarding to aligned_alloc(). Add a regression test covering aligned size, unaligned size, size smaller than alignment, and the zero-initialisation path. Signed-off-by: Cedric Koch-Hofer <cedric.koch-hofer@hpe.com>
|
Ticket title is 'd_aligned_alloc violates C11 aligned_alloc size constraint' |
Collaborator
|
Test stage NLT completed with status UNSTABLE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos//view/change-requests/job/PR-18423/1/testReport/ |
wangshilong
approved these changes
Jun 4, 2026
…/daos-19017/patch-001
…/daos-19017/patch-001
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.
Description
Problem
d_aligned_alloc()was passingsizedirectly toaligned_alloc()without ensuring it was a multiple ofalignment. The C11 standard (§7.22.3.1) requires this; violating it is undefined behaviour. ASAN aborts immediately on non-compliant sizes, while musl silently returnsNULL.Fix
Round
sizeup to the next multiple ofalignmentbefore callingaligned_alloc()using the existingD_ALIGNUP()macro. The rounded-up allocation is always at least as large as the requested size, so callers are unaffected.Regression test
A new cmocka test case
test_gurt_aligned_allocis added tosrc/gurt/tests/test_gurt.c, covering the baseline, the exact bug case from the ticket, and boundary conditions.Local validation with ASAN
This patch was locally validated with running the following command:
Steps for the author:
After all prior steps are complete: