[PATCH 2/2] ext4: Fix zalloc()

Tom Rini trini at konsulko.com
Thu Jul 11 17:45:17 CEST 2024


On Tue, Jul 02, 2024 at 09:42:23PM +0200, Richard Weinberger wrote:

> The zalloc() function suffers from two problems.
> 1. If memalign() fails it will return NULL and memset() will use a NULL pointer.
> 2. 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 at 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.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20240711/a8e16b78/attachment.sig>


More information about the U-Boot mailing list