Skip to contentSkip to conversation

Make LIST_POISON less deadly (v3)

PATCH In review Avi Kivity 3 participants 4 messages May 20, 2008 x86

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 Make LIST_POISON less deadly (v3)

The list macros use LIST_POISON1 and LIST_POISON2 as undereferencable pointers in order to trap erronous use of freed list_heads. Unfortunately userspace can arrange for those pointers to actually be dereferencable, potentially turning an oops to an expolit.

To avoid this allow architectures (currently x86_64 only) to override the default values for these pointers with truly-undereferncable values. This is easy on x86_64 as the virtual address space is large and contains unmapped ranges.

---

Changes since v1:
- add CONFIG_ILLEGAL_POINTER_VALUE instead of new header <asm/poison.h>

Changes since v2:
- switched the range from an uncanonical address to a canonical unmapped address, since uncannonical addresses generate #GP instead of #PF, losing the faulting address.

 arch/x86/Kconfig       |    5 +++++
 include/linux/poison.h |   10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
arch/x86/Kconfig +5 -0
index fe361ae..54d4e36 100644
@@ -1021,6 +1021,11 @@ config ARCH_MEMORY_PROBE
 	def_bool X86_64
 	depends on MEMORY_HOTPLUG
 
+config ILLEGAL_POINTER_VALUE
+       hex
+       default 0 if X86_32
+       default 0xffffc10000000000 if X86_64
+
 source "mm/Kconfig"
 
 config HIGHPTE
include/linux/poison.h +8 -2
index 9f31683..0d105a5 100644
@@ -1,14 +1,20 @@
 #ifndef _LINUX_POISON_H
 #define _LINUX_POISON_H
 
+#ifdef CONFIG_ILLEGAL_POINTER_VALUE
+#define POISON_POINTER_DELTA CONFIG_ILLEGAL_POINTER_VALUE
+#else
+#define POISON_POINTER_DELTA 0L
+#endif
+
 /********** include/linux/list.h **********/
 /*
  * These are non-NULL pointers that will result in page faults
  * under normal circumstances, used to verify that nobody uses
  * non-initialized list entries.
  */
-#define LIST_POISON1  ((void *) 0x00100100)
-#define LIST_POISON2  ((void *) 0x00200200)
+#define LIST_POISON1  ((void *) 0x00100100 + POISON_POINTER_DELTA)
+#define LIST_POISON2  ((void *) 0x00200200 + POISON_POINTER_DELTA)
 
 /********** include/linux/timer.h **********/
 /*
Signature · 1 line
1.5.5.1
#1 lore raw
Quoted 9 lines · Avi Kivity

The list macros use LIST_POISON1 and LIST_POISON2 as undereferencable pointers in order to trap erronous use of freed list_heads. Unfortunately userspace can arrange for those pointers to actually be dereferencable, potentially turning an oops to an expolit.

To avoid this allow architectures (currently x86_64 only) to override the default values for these pointers with truly-undereferncable values. This is easy on x86_64 as the virtual address space is large and contains unmapped ranges.

looks good - thanks Avi - i've added your patch to the -tip tree. I have opened a separate topic for it: tip/safe-poison-pointers. (because it affects other architectures as well)

Ingo

#2 lore raw
In reply to Avi Kivity

arch/x86/Kconfig config ARCH_MEMORY_PROBE · line 1027

Quoted 5 lines · Avi Kivity
arch/x86/Kconfig +4 -0
+config ILLEGAL_POINTER_VALUE
+       hex
+       default 0 if X86_32
+       default 0xffffc10000000000 if X86_64

Don't make it exactly 0xffffc10000000000 but 0xffffc10000000000 + 0x1000000 or so, otherwise list_entry() users which subtract offsets would still end up in user space and there might be actually something in there by default.

-Andi

author
#3 lore raw
Quoted 9 lines · Andi Kleen

arch/x86/Kconfig config ARCH_MEMORY_PROBE · line 1027

Quoted 6 lines · Avi Kivity
arch/x86/Kconfig +4 -0
+config ILLEGAL_POINTER_VALUE
+       hex
+       default 0 if X86_32
+       default 0xffffc10000000000 if X86_64
Quoted 5 lines

Don't make it exactly 0xffffc10000000000 but 0xffffc10000000000 + 0x1000000 or so, otherwise list_entry() users which subtract offsets would still end up in user space and there might be actually something in there by default.

The poison code adds a large offset (>1MB) so we're safe here.

Signature · 1 line
error compiling committee.c: too many arguments to function