public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Anton Moryakov <ant.v.moryakov@gmail.com>,
	<linux-mtd@lists.infradead.org>
Subject: Re: [PATCH mtd-utils] nand-utils: Fix integer overflow in nandflipbits.c
Date: Sat, 14 Dec 2024 10:59:16 +0800	[thread overview]
Message-ID: <f8f360cb-da91-a44e-cf2f-7955ee33d3d4@huawei.com> (raw)
In-Reply-To: <20241213131919.100987-1-ant.v.moryakov@gmail.com>

在 2024/12/13 21:19, Anton Moryakov 写道:
> Report of the static analyzer:
> The value of an arithmetic expression 'bit_to_flip->block * mtd.eb_size + blkoffs' is a subject to overflow because its operands are not cast to a larger data type before performing arith$
> 
> Corrections explained:
> Prevent arithmetic overflow in OOB read operation
> Resolved an issue where the calculation of the offset in the OOB read operation could overflow due to operands not being cast to a larger data type. Specifically, the multiplication of bi$
> 
> 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 7066408..ef663c6 100644
> --- a/nand-utils/nandflipbits.c
> +++ b/nand-utils/nandflipbits.c
> @@ -251,7 +251,7 @@ int main(int argc, char **argv)
>   			bufoffs += mtd.min_io_size;
>   
>   			ret = mtd_read_oob(mtd_desc, &mtd, fd,
> -					   bit_to_flip->block * mtd.eb_size +
> +					   (unsigned long long)bit_to_flip->block * (long long)mtd.eb_size +

Hi, Anton. Change it like:
(unsigned long long)bit_to_flip->block * mtd.eb_size + blkoffs
>   					   blkoffs,
>   					   mtd.oob_size, buffer + bufoffs);
>   			if (ret) {
> 


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2024-12-14  2:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-13 13:19 [PATCH mtd-utils] nand-utils: Fix integer overflow in nandflipbits.c Anton Moryakov
2024-12-14  2:59 ` Zhihao Cheng [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-12-17 16:36 Anton Moryakov
2024-12-18  2:50 ` Zhihao Cheng
2024-12-14 12:18 Anton Moryakov
2024-12-16  1:08 ` 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=f8f360cb-da91-a44e-cf2f-7955ee33d3d4@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=ant.v.moryakov@gmail.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