Skip to contentSkip to conversation

mtd: maps: physmap: Fix infinite loop crash in ROM type probing

PATCH In review Geert Uytterhoeven 3 participants 5 messages Nov 6, 2018 – Nov 7, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: maps: physmap: Fix infinite loop crash in ROM type probing

On Toshiba RBTX4927, where map_probe is supposed to fail:

    Creating 2 MTD partitions on "physmap-flash.0":
    0x000000c00000-0x000001000000 : "boot"
    0x000000000000-0x000000c00000 : "user"
    physmap-flash physmap-flash.1: physmap platform flash device: [mem 0x1e000000-0x1effffff]
    CPU 0 Unable to handle kernel paging request at virtual address 00000000, epc == 80320f40, ra == 80321004
    ...
    Call Trace:
    [<80320f40>] get_mtd_chip_driver+0x30/0x8c
    [<80321004>] do_map_probe+0x20/0x90
    [<80328448>] physmap_flash_probe+0x484/0x4ec

The access to rom_probe_types[] was changed from a sentinel-based loop to an infinite loop, causing a crash when reaching the sentinel.

Fix this by:
- Removing the no longer needed sentinel,
- Limiting the number of loop iterations to the actual number of ROM types.

Fixes c7afe08496fa463e ("mtd: maps: physmap: Invert logic on if/else branch")
---
 drivers/mtd/maps/physmap-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/maps/physmap-core.c +2 -2
index 33b77bd9022ce251..e8c3b250d8421edc 100644
@@ -396,7 +396,7 @@ static int physmap_flash_of_init(struct platform_device *dev)
 #endif /* IS_ENABLED(CONFIG_MTD_PHYSMAP_OF) */
 
 static const char * const rom_probe_types[] = {
-	"cfi_probe", "jedec_probe", "qinfo_probe", "map_rom", NULL
+	"cfi_probe", "jedec_probe", "qinfo_probe", "map_rom",
 };
 
 static const char * const part_probe_types[] = {
@@ -524,7 +524,7 @@ static int physmap_flash_probe(struct platform_device *dev)
 		} else {
 			int j;
 
-			for (j = 0; ARRAY_SIZE(rom_probe_types); j++) {
+			for (j = 0; j < ARRAY_SIZE(rom_probe_types); j++) {
 				info->mtds[i] = do_map_probe(rom_probe_types[j],
 							     &info->maps[i]);
 				if (info->mtds[i])
Signature · 1 line
2.17.1
#1 lore raw
Quoted 13 lines · On Tue, 6 Nov 2018 22:44:16 +0100 Geert Uytterhoeven <[email protected]>…

On Toshiba RBTX4927, where map_probe is supposed to fail:

    Creating 2 MTD partitions on "physmap-flash.0":
    0x000000c00000-0x000001000000 : "boot"
    0x000000000000-0x000000c00000 : "user"
    physmap-flash physmap-flash.1: physmap platform flash device: [mem 0x1e000000-0x1effffff]
    CPU 0 Unable to handle kernel paging request at virtual address 00000000, epc == 80320f40, ra == 80321004
    ...
    Call Trace:
    [<80320f40>] get_mtd_chip_driver+0x30/0x8c
    [<80321004>] do_map_probe+0x20/0x90
    [<80328448>] physmap_flash_probe+0x484/0x4ec
Quoted 2 lines

The access to rom_probe_types[] was changed from a sentinel-based loop to an infinite loop, causing a crash when reaching the sentinel.

Oops. Do you mind if I fix that in-place (squash your changes in Ricardo's original commit)?

Quoted 34 lines

Fix this by:
- Removing the no longer needed sentinel,
- Limiting the number of loop iterations to the actual number of ROM types.

Fixes c7afe08496fa463e ("mtd: maps: physmap: Invert logic on if/else branch")
---
 drivers/mtd/maps/physmap-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/maps/physmap-core.c +2 -2
index 33b77bd9022ce251..e8c3b250d8421edc 100644
@@ -396,7 +396,7 @@ static int physmap_flash_of_init(struct platform_device *dev)
 #endif /* IS_ENABLED(CONFIG_MTD_PHYSMAP_OF) */
 
 static const char * const rom_probe_types[] = {
-	"cfi_probe", "jedec_probe", "qinfo_probe", "map_rom", NULL
+	"cfi_probe", "jedec_probe", "qinfo_probe", "map_rom",
 };
 
 static const char * const part_probe_types[] = {
@@ -524,7 +524,7 @@ static int physmap_flash_probe(struct platform_device *dev)
 		} else {
 			int j;
 
-			for (j = 0; ARRAY_SIZE(rom_probe_types); j++) {
+			for (j = 0; j < ARRAY_SIZE(rom_probe_types); j++) {
 				info->mtds[i] = do_map_probe(rom_probe_types[j],
 							     &info->maps[i]);
 				if (info->mtds[i])
#2 lore raw

Hi Boris,

Quoted 15 lines · Boris Brezillon
Quoted 13 lines · On Tue, 6 Nov 2018 22:44:16 +0100 Geert Uytterhoeven <[email protected]>…

On Toshiba RBTX4927, where map_probe is supposed to fail:

    Creating 2 MTD partitions on "physmap-flash.0":
    0x000000c00000-0x000001000000 : "boot"
    0x000000000000-0x000000c00000 : "user"
    physmap-flash physmap-flash.1: physmap platform flash device: [mem 0x1e000000-0x1effffff]
    CPU 0 Unable to handle kernel paging request at virtual address 00000000, epc == 80320f40, ra == 80321004
    ...
    Call Trace:
    [<80320f40>] get_mtd_chip_driver+0x30/0x8c
    [<80321004>] do_map_probe+0x20/0x90
    [<80328448>] physmap_flash_probe+0x484/0x4ec
Quoted 5 lines
Quoted 2 lines

The access to rom_probe_types[] was changed from a sentinel-based loop to an infinite loop, causing a crash when reaching the sentinel.

Oops. Do you mind if I fix that in-place (squash your changes in Ricardo's original commit)?

No problem. Thanks!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#3 lore raw
Quoted 24 lines · On Tue, 6 Nov 2018 23:19:14 +0100 Geert Uytterhoeven <[email protected]>…

Hi Boris,

Quoted 20 lines · Boris Brezillon
Quoted 13 lines · On Tue, 6 Nov 2018 22:44:16 +0100 Geert Uytterhoeven <[email protected]>…

On Toshiba RBTX4927, where map_probe is supposed to fail:

    Creating 2 MTD partitions on "physmap-flash.0":
    0x000000c00000-0x000001000000 : "boot"
    0x000000000000-0x000000c00000 : "user"
    physmap-flash physmap-flash.1: physmap platform flash device: [mem 0x1e000000-0x1effffff]
    CPU 0 Unable to handle kernel paging request at virtual address 00000000, epc == 80320f40, ra == 80321004
    ...
    Call Trace:
    [<80320f40>] get_mtd_chip_driver+0x30/0x8c
    [<80321004>] do_map_probe+0x20/0x90
    [<80328448>] physmap_flash_probe+0x484/0x4ec
Quoted 2 lines

The access to rom_probe_types[] was changed from a sentinel-based loop to an infinite loop, causing a crash when reaching the sentinel.

Oops. Do you mind if I fix that in-place (squash your changes in Ricardo's original commit)?

Done.

Quoted 2 lines

No problem. Thanks!

Thanks for reporting/fixing the bug.

Boris

#4 lore raw

Hi Boris and Geert

Quoted 23 lines · Boris Brezillon
Quoted 19 lines · On Tue, 6 Nov 2018 23:19:14 +0100 Geert Uytterhoeven <[email protected]>…

Hi Boris,

Quoted 15 lines · Boris Brezillon
Quoted 13 lines · On Tue, 6 Nov 2018 22:44:16 +0100 Geert Uytterhoeven <[email protected]>…

On Toshiba RBTX4927, where map_probe is supposed to fail:

    Creating 2 MTD partitions on "physmap-flash.0":
    0x000000c00000-0x000001000000 : "boot"
    0x000000000000-0x000000c00000 : "user"
    physmap-flash physmap-flash.1: physmap platform flash device: [mem 0x1e000000-0x1effffff]
    CPU 0 Unable to handle kernel paging request at virtual address 00000000, epc == 80320f40, ra == 80321004
    ...
    Call Trace:
    [<80320f40>] get_mtd_chip_driver+0x30/0x8c
    [<80321004>] do_map_probe+0x20/0x90
    [<80328448>] physmap_flash_probe+0x484/0x4ec
Quoted 11 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

The access to rom_probe_types[] was changed from a sentinel-based loop to an infinite loop, causing a crash when reaching the sentinel.

Oops. Do you mind if I fix that in-place (squash your changes in Ricardo's original commit)?

Done.

Quoted 2 lines

No problem. Thanks!

Thanks to both of you for fixing this .

Quoted 4 lines

Thanks for reporting/fixing the bug.

Boris

Signature · 1 line
Ricardo Ribalda