[PATCH v3 05/10] ext4: Check for overflow of block count
Simon Glass
sjg at chromium.org
Sat May 10 15:06:11 CEST 2025
An overflow could cause too little memory to be allocated, thus
potentially causing undefined behaviour. Add a check for overflow.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
(no changes since v1)
fs/ext4/ext4_write.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index 86420d1c9d7..ae26354fbb2 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -25,6 +25,7 @@
#include <malloc.h>
#include <memalign.h>
#include <part.h>
+#include <linux/overflow.h>
#include <linux/stat.h>
#include <div64.h>
#include "ext4_common.h"
@@ -111,7 +112,8 @@ int ext4fs_get_bgdtable(void)
size_t alloc_size;
int gdsize_total;
- alloc_size = fs->no_blkgrp * fs->gdsize;
+ if (check_mul_overflow(fs->no_blkgrp, fs->gdsize, &alloc_size))
+ return -1;
gdsize_total = ROUND(alloc_size, fs->blksz);
fs->no_blk_pergdt = gdsize_total / fs->blksz;
--
2.43.0
More information about the U-Boot
mailing list