Openbmc archive mirror
 help / color / mirror / Atom feed
From: Tali Perry <tali.perry1@gmail.com>
To: Rand Deeb <rand.sec96@gmail.com>
Cc: lvc-project@linuxtesting.org,
	voskresenski.stanislav@confident.ru,
	Benjamin Fair <benjaminfair@google.com>,
	Avi Fishman <avifishman70@gmail.com>,
	Patrick Venture <venture@google.com>,
	openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	linux-i2c@vger.kernel.org, deeb.rand@confident.ru,
	Tomer Maimon <tmaimon77@gmail.com>
Subject: Re: [PATCH] i2c: Fix NULL pointer dereference in npcm_i2c_reg_slave
Date: Wed, 10 Jan 2024 10:43:38 +0200	[thread overview]
Message-ID: <CAHb3i=ttHrFw7NuL3qw1xdXDkGu9tOQdH+WuCMWgukmU6QrTKA@mail.gmail.com> (raw)
In-Reply-To: <20240109145121.8850-1-rand.sec96@gmail.com>

On Tue, Jan 9, 2024 at 4:52 PM Rand Deeb <rand.sec96@gmail.com> wrote:
>
> In the npcm_i2c_reg_slave function, a potential NULL pointer dereference
> issue occurs when 'client' is NULL. This patch adds a proper NULL check for
> 'client' at the beginning of the function to prevent undefined behavior.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Rand Deeb <rand.sec96@gmail.com>
> ---
>  drivers/i2c/busses/i2c-npcm7xx.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
> index c1b679737240..cfabfb50211d 100644
> --- a/drivers/i2c/busses/i2c-npcm7xx.c
> +++ b/drivers/i2c/busses/i2c-npcm7xx.c
> @@ -1243,13 +1243,14 @@ static irqreturn_t npcm_i2c_int_slave_handler(struct npcm_i2c *bus)
>  static int npcm_i2c_reg_slave(struct i2c_client *client)
>  {
>         unsigned long lock_flags;
> -       struct npcm_i2c *bus = i2c_get_adapdata(client->adapter);
> -
> -       bus->slave = client;
> +       struct npcm_i2c *bus;
>
> -       if (!bus->slave)
> +       if (!client)
>                 return -EINVAL;
>
> +       bus = i2c_get_adapdata(client->adapter);
> +       bus->slave = client;
> +
>         if (client->flags & I2C_CLIENT_TEN)
>                 return -EAFNOSUPPORT;
>
> --
> 2.34.1
>


Thanks for the patch!

Reviewed-by:tali.perry1@gmail.com

  reply	other threads:[~2024-01-10  8:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09 14:51 [PATCH] i2c: Fix NULL pointer dereference in npcm_i2c_reg_slave Rand Deeb
2024-01-10  8:43 ` Tali Perry [this message]
2024-01-10  9:23   ` Re: [lvc-project] " Fedor Pchelkin
2024-02-03 20:44     ` Wolfram Sang
2024-02-04  8:54       ` Fedor Pchelkin
2024-02-04 10:01         ` Rand Deeb
2024-02-04 10:12         ` Rand Deeb

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='CAHb3i=ttHrFw7NuL3qw1xdXDkGu9tOQdH+WuCMWgukmU6QrTKA@mail.gmail.com' \
    --to=tali.perry1@gmail.com \
    --cc=avifishman70@gmail.com \
    --cc=benjaminfair@google.com \
    --cc=deeb.rand@confident.ru \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=openbmc@lists.ozlabs.org \
    --cc=rand.sec96@gmail.com \
    --cc=tmaimon77@gmail.com \
    --cc=venture@google.com \
    --cc=voskresenski.stanislav@confident.ru \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).