public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Fix overflow check in expand_upwards()
@ 2017-06-29 23:02 Jörn Engel
  2017-06-30  6:57 ` Helge Deller
  0 siblings, 1 reply; 5+ messages in thread
From: Jörn Engel @ 2017-06-29 23:02 UTC (permalink / raw)
  To: Helge Deller, Hugh Dickins, linux-kernel

I believe the overflow check was correct, then got subtly broken by
	commit bd726c90b6b8
	Author: Helge Deller <deller@gmx.de>
	Date:   Mon Jun 19 17:34:05 2017 +0200

	    Allow stack to grow up to address space limit

The old overflow check may have been a bit subtle and I suppose Helge
missed its importance.

	if (!address)
		return -ENOMEM;

Functionally the my check is identical to the old one.  I just hope the
alternative form (and comment!) make it harder to miss and break things
in a future patch.

Signed-off-by: Joern Engel <joern@logfs.org>
---
 mm/mmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index a5e3dcd75e79..7366f62c31f4 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2232,7 +2232,8 @@ 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)
+	/* second check is for integer overflow */
+	if (address >= TASK_SIZE || address + PAGE_SIZE < address)
 		return -ENOMEM;
 	address += PAGE_SIZE;
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-30 18:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-29 23:02 [PATCH] mm: Fix overflow check in expand_upwards() Jörn Engel
2017-06-30  6:57 ` Helge Deller
2017-06-30  7:34   ` Helge Deller
2017-06-30 18:26     ` Jörn Engel
2017-06-30 14:51   ` Jörn Engel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox