linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/vmalloc: Sanitize __get_vm_area() arguments
@ 2020-04-03 16:32 Peter Zijlstra
  2020-04-03 18:18 ` Uladzislau Rezki
  2020-04-06 13:01 ` Christoph Hellwig
  0 siblings, 2 replies; 16+ messages in thread
From: Peter Zijlstra @ 2020-04-03 16:32 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-mm, jroedel, vbabka, urezki, Thomas Gleixner


__get_vm_area() is an exported symbol, make sure the callers stay in
the expected memory range. When calling this function with memory
ranges outside of the VMALLOC range *bad* things can happen.

(I noticed this when I managed to corrupt the kernel text by accident)

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 mm/vmalloc.c |    7 +++++++
 1 file changed, 7 insertions(+)

--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2130,6 +2130,13 @@ static struct vm_struct *__get_vm_area_n
 struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
 				unsigned long start, unsigned long end)
 {
+	/*
+	 * Ensure callers stay in the vmalloc range.
+	 */
+	if (WARN_ON(start < VMALLOC_START || start > VMALLOC_END ||
+		    end < VMALLOC_START || end > VMALLOC_END))
+		return NULL;
+
 	return __get_vm_area_node(size, 1, flags, start, end, NUMA_NO_NODE,
 				  GFP_KERNEL, __builtin_return_address(0));
 }


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re:   [PATCH] mm/vmalloc: Sanitize __get_vm_area() arguments
@ 2020-04-04 15:35 William Kucharski
  2020-04-04 18:52 ` Uladzislau Rezki
  0 siblings, 1 reply; 16+ messages in thread
From: William Kucharski @ 2020-04-04 15:35 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Andrew Morton, linux-kernel, linux-mm, jroedel, vbabka, urezki,
	Thomas Gleixner

Is there any need to similarly sanitize “size” to assure start + size doesn’t go past “end?”

> On Apr 3, 2020, at 10:33, Peter Zijlstra <peterz@infradead.org> wrote:
> 
> 
> __get_vm_area() is an exported symbol, make sure the callers stay in
> the expected memory range. When calling this function with memory
> ranges outside of the VMALLOC range *bad* things can happen.



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

end of thread, other threads:[~2020-04-17 13:38 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-03 16:32 [PATCH] mm/vmalloc: Sanitize __get_vm_area() arguments Peter Zijlstra
2020-04-03 18:18 ` Uladzislau Rezki
2020-04-03 18:53   ` Peter Zijlstra
2020-04-04 19:00     ` Uladzislau Rezki
2020-04-06 13:01 ` Christoph Hellwig
2020-04-06 14:06   ` Peter Zijlstra
2020-04-17 12:57   ` Sakari Ailus
2020-04-17 13:14     ` Peter Zijlstra
2020-04-17 13:38       ` Sakari Ailus
2020-04-04 15:35 William Kucharski
2020-04-04 18:52 ` Uladzislau Rezki
2020-04-05  5:25   ` William Kucharski
2020-04-05 17:23     ` Uladzislau Rezki
2020-04-05 19:21       ` Uladzislau Rezki
2020-04-05 20:49         ` William Kucharski
2020-04-06 12:59           ` Uladzislau Rezki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).