mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bradley Morgan <bradley.morgan@linux.dev>
To: a.kazinsky@ideco.ru
Cc: danielt@kernel.org, dianders@chromium.org,
	gregkh@linuxfoundation.org, kgdb-bugreport@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org,
	mort@sgi.com, naveen.osdev@gmail.com, stable@vger.kernel.org,
	tim.bird@sony.com
Subject: Re: [PATCH v2] kdb: Reject non-positive BYTESPERWORD before division
Date: Wed, 18 Nov 2026 20:30:38 +0000	[thread overview]
Message-ID: <D82C97F0-F6CF-4D7D-BD47-4C1870A7E1FA@linux.dev> (raw)
In-Reply-To: <20261118072853.1578323-1-a.kazinsky@ideco.ru>

On 18 November 2026 07:28:52 GMT, Alex Kazinsky <a.kazinsky@ideco.ru>
wrote:
>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>

Nice!

Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>


>---
>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;
> 
>
>
>

--- Thanks!

      parent reply	other threads:[~2026-11-18 20:30 UTC|newest]

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

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=D82C97F0-F6CF-4D7D-BD47-4C1870A7E1FA@linux.dev \
    --to=bradley.morgan@linux.dev \
    --cc=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®