s390/debug: Fix NULL pointer dereference in debug_info_copy()
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.
---
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
@@ -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
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
When
debug_register_static()fails, it clears areas,active_pagesandactive_entriesbut leaves the area bounds unchanged. Copying such an area, either by opening its view file or viadebug_dump(), makesdebug_info_copy()dereference the NULL pointers.Skip the copy loop when the source has no areas.
Fixes d72541f94512 ("s390/debug: add early tracing support")Signed-off-by Mikhail Zaslonko <[email protected]>
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
Quoted 29 lines · Mikhail Zaslonko
When
debug_register_static()fails, it clears areas,active_pagesandactive_entriesbut leaves the area bounds unchanged. Copying such an area, either by opening its view file or viadebug_dump(), makesdebug_info_copy()dereference the NULL pointers.Skip the copy loop when the source has no areas.
Fixes d72541f94512 ("s390/debug: add early tracing support")Signed-off-by Mikhail Zaslonko <[email protected]>---
v2:
- Different approach: check the areas pointer indebug_info_copy()instead of zeroing nr_areas/pages_per_area indebug_register_static(). Zeroingnr_areasmadedebug_info_alloc()returnZERO_SIZE_PTRfor active_pages/active_entries, whichdebug_to_act_entry()dereferences beforedebug_prev_entry()checksid->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
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.
Peter Oberparleiter
Reviewed-byQuoted 41 lines · Heiko Carstens
Quoted 29 lines · Mikhail Zaslonko
When
debug_register_static()fails, it clears areas,active_pagesandactive_entriesbut leaves the area bounds unchanged. Copying such an area, either by opening its view file or viadebug_dump(), makesdebug_info_copy()dereference the NULL pointers.Skip the copy loop when the source has no areas.
Fixes d72541f94512 ("s390/debug: add early tracing support")Signed-off-by Mikhail Zaslonko <[email protected]>---
v2:
- Different approach: check the areas pointer indebug_info_copy()instead of zeroing nr_areas/pages_per_area indebug_register_static(). Zeroingnr_areasmadedebug_info_alloc()returnZERO_SIZE_PTRfor active_pages/active_entries, whichdebug_to_act_entry()dereferences beforedebug_prev_entry()checksid->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
-0arch/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 indebug_info_twould make this more obvious.
Quoted 4 lines
Anyway:
Acked-by Heiko Carstens <[email protected]>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
Quoted 21 lines · Mikhail Zaslonko
When
debug_register_static()fails, it clears areas,active_pagesandactive_entriesbut leaves the area bounds unchanged. Copying such an area, either by opening its view file or viadebug_dump(), makesdebug_info_copy()dereference the NULL pointers.Skip the copy loop when the source has no areas.
Fixes d72541f94512 ("s390/debug: add early tracing support")Signed-off-by Mikhail Zaslonko <[email protected]>---
v2:
- Different approach: check the areas pointer indebug_info_copy()instead of zeroing nr_areas/pages_per_area indebug_register_static(). Zeroingnr_areasmadedebug_info_alloc()returnZERO_SIZE_PTRfor active_pages/active_entries, whichdebug_to_act_entry()dereferences beforedebug_prev_entry()checksid->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!