[Bug malloc/23852] New: posix_memalign returns an address currently mmap

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug malloc/23852] New: posix_memalign returns an address currently mmap

cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23852

            Bug ID: 23852
           Summary: posix_memalign returns an address currently mmap
           Product: glibc
           Version: 2.27
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: malloc
          Assignee: unassigned at sourceware dot org
          Reporter: support at heidef dot com
  Target Milestone: ---

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>

int main(int argc, char**argv) {
        void *a = 0;
        void *m = 0;

        posix_memalign(&a, getpagesize(), 4169);
        printf("posix1 = %p, usable = %d, errno = %d\n", a,
(int)malloc_usable_size(a), errno);
        free(a);

        /* Change to PROT_READ|PROT_WRITE if you dont't want the SIGSEGV */
        m = mmap(a, getpagesize(), PROT_NONE,
MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
        printf("mmap = %p, errno = %d\n", m, errno);

        a = 0;
        posix_memalign(&a, getpagesize(), 1024);
        printf("posix2 = %p, usable = %d, errno = %d\n", a,
(int)malloc_usable_size(a), errno);

        return 0;
}

Tried this with various glibc versions from 2.12 to 2.27 on different distros.
The allocation sizes have a play but haven't figured out the exact relationship
yet.  In this example, if you change the first posix_memalign size to 4168 on
Debian with 2.24, then it doesn't crash but does at 4169 bytes.  However, on
Fedora with 2.27, changing it to 4168 still causes a SIGSEGV.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug malloc/23852] posix_memalign returns an address currently mmap

cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23852

Andreas Schwab <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andreas Schwab <[hidden email]> ---
You are clobbering the properties of an existing, in-use memory mapping.

--
You are receiving this mail because:
You are on the CC list for the bug.