diff mbox series

[v4,4/4] mm/msync: return ENOMEM if len overflows for msync

Message ID 20230320024739.224850-5-mawupeng1@huawei.com (mailing list archive)
State New
Headers show
Series Add overflow checks for several syscalls | expand

Commit Message

mawupeng March 20, 2023, 2:47 a.m. UTC
From: Ma Wupeng <mawupeng1@huawei.com>

Return -ENOMEM if len overflows for msync.

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 mm/msync.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/mm/msync.c b/mm/msync.c
index ac4c9bfea2e7..8ac227ec38af 100644
--- a/mm/msync.c
+++ b/mm/msync.c
@@ -36,6 +36,7 @@  SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
 	struct vm_area_struct *vma;
 	int unmapped_error = 0;
 	int error = -EINVAL;
+	size_t old_len = len;
 
 	start = untagged_addr(start);
 
@@ -48,7 +49,7 @@  SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
 	error = -ENOMEM;
 	len = (len + ~PAGE_MASK) & PAGE_MASK;
 	end = start + len;
-	if (end < start)
+	if (end < start || (old_len != 0 && len == 0))
 		goto out;
 	error = 0;
 	if (end == start)