Skip to contentSkip to conversation

avoid out of bounds array reference in save_trace()

PATCH In review Luck, Tony 2 participants 3 messages Dec 9, 2009 – Dec 10, 2009

lore
Share & tools
lore

Luck, Tony

author
#0 lore raw

PATCH 1/1 avoid out of bounds array reference in save_trace()

ia64 found this the hard way (because we currently have a stub for save_stack_trace() that does nothing). But it would be a good idea to be cautious in case a real save_stack_trace() bailed out with an error before it set trace->nr_entries.

---

kernel/lockdep.c +2 -1
index 03c06af..429540c 100644
@@ -387,7 +387,8 @@ static int save_trace(struct stack_trace *trace)
 	 * complete trace that maxes out the entries provided will be reported
 	 * as incomplete, friggin useless </rant>
 	 */
-	if (trace->entries[trace->nr_entries-1] == ULONG_MAX)
+	if (trace->nr_entries != 0 &&
+	    trace->entries[trace->nr_entries-1] == ULONG_MAX)
 		trace->nr_entries--;
 
 	trace->max_entries = trace->nr_entries;
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Tony

ia64 found this the hard way (because we currently have a stub for save_stack_trace() that does nothing). But it would be a good idea to be cautious in case a real save_stack_trace() bailed out with an error before it set trace->nr_entries.

Thanks Tony,

Quoted 16 lines

---

kernel/lockdep.c +2 -1
index 03c06af..429540c 100644
@@ -387,7 +387,8 @@ static int save_trace(struct stack_trace *trace)
 	 * complete trace that maxes out the entries provided will be reported
 	 * as incomplete, friggin useless </rant>
 	 */
-	if (trace->entries[trace->nr_entries-1] == ULONG_MAX)
+	if (trace->nr_entries != 0 &&
+	    trace->entries[trace->nr_entries-1] == ULONG_MAX)
 		trace->nr_entries--;
 
 	trace->max_entries = trace->nr_entries;
#2 lore raw

[tip:core/urgent] lockdep: Avoid out of bounds array reference in save_trace()

In reply to Luck, Tony
Commit-ID:  ea5b41f9d595be354f7a50e56b28c2d72e6e88a5
Gitweb:     http://git.kernel.org/tip/ea5b41f9d595be354f7a50e56b28c2d72e6e88a5
Author:     Luck, Tony <[email protected]>
AuthorDate: Wed, 9 Dec 2009 14:29:36 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 10 Dec 2009 08:29:33 +0100

lockdep: Avoid out of bounds array reference in save_trace()

ia64 found this the hard way (because we currently have a stub for save_stack_trace() that does nothing). But it would be a good idea to be cautious in case a real save_stack_trace() bailed out with an error before it set trace->nr_entries.

LKML-Reference: <[email protected]>

---
 kernel/lockdep.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/lockdep.c +2 -1
index 7a3ae56..4f8df01 100644
@@ -386,7 +386,8 @@ static int save_trace(struct stack_trace *trace)
 	 * complete trace that maxes out the entries provided will be reported
 	 * as incomplete, friggin useless </rant>
 	 */
-	if (trace->entries[trace->nr_entries-1] == ULONG_MAX)
+	if (trace->nr_entries != 0 &&
+	    trace->entries[trace->nr_entries-1] == ULONG_MAX)
 		trace->nr_entries--;
 
 	trace->max_entries = trace->nr_entries;