Skip to contentSkip to conversation

misc: lkdtm: Add volatile to intentional NULL pointer reference

PATCH In review Matthias Kaehlcke 2 participants 2 messages Apr 14, 2017 – Apr 15, 2017 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: lkdtm: Add volatile to intentional NULL pointer reference

From: Michael Davidson <[email protected]>

Add a volatile qualifier where a NULL pointer is deliberately dereferenced to trigger a panic.

Without the volatile qualifier clang will issue the following warning:
"indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference]" and replace the pointer reference with a __builtin_trap() (which generates a ud2 instruction on x86_64).

---
 drivers/misc/lkdtm_bugs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/lkdtm_bugs.c +1 -1
index e3f4cd8876b5..d734d75afade 100644
@@ -67,7 +67,7 @@ void lkdtm_WARNING(void)
 
 void lkdtm_EXCEPTION(void)
 {
-	*((int *) 0) = 0;
+	*((volatile int *) 0) = 0;
 }
 
 void lkdtm_LOOP(void)
Signature · 1 line
2.12.2.762.g0e3151a226-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Matthias Kaehlcke

From: Michael Davidson <[email protected]>

Add a volatile qualifier where a NULL pointer is deliberately dereferenced to trigger a panic.

Quoted 7 lines

Without the volatile qualifier clang will issue the following warning:
"indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference]" and replace the pointer reference with a __builtin_trap() (which generates a ud2 instruction on x86_64).

Thanks!

Greg, please add this to drivers/misc when you get a chance. :)

-Kees

Quoted 20 lines
---
 drivers/misc/lkdtm_bugs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/lkdtm_bugs.c +1 -2
index e3f4cd8876b5..d734d75afade 100644
@@ -67,7 +67,7 @@ void lkdtm_WARNING(void)
 
 void lkdtm_EXCEPTION(void)
 {
-       *((int *) 0) = 0;
+       *((volatile int *) 0) = 0;
 }
 
 void lkdtm_LOOP(void)
--

2.12.2.762.g0e3151a226-goog

Signature · 2 lines
Kees Cook
Pixel Security