
On Tue, Jul 02, 2024 at 09:42:23PM +0200, Richard Weinberger wrote:
The zalloc() function suffers from two problems.
- If memalign() fails it will return NULL and memset() will use a NULL pointer.
- memalign() itself seems to crash when more than 2^32 bytes are requested.
So, check the return value of memalign() and allocate only of size is less than CONFIG_SYS_MALLOC_LEN.
Signed-off-by: Richard Weinberger richard@nod.at
FWIW, I didn't investigate further why memalign() fails for large sizes. Maybe this is an issue on it's own.
Thanks, //richard
fs/ext4/ext4_common.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h index 84500e990a..0d1f72ae01 100644 --- a/fs/ext4/ext4_common.h +++ b/fs/ext4/ext4_common.h @@ -43,8 +43,14 @@
static inline void *zalloc(size_t size) {
- void *p = memalign(ARCH_DMA_MINALIGN, size);
- memset(p, 0, size);
- void *p = NULL;
- if (size < CONFIG_SYS_MALLOC_LEN)
p = memalign(ARCH_DMA_MINALIGN, size);
- if (p)
memset(p, 0, size);
- return p;
}
The problem here is that "zalloc" is inline and so this change causes about 1KiB of growth on platforms which enable ext4 and so at least mx6sabresd now overflows it's maximum size. Looking harder, I think the best solution here would be for ext4 to stop using its own wrapper and instead call our kzalloc compatibility function.