]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mtd: mtdpart: fix uninitialized erasesize on MTDPART_OFS_RETAIN error path
authorNikolay Ivchenko <nivchenko.dev@gmail.com>
Sat, 20 Jun 2026 17:06:03 +0000 (20:06 +0300)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 29 Jun 2026 14:42:42 +0000 (16:42 +0200)
When parsing partition layouts, if a partition requested with
MTDPART_OFS_RETAIN runs out of space, the allocator jumps directly
to 'out_register' to preserve partition numbering.

However, this jump bypasses child->erasesize initialization, leaving
it at zero. When add_mtd_device() is later called on this child, the
registration fails and triggers a WARN_ON() due to the zero ->erasesize.

Fix this by zeroing out child->part.offset and child->part.size, and
initializing child->erasesize to parent->erasesize. This is the exact
same pattern already used just a few lines below in the "out of reach"
error check (child->part.offset >= parent_size) to safely register a
disabled partition.

Reported-by: syzbot+3ae80219c633aca5431c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=3ae80219c633aca5431c
Signed-off-by: Nikolay Ivchenko <nivchenko.dev@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/mtdpart.c

index 795a94e6b482fd076ed71f9fabfe8c73be84f556..7f23f8a1b59c58f88a91d3906ddf39083e6698e6 100644 (file)
@@ -118,6 +118,9 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
                                part->name, parent_size - child->part.offset,
                                child->part.size);
                        /* register to preserve ordering */
+                       child->part.offset = 0;
+                       child->part.size = 0;
+                       child->erasesize = parent->erasesize;
                        goto out_register;
                }
        }