From: Jason Gunthorpe <jgg@ziepe.ca>
To: Colin King <colin.king@canonical.com>
Cc: Peter Huewe <peterhuewe@gmx.de>,
Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-integrity@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tpm: st33zp24: check if chip is null before dereferencing
Date: Fri, 06 Apr 2018 16:07:11 +0000 [thread overview]
Message-ID: <20180406160711.GA14097@ziepe.ca> (raw)
In-Reply-To: <20180406160541.8188-1-colin.king@canonical.com>
On Fri, Apr 06, 2018 at 05:05:41PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently chip is being dereferenced by the call to dev_get_drvdata
> before it is being null checked, hence we have a potential null
> pointer dereference bug. Fix this by only dereferencing it after the
> null check.
>
> Detected by CoverityScan, CID#1357806 ("Dereference before null check")
>
> Fixes: 9e0d39d8a6a0 ("tpm: Remove useless priv field in struct tpm_vendor_specific")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> drivers/char/tpm/st33zp24/st33zp24.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c
> index f95b9c75175b..476865d66a0e 100644
> +++ b/drivers/char/tpm/st33zp24/st33zp24.c
> @@ -367,7 +367,7 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
> static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf,
> size_t len)
> {
> - struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
> + struct st33zp24_dev *tpm_dev;
> u32 status, i, size, ordinal;
> int burstcnt = 0;
> int ret;
Chip can't be NULL here, so I would prefer to see the NULL test
deleted.
Thanks,
Jason
next prev parent reply other threads:[~2018-04-06 16:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-06 16:05 [PATCH] tpm: st33zp24: check if chip is null before dereferencing Colin King
2018-04-06 16:07 ` Jason Gunthorpe [this message]
2018-04-10 13:50 ` Sasha Levin
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=20180406160711.GA14097@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=arnd@arndb.de \
--cc=colin.king@canonical.com \
--cc=gregkh@linuxfoundation.org \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox