From: Tom Rini <trini@konsulko.com>
To: Richard Weinberger <richard@nod.at>
Cc: u-boot@lists.denx.de, Jixiong.Hu@mediatek.com, sjg@chromium.org,
patrick.delaunay@foss.st.com, ilias.apalodimas@linaro.org,
seanga2@gmail.com, xypron.glpk@gmx.de,
upstream+uboot@sigma-star.at
Subject: Re: [PATCH 2/2] ext4: Fix zalloc()
Date: Thu, 11 Jul 2024 09:45:17 -0600 [thread overview]
Message-ID: <20240711154517.GA2391959@bill-the-cat> (raw)
In-Reply-To: <20240702194223.31998-2-richard@nod.at>
[-- Attachment #1: Type: text/plain, Size: 1556 bytes --]
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@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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
next prev parent reply other threads:[~2024-07-11 15:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 19:42 [PATCH 1/2] ext4: Fix integer overflow in ext4fs_read_symlink() Richard Weinberger
2024-07-02 19:42 ` [PATCH 2/2] ext4: Fix zalloc() Richard Weinberger
2024-07-11 15:45 ` Tom Rini [this message]
2024-07-12 7:59 ` Richard Weinberger
2024-07-12 11:15 ` Heinrich Schuchardt
2024-07-12 11:29 ` Richard Weinberger
2024-07-12 11:10 ` [PATCH 1/2] ext4: Fix integer overflow in ext4fs_read_symlink() Heinrich Schuchardt
2024-07-12 11:14 ` Richard Weinberger
2024-07-12 11:19 ` Heinrich Schuchardt
2024-07-12 11:26 ` Richard Weinberger
2024-07-12 16:54 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240711154517.GA2391959@bill-the-cat \
--to=trini@konsulko.com \
--cc=Jixiong.Hu@mediatek.com \
--cc=ilias.apalodimas@linaro.org \
--cc=patrick.delaunay@foss.st.com \
--cc=richard@nod.at \
--cc=seanga2@gmail.com \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
--cc=upstream+uboot@sigma-star.at \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.