* [PATCH] nftl_format: prevent unsigned underflow in INFTL virtual unit calculation
@ 2026-01-27 12:31 Anton Moryakov
0 siblings, 0 replies; only message in thread
From: Anton Moryakov @ 2026-01-27 12:31 UTC (permalink / raw)
To: linux-mtd; +Cc: David Oberhollenzer, Anton Moryakov
When formatting an INFTL partition, the code computes:
numvunits = (ezones - 2) * PERCENTUSED / 100;
If ezones < 2 (e.g. due to user specifying start offset >= device size),
this causes an unsigned underflow, leading to a huge and invalid numvunits.
Add a guard to ensure ezones >= 2 before subtraction. If not, abort with
an error message, as a valid INFTL partition requires at least two erase
blocks for media headers.
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
nand-utils/nftl_format.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/nand-utils/nftl_format.c b/nand-utils/nftl_format.c
index c8b8b50..3667be3 100644
--- a/nand-utils/nftl_format.c
+++ b/nand-utils/nftl_format.c
@@ -371,6 +371,8 @@ int main(int argc, char **argv)
maxzones = meminfo.size / meminfo.erasesize;
pezstart = startofs / meminfo.erasesize + 1;
pezend = startofs / meminfo.erasesize + ezones - 1;
+ if (ezones < 2)
+ exit(EXIT_FAILURE);
numvunits = (ezones - 2) * PERCENTUSED / 100;
for (ezone = pezstart; ezone < maxzones; ezone++) {
if (BadUnitTable[ezone] != ZONE_GOOD) {
--
2.39.2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-01-27 12:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-27 12:31 [PATCH] nftl_format: prevent unsigned underflow in INFTL virtual unit calculation Anton Moryakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox