mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Kazinsky <a.kazinsky@ideco.ru>
To: Daniel Thompson <danielt@kernel.org>
Cc: Alex Kazinsky <a.kazinsky@ideco.ru>,
	Douglas Anderson <dianders@chromium.org>,
	Naveen Kumar Chaudhary <naveen.osdev@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Tim Bird <tim.bird@sony.com>, Martin Hicks <mort@sgi.com>,
	kgdb-bugreport@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org,
	stable@vger.kernel.org
Subject: [PATCH v2] kdb: Reject non-positive BYTESPERWORD before division
Date: Wed, 18 Nov 2026 11:28:52 +0400	[thread overview]
Message-ID: <20261118072853.1578323-1-a.kazinsky@ideco.ru> (raw)

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;
 


             reply	other threads:[~2026-11-18  7:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  7:28 Alex Kazinsky [this message]
2026-11-18 16:51 ` Doug Anderson
2026-11-18 20:30 ` Bradley Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118072853.1578323-1-a.kazinsky@ideco.ru \
    --to=a.kazinsky@ideco.ru \
    --cc=danielt@kernel.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kgdb-bugreport@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=mort@sgi.com \
    --cc=naveen.osdev@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=tim.bird@sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®