Skip to content

DAOS-19017 gurt: fix d_aligned_alloc size constraint violation#18423

Open
knard38 wants to merge 3 commits into
masterfrom
ckochhof/fix/master/daos-19017/patch-001
Open

DAOS-19017 gurt: fix d_aligned_alloc size constraint violation#18423
knard38 wants to merge 3 commits into
masterfrom
ckochhof/fix/master/daos-19017/patch-001

Conversation

@knard38
Copy link
Copy Markdown
Contributor

@knard38 knard38 commented Jun 3, 2026

Description

Problem

d_aligned_alloc() was passing size directly to aligned_alloc() without ensuring it was a multiple of alignment. The C11 standard (§7.22.3.1) requires this; violating it is undefined behaviour. ASAN aborts immediately on non-compliant sizes, while musl silently returns NULL.

Fix

Round size up to the next multiple of alignment before calling aligned_alloc() using the existing D_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_alloc is added to src/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:

$ LD_LIBRARY_PATH=/mnt/daos_scratch/kochhofe/daos-install/install/lib64 \
  ASAN_OPTIONS=detect_leaks=0 \
  /var/tmp/daos-build/daos/debug/gcc/src/gurt/tests/test_gurt \
  --filter test_gurt_aligned_alloc
[==========] Running 31 test(s).
...
[ RUN      ] test_gurt_aligned_alloc
[       OK ] test_gurt_aligned_alloc
...
[  PASSED  ] 31 test(s).

Steps for the author:

  • Commit message follows the guidelines.
  • Appropriate Features or Test-tag pragmas were used.
  • Appropriate Functional Test Stages were run.
  • At least two positive code reviews including at least one code owner from each category referenced in the PR.
  • Testing is complete. If necessary, forced-landing label added and a reason added in a comment.

After all prior steps are complete:

  • Gatekeeper requested (daos-gatekeeper added as a reviewer).

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>
@knard38 knard38 self-assigned this Jun 3, 2026
@knard38 knard38 marked this pull request as ready for review June 3, 2026 13:11
@knard38 knard38 requested a review from a team as a code owner June 3, 2026 13:11
@knard38 knard38 requested review from gnailzenh, liw and wangshilong June 3, 2026 13:13
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Ticket title is 'd_aligned_alloc violates C11 aligned_alloc size constraint'
Status is 'In Review'
Labels: 'asan'
https://daosio.atlassian.net/browse/DAOS-19017

@daosbuild3
Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants