Skip to contentSkip to conversation

stackdepot-check-depot_index-before-accessing-the-stack-slab.patch removed from -mm tree

merged [email protected] 1 participant 1 message Apr 8, 2020

lore
Share & tools
lore

[email protected]

author tree notice Applied
#0 lore raw

The patch titled
Subject: lib/stackdepot.c: check depot_index before accessing the stack slab
has been removed from the -mm tree. Its filename was
stackdepot-check-depot_index-before-accessing-the-stack-slab.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Alexander Potapenko <[email protected]>
Subject: lib/stackdepot.c: check depot_index before accessing the stack slab

Avoid crashes on corrupted stack ids. Despite stack ID corruption may indicate other bugs in the program, we'd better fail gracefully on such IDs instead of crashing the kernel.

This patch has been previously mailed as part of KMSAN RFC patch series.

Cc Vegard Nossum <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Marco Elver <[email protected]>
Cc Andrey Konovalov <[email protected]>
Cc Andrey Ryabinin <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Sergey Senozhatsky <[email protected]>

From: Dan Carpenter <[email protected]>
Subject: lib/stackdepot.c: fix a condition in stack_depot_fetch()

We should check for a NULL pointer first before adding the offset. Otherwise if the pointer is NULL and the offset is non-zero, it will lead to an Oops.

Fixes d45048e65a59 ("lib/stackdepot.c: check depot_index before accessing the stack slab")

---

 lib/stackdepot.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
lib/stackdepot.c renamed from lib/stackdepot.c~stackdepot-check-depot_index-before-accessing-the-stack-slab +13 -2
@@ -202,9 +202,20 @@ unsigned int stack_depot_fetch(depot_sta
 			       unsigned long **entries)
 {
 	union handle_parts parts = { .handle = handle };
-	void *slab = stack_slabs[parts.slabindex];
+	void *slab;
 	size_t offset = parts.offset << STACK_ALLOC_ALIGN;
-	struct stack_record *stack = slab + offset;
+	struct stack_record *stack;
+
+	*entries = NULL;
+	if (parts.slabindex > depot_index) {
+		WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n",
+			parts.slabindex, depot_index, handle);
+		return 0;
+	}
+	slab = stack_slabs[parts.slabindex];
+	if (!slab)
+		return 0;
+	stack = slab + offset;
 
 	*entries = stack->entries;
 	return stack->size;

_

Patches currently in -mm which might be from [email protected] are