Re: [PATCH v2] kdb: Reject non-positive BYTESPERWORD before division
From: Doug Anderson
Date: Wed Nov 18 2026 - 11:52:43 EST
Hi,
On Tue, Nov 17, 2026 at 11:29 PM Alex Kazinsky <a.kazinsky@xxxxxxxx> 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@xxxxxxxxxxxxxxx
> Signed-off-by: Alex Kazinsky <a.kazinsky@xxxxxxxx>
> ---
> v1: https://lore.kernel.org/all/20261113111152.4190309-1-a.kazinsky@xxxxxxxx/
>
> 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(+)
Reviewed-by: Douglas Anderson <dianders@xxxxxxxxxxxx>