Skip to content

Commit

Permalink
x86/compat: fix error-check for compat mmap()
Browse files Browse the repository at this point in the history
Raw sys_mmap() returns address or error like -ENOMEM.
Don't check MAP_FAILED, check that result is aligned by page.

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
  • Loading branch information
0x7f454c46 committed Jan 18, 2017
1 parent 75e8e9c commit d6bcd38
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions criu/arch/x86/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ static inline void *alloc_compat_syscall_stack(void)
void *mem = (void*)sys_mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_32BIT | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

if (mem == MAP_FAILED)
if ((uintptr_t)mem % PAGE_SIZE) {
int err = (~(uint32_t)(uintptr_t)mem) + 1;

pr_err("mmap() of compat syscall stack failed with %d\n", err);
return 0;
}
return mem;
}

Expand All @@ -26,7 +30,7 @@ static inline void free_compat_syscall_stack(void *mem)
long int ret = sys_munmap(mem, PAGE_SIZE);

if (ret)
pr_err("munmap of compat addr %p failed with %ld", mem, ret);
pr_err("munmap() of compat addr %p failed with %ld", mem, ret);
}

#ifdef CONFIG_COMPAT
Expand Down

0 comments on commit d6bcd38

Please sign in to comment.