kdb: Reject zero BYTESPERWORD before calculating the repeat count
PATCH 1/1 kdb: Reject zero BYTESPERWORD before calculating the repeat count
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.
--- kernel/debug/kdb/kdb_main.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/debug/kdb/kdb_main.c +3 -0
@@ -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;
Signature · 1 line
2.56.0
Doug Anderson
reviewerHi,
Quoted 22 lines · Alex Kazinsky
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_BADWIDTHbefore 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 <[email protected]>--- kernel/debug/kdb/kdb_main.c | 3 +++ 1 file changed, 3 insertions(+)kernel/debug/kdb/kdb_main.c +0
-0
kernel/debug/kdb/kdb_main.c static int kdb_md(int argc, const char **argv) · line 1532
Quoted 6 lines
kernel/debug/kdb/kdb_main.c +3
-0@@ -1527,6 +1527,9 @@ static int kdb_md(int argc, const char **argv)kdbgetintenv ("RADIX" , &radix);kdbgetintenv ("BYTESPERWORD" , &bytesperword); +if (!bytesperword) +return KDB_BADWIDTH ; +
Could you check bytesperword <= 0 rather than !bytesperword (and update the commit message accordingly)?
AI-generated details, in case they are interesting to you:
kdbgetintenv() parses an unsigned long with kstrtoul() and casts it to int, so on 64-bit systems set BYTESPERWORD=0xffffffff gives bytesperword = -1. Combined with set MDCOUNT=0x8000000 (so `mdcount
* 16 wraps to INT_MIN, -2147483648), mdcount * 16 / bytesperword computes INT_MIN / -1. Because +2147483648 overflows a 32-bit signed int (INT_MAX is 2147483647), x86's signed idiv instruction raises the same #DE` divide error exception as dividing by zero.
-Doug