* [PATCH] s390/debug: Reset pages_per_area and nr_areas when static registration fails
@ 2026-09-10 10:45 Mikhail Zaslonko
2026-09-10 11:01 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Mikhail Zaslonko @ 2026-09-10 10:45 UTC (permalink / raw)
To: linux-s390
Cc: Heiko Carstens, Alexander Gordeev, Vasily Gorbik,
Peter Oberparleiter
Everywhere else in the debug feature, a NULL areas pointer implies zero
bounds: debug_info_alloc() sets areas to NULL exactly when
pages_per_area is 0, and debug_areas_swap() swaps areas, nr_areas and
pages_per_area together. The error path of debug_register_static() is the
sole exception.
Set pages_per_area and nr_areas to zero on the error path to restore
the invariant.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260903130733.709001-1-zaslonko@linux.ibm.com?part=3
Fixes: d72541f94512 ("s390/debug: add early tracing support")
Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
---
arch/s390/kernel/debug.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index b5bf8284dbfc..cb7799cf62d9 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -973,6 +973,8 @@ void debug_register_static(debug_info_t *id, int pages_per_area, int nr_areas)
id->areas = NULL;
id->active_pages = NULL;
id->active_entries = NULL;
+ id->nr_areas = 0;
+ id->pages_per_area = 0;
raw_spin_unlock_irqrestore(&id->lock, flags);
return;
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] s390/debug: Reset pages_per_area and nr_areas when static registration fails
2026-09-10 10:45 [PATCH] s390/debug: Reset pages_per_area and nr_areas when static registration fails Mikhail Zaslonko
@ 2026-09-10 11:01 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-09-10 11:01 UTC (permalink / raw)
To: Mikhail Zaslonko
Cc: Alexander Gordeev, Christian Borntraeger, linux-s390,
Heiko Carstens, Vasily Gorbik
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Setting `nr_areas = 0` on the error path exposes a `ZERO_SIZE_PTR` dereference in `debug_to_act_entry()` if `debug_dump()` is called with `reverse = true`.
Pre-existing issues:
- [High] debug_dump() does not check if the provided `id` is NULL before processing, leading to a kernel panic if a dynamic debug feature fails to register.
- [High] A TOCTOU race condition exists between tracing event functions (like `debug_event_common()`) and the error path of `debug_register_static()`. If `debug_register_static()` fails, this race results in a NULL pointer dereference.
--
commit e3103537d5e7bf2aad3e77c036a8ee844699d72c
Author: Mikhail Zaslonko <zaslonko@linux.ibm.com>
s390/debug: Reset pages_per_area and nr_areas when static registration fails
This patch addresses an invariant mismatch on the error path of
debug_register_static(). It sets pages_per_area and nr_areas to zero to
match the behavior where a NULL areas pointer implies zero bounds.
Closes: https://sashiko.dev/#/patchset/20260903130733.709001-1-zaslonko@linux.ibm.com?part=3
> diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
> index 14d2b58ad0930..0a48748bea267 100644
> --- a/arch/s390/kernel/debug.c
> +++ b/arch/s390/kernel/debug.c
> @@ -971,6 +971,8 @@ void debug_register_static(debug_info_t *id, int pages_per_area, int nr_areas)
> id->areas = NULL;
> id->active_pages = NULL;
> id->active_entries = NULL;
[Severity: High]
This is a pre-existing issue, but there is a race condition between tracing
event functions (like debug_event_common()) and the error path of
debug_register_static().
If debug_register_static() fails, this race results in a NULL pointer
dereference:
arch/s390/kernel/debug.c:debug_event_common() {
if (!debug_active || !id->areas)
return NULL;
...
} else {
raw_spin_lock_irqsave(&id->lock, flags);
}
do {
active = get_active_entry(id);
If the lockless check in debug_event_common() passes before
debug_register_static() nullifies id->areas, debug_event_common() will wait
on the lock.
Once debug_register_static() releases the lock, debug_event_common() gets
the lock and calls get_active_entry(id) without re-checking id->areas. This
dereferences id->areas[id->active_area] (now NULL) and panics the kernel.
Can id->areas be re-checked inside the lock before calling
get_active_entry(id)?
> + id->nr_areas = 0;
> + id->pages_per_area = 0;
[Severity: High]
Does setting id->nr_areas to 0 expose a ZERO_SIZE_PTR dereference on
snap_id->active_pages?
If debug_dump(..., reverse = true) is later called on this static trace, it
copies the debug info by calling debug_info_alloc() with nr_areas = 0.
This allocates a ZERO_SIZE_PTR (address 0x10) for active_pages.
When debug_dump() iterates backwards, it calls debug_prev_entry(). This
checks if (p_info->act_entry == DEBUG_PROLOG_ENTRY) and immediately calls
debug_to_act_entry() before verifying if (!id->areas):
arch/s390/kernel/debug.c:debug_prev_entry() {
if (p_info->act_entry == DEBUG_PROLOG_ENTRY)
debug_to_act_entry(p_info);
if (!id->areas)
return false;
debug_to_act_entry() then reads snap_id->active_pages[snap_id->active_area],
dereferencing the unmapped ZERO_SIZE_PTR and panicking the kernel.
> raw_spin_unlock_irqrestore(&id->lock, flags);
>
> return;
[Severity: High]
This isn't a bug introduced by this patch, but debug_dump() does not check
if the provided id pointer is NULL before processing.
If a dynamic debug feature fails to register during initialization (e.g., in
PCI), the debug ID pointer remains NULL. Subsystems may then call
debug_dump() (e.g., zpci_report_status()) with this NULL pointer on their
error reporting path.
debug_dump() passes this NULL pointer directly to debug_file_private_alloc():
arch/s390/kernel/debug.c:debug_dump() {
...
p_info = debug_file_private_alloc(id, view);
debug_file_private_alloc() then passes it to debug_info_copy(), which
unconditionally dereferences in->name:
arch/s390/kernel/debug.c:debug_info_copy() {
...
rc = debug_info_alloc(in->name, in->pages_per_area,
in->nr_areas, in->buf_size, in->level, mode);
Can we add a NULL check for the id pointer at the start of debug_dump() to
prevent this panic on the error path?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910104525.3788362-1-zaslonko@linux.ibm.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-10 11:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-10 10:45 [PATCH] s390/debug: Reset pages_per_area and nr_areas when static registration fails Mikhail Zaslonko
2026-09-10 11:01 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox