[PATCH] kdb: Reject zero BYTESPERWORD before calculating the repeat count
From: Alex Kazinsky
Date: Fri Nov 13 2026 - 14:01:01 EST
Setting BYTESPERWORD to zero in the kdb environment causes kdb_md()
to divide by zero when calculating the initial repeat count. The
existing width validation happens after this division.
Reject a zero width with KDB_BADWIDTH before calculating the repeat
count.
Found by Linux Verification Center (linuxtesting.org) with SVACE static
analysis tool.
Fixes: 5d5314d6795f ("kdb: core for kgdb back end (1 of 2)")
Signed-off-by: Alex Kazinsky <a.kazinsky@xxxxxxxx>
---
kernel/debug/kdb/kdb_main.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 40c332d2179d..c3cbeb25f6fb 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -1527,6 +1527,9 @@ static int kdb_md(int argc, const char **argv)
kdbgetintenv("RADIX", &radix);
kdbgetintenv("BYTESPERWORD", &bytesperword);
+ if (!bytesperword)
+ return KDB_BADWIDTH;
+
/* Assume 'md <addr>' and start with environment values */
repeat = mdcount * 16 / bytesperword;
--
2.56.0