diff --git a/mm/mmap.c b/mm/mmap.c
index 7fa6759322d1f2aa39f9dc2c497e714a8d9566f0..f19efcf7541878093eb3c3323a597cf8d1da5ae2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2231,7 +2231,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
 
 	/* Guard against exceeding limits of the address space. */
 	address &= PAGE_MASK;
-	if (address >= TASK_SIZE)
+	if (address >= (TASK_SIZE & PAGE_MASK))
 		return -ENOMEM;
 	address += PAGE_SIZE;