GNU bug report logs - #47429
allocating JIT code buffer failed: Permission denied

Previous Next

Package: guile;

Reported by: noloader <at> gmail.com

Date: Fri, 26 Mar 2021 22:49:02 UTC

Severity: normal

Full log


Message #11 received at 47429 <at> debbugs.gnu.org (full text, mbox):

From: Jeffrey Walton <noloader <at> gmail.com>
To: 47429 <at> debbugs.gnu.org
Subject: Re 47429:allocating JIT code buffer failed: Permission denied
Date: Fri, 26 Mar 2021 19:34:24 -0400
Dammit, check for the proper return value...

% cat mmap-test.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
int main(int argc, char* argv[])
{
    size_t len = 10;
    int prot = PROT_EXEC | PROT_READ | PROT_WRITE;
    int flags = MAP_PRIVATE | MAP_ANONYMOUS;

    void *p = mmap (NULL, len, prot, flags, -1, 0);
    int err = errno;

    if (p != (void*) -1) {
        printf("p is good\n");
        munmap(p, len);
    }
    else {
        printf("p is bad (%d)\n", err);
    }

    return 0;
}

% clang -Wall mmap-test.c -o mmap-test.exe
% ./mmap-test.exe
p is bad (13)

That is the permission denied.

Next, avoid W+X:

% cat mmap-test.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
int main(int argc, char* argv[])
{
    size_t len = 10;
    int prot = /*PROT_EXEC |*/ PROT_READ | PROT_WRITE;
    int flags = MAP_PRIVATE | MAP_ANONYMOUS;

    void *p = mmap (NULL, len, prot, flags, -1, 0);
    int err = errno;

    if (p != (void*) -1) {
        printf("p is good\n");
        munmap(p, len);
    }
    else {
        printf("p is bad (%d)\n", err);
    }

    return 0;
}

It looks like W^X is the culprit.

Jeff




This bug report was last modified 4 years and 80 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.