From: Anton Moryakov <ant.v.moryakov@gmail.com>
To: chengzhihao1@huawei.com, linux-mtd@lists.infradead.org
Cc: Anton Moryakov <ant.v.moryakov@gmail.com>
Subject: [PATCH mtd-utils] nand-utils: Fix integer overflow in nandflipbits.c
Date: Tue, 17 Dec 2024 19:36:53 +0300 [thread overview]
Message-ID: <20241217163653.298586-1-ant.v.moryakov@gmail.com> (raw)
Report of the static analyzer:
The value of an arithmetic expression 'page * (mtd.min_io_size + mtd.oob_size)' is a subject to overflow because its operands are not cast to a larger data type before performing arithmetic
Corrections explained:
Casting bit_to_flip->block to unsigned long long expands the range of values and allows the result of the multiplication to be calculated in a wider data type.
The arithmetic is performed in a safe range, preventing overflow.
Sum + blkoffs is now also safe, since the result of the expression is already calculated in unsigned long long.
Triggers found by static analyzer Svace.
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
nand-utils/nandflipbits.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/nand-utils/nandflipbits.c b/nand-utils/nandflipbits.c
index ef663c6..c4642fe 100644
--- a/nand-utils/nandflipbits.c
+++ b/nand-utils/nandflipbits.c
@@ -213,7 +213,7 @@ int main(int argc, char **argv)
bits_to_flip[i].block = bits_to_flip[i].offset / blklen;
bits_to_flip[i].offset %= blklen;
page = bits_to_flip[i].offset / pagelen;
- bits_to_flip[i].offset = (page *
+ bits_to_flip[i].offset = ((unsigned long long)page *
(mtd.min_io_size + mtd.oob_size)) +
(bits_to_flip[i].offset % pagelen);
}
--
2.30.2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next reply other threads:[~2024-12-17 16:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 16:36 Anton Moryakov [this message]
2024-12-18 2:50 ` [PATCH mtd-utils] nand-utils: Fix integer overflow in nandflipbits.c Zhihao Cheng
-- strict thread matches above, loose matches on Subject: below --
2024-12-14 12:18 Anton Moryakov
2024-12-16 1:08 ` Zhihao Cheng
2024-12-13 13:19 Anton Moryakov
2024-12-14 2:59 ` Zhihao Cheng
2024-12-12 18:39 Anton Moryakov
2024-12-13 2:37 ` Zhihao Cheng
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=20241217163653.298586-1-ant.v.moryakov@gmail.com \
--to=ant.v.moryakov@gmail.com \
--cc=chengzhihao1@huawei.com \
--cc=linux-mtd@lists.infradead.org \
/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