ANDROID: 16K: __PAGE_ALIGN stack_[top|base]

In page-compat mode, align the stack top / base by the emulated
page-size.

Bug: 383389337
Bug: 315325080
Bug: 302403436
Change-Id: I46e08a3b99842e7810866f48a2f53365c0bbd2bc
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This commit is contained in:
Kalesh Singh
2024-02-08 23:31:09 -08:00
committed by Carlos Llamas
parent ba166bce2c
commit a9e38ff89a

View File

@@ -38,6 +38,7 @@
#include <linux/sched/signal.h>
#include <linux/sched/numa_balancing.h>
#include <linux/sched/task.h>
#include <linux/page_size_compat.h>
#include <linux/pagemap.h>
#include <linux/perf_event.h>
#include <linux/highmem.h>
@@ -283,7 +284,7 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
*/
BUILD_BUG_ON(VM_STACK_FLAGS & VM_STACK_INCOMPLETE_SETUP);
vma->vm_end = STACK_TOP_MAX;
vma->vm_start = vma->vm_end - PAGE_SIZE;
vma->vm_start = vma->vm_end - __PAGE_SIZE;
vm_flags_init(vma, VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP);
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
@@ -745,14 +746,14 @@ int setup_arg_pages(struct linux_binprm *bprm,
if (vma->vm_end - vma->vm_start > stack_base)
return -ENOMEM;
stack_base = PAGE_ALIGN(stack_top - stack_base);
stack_base = __PAGE_ALIGN(stack_top - stack_base);
stack_shift = vma->vm_start - stack_base;
mm->arg_start = bprm->p - stack_shift;
bprm->p = vma->vm_end - stack_shift;
#else
stack_top = arch_align_stack(stack_top);
stack_top = PAGE_ALIGN(stack_top);
stack_top = __PAGE_ALIGN(stack_top);
if (unlikely(stack_top < mmap_min_addr) ||
unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
@@ -822,7 +823,7 @@ int setup_arg_pages(struct linux_binprm *bprm,
* Align this down to a page boundary as expand_stack
* will align it up.
*/
rlim_stack = bprm->rlim_stack.rlim_cur & PAGE_MASK;
rlim_stack = bprm->rlim_stack.rlim_cur & __PAGE_MASK;
stack_expand = min(rlim_stack, stack_size + stack_expand);