Skip to contentSkip to conversation

PM / Hibernate: Don't let kasan instrument snapshot.c

PATCH New James Morse 2 participants 4 messages Jun 2, 2016 – Jun 16, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / Hibernate: Don't let kasan instrument snapshot.c

Kasan causes the compiler to instrument C code and is used at runtime to detect accesses to memory that has been freed, or not yet allocated.

The code in snapshot.c saves and restores memory when hibernating. This will access whole pages in the slab cache that have both free and allocated areas, resulting in a large number of false positives from Kasan.

Disable instrumentation of this file.

---
With this, I can hibernate/resume a kernel built with kasan on arm64.

 kernel/power/Makefile | 2 ++
 1 file changed, 2 insertions(+)
kernel/power/Makefile +2 -0
index cb880a14cc39..eb4f717705ba 100644
@@ -1,6 +1,8 @@
 
 ccflags-$(CONFIG_PM_DEBUG)	:= -DDEBUG
 
+KASAN_SANITIZE_snapshot.o	:= n
+
 obj-y				+= qos.o
 obj-$(CONFIG_PM)		+= main.o
 obj-$(CONFIG_VT_CONSOLE_SLEEP)	+= console.o
Signature · 1 line
2.8.0.rc3
#1 lore raw

PATCH 1/1 PM / Hibernate: Don't let kasan instrument snapshot.c

Quoted 24 lines · James Morse

Kasan causes the compiler to instrument C code and is used at runtime to detect accesses to memory that has been freed, or not yet allocated.

The code in snapshot.c saves and restores memory when hibernating. This will access whole pages in the slab cache that have both free and allocated areas, resulting in a large number of false positives from Kasan.

Disable instrumentation of this file.

---
With this, I can hibernate/resume a kernel built with kasan on arm64.

 kernel/power/Makefile | 2 ++
 1 file changed, 2 insertions(+)
kernel/power/Makefile +0 -0
index cb880a14cc39..eb4f717705ba 100644

kernel/power/Makefile line 8

Quoted 8 lines
kernel/power/Makefile +2 -0
@@ -1,6 +1,8 @@
 
 ccflags-$(CONFIG_PM_DEBUG)	:= -DDEBUG
 
+KASAN_SANITIZE_snapshot.o	:= n
+
 obj-y				+= qos.o
 obj-$(CONFIG_PM)		+= main.o
 obj-$(CONFIG_VT_CONSOLE_SLEEP)	+= console.o

Applied, thanks!

Does the arch code need to be annotated in a similar way too?

#2 lore raw

PATCH 1/1 PM / Hibernate: Don't let kasan instrument snapshot.c

Hi Rafael,

Quoted 1 line · Rafael J. Wysocki

Does the arch code need to be annotated in a similar way too?

Only if you do the restore copying from C, both 32bit and 64bit x86 do this copy in assembly code, which doesn't get instrumented.

Thanks,

James

#3 lore raw

PATCH 1/1 PM / Hibernate: Don't let kasan instrument snapshot.c

Quoted 7 lines · James Morse

Hi Rafael,

Quoted 1 line · Rafael J. Wysocki

Does the arch code need to be annotated in a similar way too?

Only if you do the restore copying from C, both 32bit and 64bit x86 do this copy in assembly code, which doesn't get instrumented.

OK, that's what I wanted to know.

Thanks!