Skip to contentSkip to conversation

mtd: partitions: redboot: Added conversion of operands to a larger type

PATCH In review Denis Arefev 2 participants 2 messages Sep 10, 2024 – Sep 25, 2024 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: partitions: redboot: Added conversion of operands to a larger type

The value of an arithmetic expression directory * master->erasesize is subject to overflow due to a failure to cast operands to a larger data type before perfroming arithmetic

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/mtd/parsers/redboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/parsers/redboot.c +1 -1
index 3b55b676ca6b..c8f7e7b351d7 100644
@@ -92,7 +92,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
 	parse_redboot_of(master);
 
 	if (directory < 0) {
-		offset = master->size + directory * master->erasesize;
+		offset = master->size + (unsigned long) directory * master->erasesize;
 		while (mtd_block_isbad(master, offset)) {
 			if (!offset) {
 nogood:
Signature · 1 line
2.25.1
#1 lore raw
Quoted 17 lines · Denis Arefev

The value of an arithmetic expression directory * master->erasesize is subject to overflow due to a failure to cast operands to a larger data type before perfroming arithmetic

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/mtd/parsers/redboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/parsers/redboot.c +0 -0
index 3b55b676ca6b..c8f7e7b351d7 100644

drivers/mtd/parsers/redboot.c static int parse_redboot_partitions(struct mtd_info *master, · line 98

Quoted 8 lines
drivers/mtd/parsers/redboot.c +1 -1
@@ -92,7 +92,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
 	parse_redboot_of(master);
 
 	if (directory < 0) {
-		offset = master->size + directory * master->erasesize;
+		offset = master->size + (unsigned long) directory * master->erasesize;
 		while (mtd_block_isbad(master, offset)) {
 			if (!offset) {
 nogood:

I guess the message has been sent by a mistake, the patch is already upstream 1162bc2f8f5de7da23d18aa4b7fbd4e93c369c50