All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@sigma-star.at>
To: Richard Weinberger <richard@nod.at>, upstream@sigma-star.at
Cc: sjg@chromium.org, Jixiong.Hu@mediatek.com,
	marek.vasut+renesas@mailbox.org, patrick.delaunay@foss.st.com,
	ilias.apalodimas@linaro.org, seanga2@gmail.com,
	trini@konsulko.com, upstream+uboot@sigma-star.at,
	u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>
Subject: Re: [PATCH v2 1/3] ext4: Fix integer overflow in ext4fs_read_symlink()
Date: Fri, 09 Aug 2024 18:29:34 +0200	[thread overview]
Message-ID: <39167592.RpJgFE2GTS@somecomputer> (raw)
In-Reply-To: <04ba0220-864c-40cf-bdc4-73ae6137b704@gmx.de>

Heinrich,

Am Freitag, 9. August 2024, 18:13:27 CEST schrieb 'Heinrich Schuchardt' via upstream:
> Thank you for pointing at the problematic code.
> 
> You are calling __builtin_add_overflow(int, int, size_t *).
> 
> __builtin_add_overflow() is not defined in the C-standard.
> 
> Is there any well defined behavior for this on systems where size_t has
> more bits than int?

https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html says:

Built-in Function: bool __builtin_add_overflow (type1 a, type2 b, type3 *res)

These built-in functions promote the first two operands into infinite precision signed type and perform addition on those promoted operands.
The result is then cast to the type the third pointer argument points to and stored there.
If the stored result is equal to the infinite precision result, the built-in functions return false, otherwise they return true.
As the addition is performed in infinite signed precision, these built-in functions have fully defined behavior for all argument values. 

So, I don't really see a problem here.

> I could imagine implementations just copying an int to the first 32 bits
> of alloc_size and leaving the other bits untouched.
> 
> Hopefully your C-compiler simply refuses to compile this code.
> 
> I would prefer to stick to standard C:
> 
> alloc_size = le32_to_cpu(diro->inode.size) + 1UL;
> if (!alloc_size)
> 	return NULL;
> 
> Here an overflow can only occur on 32bit systems.

In this specific case we could avoid the builtis, yes.
But I prefer using __builtin_add_overflow() as it offers a generic
and bullet prove mechanism to avoid these kind of bugs.

It's not that they are something new and funky.
Other projects use them since ages.

Thanks,
//richard

-- 
​​​​​sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT
UID/VAT Nr: ATU 66964118 | FN: 374287y



  reply	other threads:[~2024-08-09 16:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09  9:54 [PATCH v2 1/3] ext4: Fix integer overflow in ext4fs_read_symlink() Richard Weinberger
2024-08-09  9:54 ` [PATCH v2 2/3] compiler: Ensure __builtin_*_overflow() support Richard Weinberger
2024-08-09  9:54 ` [PATCH v2 3/3] ext4: Fix zalloc() Richard Weinberger
2024-08-09 10:45   ` Heinrich Schuchardt
2024-08-26 10:28   ` Ilias Apalodimas
2024-08-09 16:13 ` [PATCH v2 1/3] ext4: Fix integer overflow in ext4fs_read_symlink() Heinrich Schuchardt
2024-08-09 16:29   ` Richard Weinberger [this message]
2024-08-09 22:02     ` Tom Rini
2024-08-16  3:47 ` 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=39167592.RpJgFE2GTS@somecomputer \
    --to=richard@sigma-star.at \
    --cc=Jixiong.Hu@mediatek.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=patrick.delaunay@foss.st.com \
    --cc=richard@nod.at \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=upstream+uboot@sigma-star.at \
    --cc=upstream@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.