Skip to contentSkip to conversation

PM: declare __tracedata symbols as char[] rather than char

PATCH Applied Eric Biggers 2 participants 2 messages Jan 25, 2016 – Feb 21, 2016

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

PATCH 1/1 PM: declare __tracedata symbols as char[] rather than char

Accessing more than one byte from a symbol declared simply 'char' is undefined behavior, as reported by UBSAN:

	UBSAN: Undefined behaviour in drivers/base/power/trace.c:178:18
	load of address ffffffff8203fc78 with insufficient space
	for an object of type 'char'

Avoid this by declaring the symbols as arrays.

---
 drivers/base/power/trace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/power/trace.c +2 -2
index a311cfa..a697579 100644
@@ -166,14 +166,14 @@ void generate_pm_trace(const void *tracedata, unsigned int user)
 }
 EXPORT_SYMBOL(generate_pm_trace);
 
-extern char __tracedata_start, __tracedata_end;
+extern char __tracedata_start[], __tracedata_end[];
 static int show_file_hash(unsigned int value)
 {
 	int match;
 	char *tracedata;
 
 	match = 0;
-	for (tracedata = &__tracedata_start ; tracedata < &__tracedata_end ;
+	for (tracedata = __tracedata_start ; tracedata < __tracedata_end ;
 			tracedata += 2 + sizeof(unsigned long)) {
 		unsigned short lineno = *(unsigned short *)tracedata;
 		const char *file = *(const char **)(tracedata + 2);
Signature · 1 line
2.7.0
#1 lore raw
Quoted 10 lines · Eric Biggers

Accessing more than one byte from a symbol declared simply 'char' is undefined behavior, as reported by UBSAN:

	UBSAN: Undefined behaviour in drivers/base/power/trace.c:178:18
	load of address ffffffff8203fc78 with insufficient space
	for an object of type 'char'

Avoid this by declaring the symbols as arrays.

Queued up for 4.6, thanks!

Rafael