mtd: diskonchip: Cast an operand to uint64_t to prevent potential uint32_t overflow in inftl_partscan()
Subsystems (2)
PATCH v2 1/1 mtd: diskonchip: Cast an operand to uint64_t to prevent potential uint32_t overflow in inftl_partscan()
From: Zichen Xie <[email protected]>
This was found by a static analyzer.
There may be a potential integer overflow issue in inftl_partscan(). parts[0].size is defined as "uint64_t" while mtd->erasesize and ip->firstUnit are defined as 32-bit unsigned integer. The result of the calculation will be limited to 32 bits without correct casting.
So, we recommend adding an extra cast to prevent potential integer overflow.
---
v2: correct "Fixes" tag.
--- drivers/mtd/nand/raw/diskonchip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/diskonchip.c +1 -1
@@ -1098,7 +1098,7 @@ static inline int __init inftl_partscan(struct mtd_info *mtd, struct mtd_partiti (i == 0) && (ip->firstUnit > 0)) { parts[0 ].name =" DiskOnChip IPL / Media Header partition" ; parts[0 ].offset =0 ; - parts[0 ].size = mtd->erasesize * ip->firstUnit; + parts[0 ].size = (uint64_t )mtd->erasesize * ip->firstUnit; numparts =1 ; }
Signature · 6 lines
2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Miquel Raynal
maintainerHi,
[email protected] wrote on Mon, 21 Oct 2024 14:27:54 -0500:
Quoted 3 lines
From: Zichen Xie <[email protected]>
This was found by a static analyzer.
This should be the last sentence, not the first, maybe?
Quoted 7 lines
There may be a potential integer overflow issue in
inftl_partscan(). parts[0].size is defined as "uint64_t" whilemtd->erasesizeandip->firstUnitare defined as 32-bit unsigned integer. The result of the calculation will be limited to 32 bits without correct casting.
So, we recommend adding an extra cast to prevent potential integer overflow.
The wrapping is odd.
Quoted 5 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Zichen Xie <[email protected]>---
v2: correct "Fixes" tag.
If you want to provide a fix, you probably want to Cc: stable as well.
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 8 lines · Miquel Raynal
Hi,
[email protected] wrote on Mon, 21 Oct 2024 14:27:54 -0500:
Quoted 3 lines
From: Zichen Xie <[email protected]>
This was found by a static analyzer.
This should be the last sentence, not the first, maybe?
I saw a lot patches making it as the first sentence. So, I did it too.
Quoted 9 lines
Quoted 8 lines
There may be a potential integer overflow issue in
inftl_partscan(). parts[0].size is defined as "uint64_t" whilemtd->erasesizeandip->firstUnitare defined as 32-bit unsigned integer. The result of the calculation will be limited to 32 bits without correct casting.
So, we recommend adding an extra cast to prevent potential integer overflow.The wrapping is odd.
Sorry, but could you please point out where's odd so I can fix it.
Quoted 6 lines
Quoted 5 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Zichen Xie <[email protected]>---
v2: correct "Fixes" tag.If you want to provide a fix, you probably want to Cc: stable as well.
Yeah, I will add that to the next version.
Best,
Zichen
Quoted 3 lines
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Miquel Raynal
maintainerHi Zichen,
[email protected] wrote on Tue, 22 Oct 2024 10:49:45 -0500:
Quoted 10 lines · Miquel Raynal
Quoted 8 lines
Hi,
[email protected] wrote on Mon, 21 Oct 2024 14:27:54 -0500:
Quoted 3 lines
From: Zichen Xie <[email protected]>
This was found by a static analyzer.
This should be the last sentence, not the first, maybe?
I saw a lot patches making it as the first sentence. So, I did it too.
Well, they are likely wrong.
Also, please shorten your commit title
"Cast an operand to prevent potential overflow" would be enough. You'll give the details in the commit log anyway.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
There may be a potential integer overflow issue in
inftl_partscan(). parts[0].size is defined as "uint64_t" whilemtd->erasesizeandip->firstUnitare defined as 32-bit unsigned integer. The result of the calculation will be limited to 32 bits without correct casting.
So, we recommend adding an extra cast to prevent potential integer overflow.The wrapping is odd.
Sorry, but could you please point out where's odd so I can fix it.
Your commit log is wrapped at 60-char.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Zichen Xie <[email protected]>---
v2: correct "Fixes" tag.
Quoted 12 lines
Quoted 1 line
If you want to provide a fix, you probably want to Cc: stable as well.
Yeah, I will add that to the next version.
Best,
Zichen
Quoted 3 lines
Thanks,
Miquèl
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/