Bug 474339 - aligned_alloc with alignment less than VG_MIN_MALLOC_SZB causes Valgrind to panic
Summary: aligned_alloc with alignment less than VG_MIN_MALLOC_SZB causes Valgrind to p...
Status: RESOLVED DUPLICATE of bug 474332
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (other bugs)
Version First Reported In: unspecified
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-09 13:44 UTC by Stefano Bonicatti
Modified: 2023-09-09 19:48 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefano Bonicatti 2023-09-09 13:44:50 UTC
SUMMARY

This is somewhat connected to https://bugs.kde.org/show_bug.cgi?id=474332, because if I do a workaround for this here: https://sourceware.org/git/?p=valgrind.git;a=blob;f=coregrind/m_mallocfree.c;h=44beb3d8b57cc3d7859a2966b4f5824e255fb6d4;hb=23250889de4e2079ad1ede6874cc824bc9dd92db#l2258, by removing the panic and setting req_alignB to VG_MIN_MALLOC_SZB, I hit the other issue.

I'm using Valgrind on master, at commit: d4c9a98527afdbd67b25a1300339a42b9e0a24c2

STEPS TO REPRODUCE
1. Compile and run the following C snippet:

#include <stdlib.h>
#include <stdio.h>

int main() {
    char *p = aligned_alloc(4, 4);

    if(p == NULL) {
        printf("Allocation failed!\n");     
        return 1;
    }

    printf("Allocation succeeded!\n");

    return 0;
}

2. Then run it again under Valgrind

OBSERVED RESULT

The allocation succeeds when run on its own, but with Valgrind fails:

VG_(arena_memalign)(0x58889810, 4, 4)
bad alignment value 4
(it is too small, below the lower limit of 16)
valgrind: the 'impossible' happened:
   VG_(arena_memalign)
 
EXPECTED RESULT

Both succeeds.

ADDITIONAL INFORMATION

The issue seems to be similar to the other bug I linked above, but here the requirement on the alignment seems to be more strict and actually connected to what's required from malloc, but not aligned_alloc, which again is implementation dependent and on glibc the only limit seems to be that it has to be a power of 2.
Comment 1 Paul Floyd 2023-09-09 19:48:46 UTC
This is the same as 474332.

*** This bug has been marked as a duplicate of bug 474332 ***