Skip to contentSkip to conversation

s390/debug: Fix NULL pointer dereference in debug_info_copy()

PATCH Applied Mikhail Zaslonko 4 participants 5 messages Sep 16 – Sep 22 s390

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 s390/debug: Fix NULL pointer dereference in debug_info_copy()

When debug_register_static() fails, it clears areas, active_pages and active_entries but leaves the area bounds unchanged. Copying such an area, either by opening its view file or via debug_dump(), makes debug_info_copy() dereference the NULL pointers.

Skip the copy loop when the source has no areas.

Fixes d72541f94512 ("s390/debug: add early tracing support")

---
v2:
- Different approach: check the areas pointer in debug_info_copy() instead of zeroing nr_areas/pages_per_area in debug_register_static(). Zeroing nr_areas made debug_info_alloc() return ZERO_SIZE_PTR for active_pages/active_entries, which debug_to_act_entry() dereferences before debug_prev_entry() checks id->areas.
Checking the pointer also matches what all other readers in this file already do.
- v1: https://lore.kernel.org/all/[email protected]/

 arch/s390/kernel/debug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kernel/debug.c +2 -1
index b5bf8284dbfc..d611d0eed1f6 100644
@@ -434,7 +434,8 @@ static debug_info_t *debug_info_copy(debug_info_t *in, int mode)
 		debug_info_free(rc);
 	} while (1);
 
-	if (mode == NO_AREAS)
+	/* debug_register_static() failure leaves areas NULL, bounds intact */
+	if (mode == NO_AREAS || !in->areas)
 		goto out;
 
 	for (i = 0; i < in->nr_areas; i++) {
Signature · 1 line
2.55.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

When debug_register_static() fails, it clears areas, active_pages and active_entries but leaves the area bounds unchanged. Copying such an area, either by opening its view file or via debug_dump(), makes debug_info_copy() dereference the NULL pointers.

Skip the copy loop when the source has no areas.

Fixes d72541f94512 ("s390/debug: add early tracing support")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Acked-by on v2 1/1
#2 lore raw
In reply to Mikhail Zaslonko
Quoted 29 lines · Mikhail Zaslonko

When debug_register_static() fails, it clears areas, active_pages and active_entries but leaves the area bounds unchanged. Copying such an area, either by opening its view file or via debug_dump(), makes debug_info_copy() dereference the NULL pointers.

Skip the copy loop when the source has no areas.

Fixes d72541f94512 ("s390/debug: add early tracing support")

---
v2:
- Different approach: check the areas pointer in debug_info_copy() instead of zeroing nr_areas/pages_per_area in debug_register_static(). Zeroing nr_areas made debug_info_alloc() return ZERO_SIZE_PTR for active_pages/active_entries, which debug_to_act_entry() dereferences before debug_prev_entry() checks id->areas.
Checking the pointer also matches what all other readers in this file already do.
- v1: https://lore.kernel.org/all/[email protected]/

 arch/s390/kernel/debug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kernel/debug.c +0 -0
index b5bf8284dbfc..d611d0eed1f6 100644

arch/s390/kernel/debug.c static debug_info_t *debug_info_copy(debug_info_t *in, int mode) · line 438

Quoted 6 lines
arch/s390/kernel/debug.c +2 -1
@@ -434,7 +434,8 @@ static debug_info_t *debug_info_copy(debug_info_t *in, int mode)
 		debug_info_free(rc);
 	} while (1);
 
-	if (mode == NO_AREAS)
+	/* debug_register_static() failure leaves areas NULL, bounds intact */
+	if (mode == NO_AREAS || !in->areas)

This is just a more or less random indicator that debug_register_static() failed. But this seems to be the easiest way forward. Alternatively an explicit flag in debug_info_t would make this more obvious.

Anyway:

Waiting for Peter's reply.

#3 lore raw
Quoted 41 lines · Heiko Carstens
Quoted 29 lines · Mikhail Zaslonko

When debug_register_static() fails, it clears areas, active_pages and active_entries but leaves the area bounds unchanged. Copying such an area, either by opening its view file or via debug_dump(), makes debug_info_copy() dereference the NULL pointers.

Skip the copy loop when the source has no areas.

Fixes d72541f94512 ("s390/debug: add early tracing support")

---
v2:
- Different approach: check the areas pointer in debug_info_copy() instead of zeroing nr_areas/pages_per_area in debug_register_static(). Zeroing nr_areas made debug_info_alloc() return ZERO_SIZE_PTR for active_pages/active_entries, which debug_to_act_entry() dereferences before debug_prev_entry() checks id->areas.
Checking the pointer also matches what all other readers in this file already do.
- v1: https://lore.kernel.org/all/[email protected]/

 arch/s390/kernel/debug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kernel/debug.c +0 -0
index b5bf8284dbfc..d611d0eed1f6 100644

arch/s390/kernel/debug.c static debug_info_t *debug_info_copy(debug_info_t *in, int mode) · line 438

Quoted 6 lines
arch/s390/kernel/debug.c +2 -1
@@ -434,7 +434,8 @@ static debug_info_t *debug_info_copy(debug_info_t *in, int mode)
 		debug_info_free(rc);
 	} while (1);
 
-	if (mode == NO_AREAS)
+	/* debug_register_static() failure leaves areas NULL, bounds intact */
+	if (mode == NO_AREAS || !in->areas)

This is just a more or less random indicator that debug_register_static() failed. But this seems to be the easiest way forward. Alternatively an explicit flag in debug_info_t would make this more obvious.

Quoted 4 lines

Anyway:

Waiting for Peter's reply.

As Heiko mentioned, this can be done in a number of ways, but this one is fine from my perspective.

Signature · 2 lines
Peter Oberparleiter
Linux on IBM Z Development - IBM Germany R&D
maintainer Applied
#4 lore raw
In reply to Mikhail Zaslonko
Quoted 21 lines · Mikhail Zaslonko

When debug_register_static() fails, it clears areas, active_pages and active_entries but leaves the area bounds unchanged. Copying such an area, either by opening its view file or via debug_dump(), makes debug_info_copy() dereference the NULL pointers.

Skip the copy loop when the source has no areas.

Fixes d72541f94512 ("s390/debug: add early tracing support")

---
v2:
- Different approach: check the areas pointer in debug_info_copy() instead of zeroing nr_areas/pages_per_area in debug_register_static(). Zeroing nr_areas made debug_info_alloc() return ZERO_SIZE_PTR for active_pages/active_entries, which debug_to_act_entry() dereferences before debug_prev_entry() checks id->areas.
Checking the pointer also matches what all other readers in this file already do.
- v1: https://lore.kernel.org/all/[email protected]/

Quoted 2 lines
 arch/s390/kernel/debug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks!