Skip to content

panic with MMU=y if /dev/shm is mounted noexec #606

@ddiss

Description

@ddiss

This isn't so much a bug report as it is a usability / debugging issue...

In arch/lkl/mm/mmu_mem.c we have:

 41 void mmap_pages_for_ptes(unsigned long va, unsigned int nr, pte_t pte)             
 42 {
 43         // TODO: At the moment we mmap memory as RWX. However, we should mmap pages
 44         // with proper access flags (read-only, read-write, etc)                   
 45         enum lkl_prot prot = LKL_PROT_READ | LKL_PROT_WRITE | LKL_PROT_EXEC;       
 46         unsigned long pa = pte.pte & PAGE_MASK;                                    
 47         unsigned long pg_off = pa - (ARCH_PFN_OFFSET << PAGE_SHIFT);               
 48 
 49         void *res = lkl_ops->shmem_mmap((void *)va, pg_off, PAGE_SIZE * nr, prot); 
 50 
 51         BUG_ON(res != (void *)va);

Where the posix-host.c shmem_mmap is:

static void *lkl_shmem_mmap(void *addr, unsigned long pg_off,
                unsigned long size, enum lkl_prot mem_prot_flags)
{
        int prot = get_prot(mem_prot_flags);
        int flags = MAP_SHARED | MAP_FIXED_NOREPLACE;
        void *ret = mmap(addr, size, prot, flags, shared_mem_fd, pg_off);

mmap can fail with EPERM if /dev/shm is mounted with the noexec mount option, as is common during e.g. Dracut initramfs early-boot:

openat(AT_FDCWD, "/dev/shm/lkl_phys_mem_288", O_RDWR|O_CREAT|O_NOFOLLOW|O_CLOEXEC, 0700) = 3
mmap(0x4ffef000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_FIXED_NOREPLACE, 3, 0x1f78000) = -1 EPERM
BUG: failure at arch/lkl/mm/mmu_mem.c:54/mmap_pages_for_ptes()!

Ideally we should be able to detect this case and give a more user-friendly error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions