ANDROID: 16K: mlock: __PAGE_ALIGN addr and len

In page-compat mode, mlock() syscalls must be at __PAGE_ALIGN-ed
addresses and of __PAGE_SIZE-multiple length.

Bug: 383389337
Bug: 315325080
Bug: 302403436
Change-Id: Iddc74af7c3f7fbd5051b3f1537155dda513405ad
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This commit is contained in:
Kalesh Singh
2023-11-20 11:51:28 -08:00
committed by Carlos Llamas
parent 4956d7c6c4
commit 7852452429

View File

@@ -25,6 +25,7 @@
#include <linux/memcontrol.h>
#include <linux/mm_inline.h>
#include <linux/secretmem.h>
#include <linux/page_size_compat.h>
#include "internal.h"
@@ -518,8 +519,8 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
struct vm_area_struct *vma, *prev;
VMA_ITERATOR(vmi, current->mm, start);
VM_BUG_ON(offset_in_page(start));
VM_BUG_ON(len != PAGE_ALIGN(len));
VM_BUG_ON(__offset_in_page_log(start));
VM_BUG_ON(len != __PAGE_ALIGN(len));
end = start + len;
if (end < start)
return -EINVAL;
@@ -620,8 +621,8 @@ static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t fla
if (!can_do_mlock())
return -EPERM;
len = PAGE_ALIGN(len + (offset_in_page(start)));
start &= PAGE_MASK;
len = __PAGE_ALIGN(len + (__offset_in_page(start)));
start &= __PAGE_MASK;
lock_limit = rlimit(RLIMIT_MEMLOCK);
lock_limit >>= PAGE_SHIFT;
@@ -680,8 +681,8 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
start = untagged_addr(start);
len = PAGE_ALIGN(len + (offset_in_page(start)));
start &= PAGE_MASK;
len = __PAGE_ALIGN(len + (__offset_in_page(start)));
start &= __PAGE_MASK;
if (mmap_write_lock_killable(current->mm))
return -EINTR;