Skip to contentSkip to conversation

lib/x86/stack: fix null dereference

PATCH Applied Andrew Jones 2 participants 2 messages Nov 3, 2016 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/x86/stack: fix null dereference

With gcc 6.2.1 (gcc-6.2.1-2.fc24.x86_64) hitting an assert() in x86 code causes an infinite loop. This is due to a null dereference in backtrace_frame. Let's not do that.

---
 lib/x86/stack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/stack.c +1 -1
index d75c0beb46fb..5ecd97ce90b9 100644
@@ -13,7 +13,7 @@ int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
 	}
 	walking = 1;
 
-	for (depth = 0; depth < max_depth; depth++) {
+	for (depth = 0; bp && depth < max_depth; depth++) {
 		return_addrs[depth] = (void *) bp[1];
 		if (return_addrs[depth] == 0)
 			break;
Signature · 1 line
2.7.4
maintainer Applied
#1 lore raw
Quoted 15 lines · Andrew Jones

With gcc 6.2.1 (gcc-6.2.1-2.fc24.x86_64) hitting an assert() in x86 code causes an infinite loop. This is due to a null dereference in backtrace_frame. Let's not do that.

---
 lib/x86/stack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/stack.c +0 -0
index d75c0beb46fb..5ecd97ce90b9 100644

lib/x86/stack.c int backtrace_frame(const void *frame, const void **return_addrs, int max_depth) · line 19

Quoted 8 lines
lib/x86/stack.c +1 -1
@@ -13,7 +13,7 @@ int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
 	}
 	walking = 1;
 
-	for (depth = 0; depth < max_depth; depth++) {
+	for (depth = 0; bp && depth < max_depth; depth++) {
 		return_addrs[depth] = (void *) bp[1];
 		if (return_addrs[depth] == 0)
 			break;

Applied, thanks.

Paolo