[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240710054558.1959243-1-jianghaoran@kylinos.cn>
Date: Wed, 10 Jul 2024 13:45:58 +0800
From: Haoran Jang <jianghaoran@...inos.cn>
To: linux-mm@...ck.org
Cc: linux-kernel@...r.kernel.org,
lstoakes@...il.com,
vbabka@...e.cz,
Liam.Howlett@...cle.com,
akpm@...ux-foundation.org,
Haoran Jiang <jianghaoran@...inos.cn>
Subject: [PATCH] mm/mmap: Align the length parameter of munmap with hugepage size
From: Haoran Jiang <jianghaoran@...inos.cn>
munmap hugepge mappings, if the length of the range to munmap
is not aligned with hugepage size,munmap will fail.
In the hugetlb_vm_op_split function, an error will be returned
if startaddr+len is not hugepage size aligned.
before this patch:
in "tools/testing/selftests/mm/hugepage-mremap.c"
modify DEFAULT_LENGTH_MB to 3M,compile and run,
the following error message is displayed
-------------------------
running ./hugepage-mremap
-------------------------
TAP version 13
1..1
Map haddr: Returned address is 0x7eaa40000000
Map daddr: Returned address is 0x7daa40000000
Map vaddr: Returned address is 0x7faa40000000
Address returned by mmap() = 0x7cb34b000000
Mremap: Returned address is 0x7faa40000000
First hex is 0
First hex is 3020100
Bail out! mremap: Expected failure, but call succeeded
Signed-off-by: Haoran Jiang <jianghaoran@...inos.cn>
---
mm/mmap.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 83b4682ec85c..0b3a60bf9b6f 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2733,7 +2733,15 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm,
if ((offset_in_page(start)) || start > TASK_SIZE || len > TASK_SIZE-start)
return -EINVAL;
- end = start + PAGE_ALIGN(len);
+ vma = find_vma(mm, start);
+ if (!vma) {
+ if (unlock)
+ mmap_write_unlock(mm);
+ return 0;
+ }
+
+ end = start + ALIGN(len, vma_kernel_pagesize(vma));
+
if (end == start)
return -EINVAL;
--
2.43.0
Powered by blists - more mailing lists