* [PATCH] mtd: mtdpart: fix uninitialized erasesize on MTDPART_OFS_RETAIN error path
@ 2026-06-20 17:06 Nikolay Ivchenko
2026-06-29 14:44 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Nikolay Ivchenko @ 2026-06-20 17:06 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr
Cc: linux-mtd, linux-kernel, syzbot+3ae80219c633aca5431c, Nikolay Ivchenko
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>
---
drivers/mtd/mtdpart.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 795a94e6b482..7f23f8a1b59c 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -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;
}
}
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: mtdpart: fix uninitialized erasesize on MTDPART_OFS_RETAIN error path
2026-06-20 17:06 [PATCH] mtd: mtdpart: fix uninitialized erasesize on MTDPART_OFS_RETAIN error path Nikolay Ivchenko
@ 2026-06-29 14:44 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2026-06-29 14:44 UTC (permalink / raw)
To: richard, vigneshr, Nikolay Ivchenko
Cc: linux-mtd, linux-kernel, syzbot+3ae80219c633aca5431c
On Sat, 20 Jun 2026 20:06:03 +0300, Nikolay Ivchenko wrote:
> 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.
>
> [...]
Applied to mtd/fixes, thanks!
[1/1] mtd: mtdpart: fix uninitialized erasesize on MTDPART_OFS_RETAIN error path
commit: ae9d8058f13238cad5f5d16f676da91187684581
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-29 14:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-20 17:06 [PATCH] mtd: mtdpart: fix uninitialized erasesize on MTDPART_OFS_RETAIN error path Nikolay Ivchenko
2026-06-29 14:44 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome