mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] kdb: Reject non-positive BYTESPERWORD before division
@ 2026-11-18  7:28 Alex Kazinsky
  2026-11-18 16:51 ` Doug Anderson
  2026-11-18 20:30 ` Bradley Morgan
  0 siblings, 2 replies; 3+ messages in thread
From: Alex Kazinsky @ 2026-11-18  7:28 UTC (permalink / raw)
  To: Daniel Thompson
  Cc: Alex Kazinsky, Douglas Anderson, Naveen Kumar Chaudhary,
	Greg Kroah-Hartman, Tim Bird, Martin Hicks, kgdb-bugreport,
	linux-kernel, lvc-project, stable

kdb_md() uses BYTESPERWORD as a divisor when calculating the initial
repeat count, before validating the word width. A zero width causes a
division by zero. kdbgetintenv() also casts an unsigned long to int,
so the resulting width can be negative. If the width is -1 and the
scaled count is INT_MIN, the quotient overflows and raises a divide
error on x86.

Return KDB_BADWIDTH for non-positive widths 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)")
Cc: stable@vger.kernel.org
Signed-off-by: Alex Kazinsky <a.kazinsky@ideco.ru>
---
v1: https://lore.kernel.org/all/20261113111152.4190309-1-a.kazinsky@ideco.ru/

Changes in v2:
- Reject negative BYTESPERWORD values as well as zero.
- Explain the signed division overflow in the commit message.

 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..b1719382144b 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 <= 0)
+		return KDB_BADWIDTH;
+
 	/* Assume 'md <addr>' and start with environment values */
 	repeat = mdcount * 16 / bytesperword;
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18 20:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18  7:28 [PATCH v2] kdb: Reject non-positive BYTESPERWORD before division Alex Kazinsky
2026-11-18 16:51 ` Doug Anderson
2026-11-18 20:30 ` Bradley Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®