From: Peter Rosin <peda@axentia.se>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Wolfram Sang <wsa@kernel.org>,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] i2c: mux: harden i2c_mux_alloc() against integer overflows
Date: Thu, 15 Sep 2022 15:36:58 +0200 [thread overview]
Message-ID: <04c933c3-499a-e13b-c25d-a60e601dbd8b@axentia.se> (raw)
In-Reply-To: <YyMM8iVSHJ4ammsg@kili>
Hi Dan,
2022-09-15 at 13:30, Dan Carpenter wrote:
> A couple years back we went through the kernel an automatically
> converted size calculations to use struct_size() instead. The
> struct_size() calculation is protected against integer overflows.
>
> However it does not make sense to use the result from struct_size()
> for additional math operations as that would negate any safeness.
Indeed. Nice catch!
> Fixes: 1f3b69b6b939 ("i2c: mux: Use struct_size() in devm_kzalloc()")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Peter Rosin <peda@axentia.se>
Cheers,
Peter
> ---
> drivers/i2c/i2c-mux.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
> index 774507b54b57..313904be5f3b 100644
> --- a/drivers/i2c/i2c-mux.c
> +++ b/drivers/i2c/i2c-mux.c
> @@ -243,9 +243,10 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
> int (*deselect)(struct i2c_mux_core *, u32))
> {
> struct i2c_mux_core *muxc;
> + size_t mux_size;
>
> - muxc = devm_kzalloc(dev, struct_size(muxc, adapter, max_adapters)
> - + sizeof_priv, GFP_KERNEL);
> + mux_size = struct_size(muxc, adapter, max_adapters);
> + muxc = devm_kzalloc(dev, size_add(mux_size, sizeof_priv), GFP_KERNEL);
> if (!muxc)
> return NULL;
> if (sizeof_priv)
next prev parent reply other threads:[~2022-09-15 13:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-15 11:30 Dan Carpenter
2022-09-15 13:36 ` Peter Rosin [this message]
2022-09-15 13:51 ` Gustavo A. R. Silva
2022-09-15 14:09 ` Dan Carpenter
2022-09-16 8:07 ` Kees Cook
2022-09-16 8:23 ` Dan Carpenter
2022-09-16 13:31 ` Kees Cook
2022-09-16 14:55 ` Dan Carpenter
2022-09-16 21:31 ` Kees Cook
2022-09-16 8:01 ` Kees Cook
2022-09-16 8:20 ` Dan Carpenter
2022-09-16 19:31 ` Wolfram Sang
2022-09-19 6:35 ` Dan Carpenter
2022-09-21 20:13 ` Wolfram Sang
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=04c933c3-499a-e13b-c25d-a60e601dbd8b@axentia.se \
--to=peda@axentia.se \
--cc=dan.carpenter@oracle.com \
--cc=gustavo@embeddedor.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wsa@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®