Thanks.
For the record, here is an ugly patch that deactivates half of stack randomization for all programs
(actually seem easier in this case) and makes the rest controlled by paxctl. The result is good for my purpose
and I leave it there in case it could be useful to someone else (that hopefully understand that this patch has
no other point than actually reducing the security of the system...).
- Code: Select all
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index be797cf..c22cfad 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1016,7 +1016,8 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
#endif
if ((current->flags & PF_RANDOMIZE) &&
- !(current->personality & ADDR_NO_RANDOMIZE)) {
+ !(current->personality & ADDR_NO_RANDOMIZE)
+ && current->mm->pax_flags & MF_PAX_RANDMMAP) {
random_variable = (unsigned long) get_random_int();
random_variable &= STACK_RND_MASK;
random_variable <<= PAGE_SHIFT;
@@ -1282,7 +1283,8 @@ static int load_elf_binary(struct linux_binprm *bprm)
if (elf_read_implies_exec(loc->elf_ex, executable_stack))
current->personality |= READ_IMPLIES_EXEC;
- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
+ if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space
+ && current->mm->pax_flags & MF_PAX_RANDMMAP)
current->flags |= PF_RANDOMIZE;
setup_new_exec(bprm);
diff --git a/fs/exec.c b/fs/exec.c
index 122301f..5a26c33 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -322,11 +322,6 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
up_write(&mm->mmap_sem);
bprm->p = vma->vm_end - sizeof(void *);
-#ifdef CONFIG_PAX_RANDUSTACK
- if (randomize_va_space)
- bprm->p ^= prandom_u32() & ~PAGE_MASK;
-#endif
-
return 0;
err:
up_write(&mm->mmap_sem);