* [PATCH] tpm: st33zp24: check if chip is null before dereferencing
@ 2018-04-06 16:05 Colin King
2018-04-06 16:07 ` Jason Gunthorpe
2018-04-10 13:50 ` Sasha Levin
0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2018-04-06 16:05 UTC (permalink / raw)
To: Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe, Arnd Bergmann,
Greg Kroah-Hartman, linux-integrity
Cc: kernel-janitors, linux-kernel
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
--- a/drivers/char/tpm/st33zp24/st33zp24.c
+++ 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;
@@ -378,6 +378,7 @@ static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf,
if (len < TPM_HEADER_SIZE)
return -EBUSY;
+ tpm_dev = dev_get_drvdata(&chip->dev);
ret = request_locality(chip);
if (ret < 0)
return ret;
--
2.15.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tpm: st33zp24: check if chip is null before dereferencing
2018-04-06 16:05 [PATCH] tpm: st33zp24: check if chip is null before dereferencing Colin King
@ 2018-04-06 16:07 ` Jason Gunthorpe
2018-04-10 13:50 ` Sasha Levin
1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2018-04-06 16:07 UTC (permalink / raw)
To: Colin King
Cc: Peter Huewe, Jarkko Sakkinen, Arnd Bergmann, Greg Kroah-Hartman,
linux-integrity, kernel-janitors, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tpm: st33zp24: check if chip is null before dereferencing
2018-04-06 16:05 [PATCH] tpm: st33zp24: check if chip is null before dereferencing Colin King
2018-04-06 16:07 ` Jason Gunthorpe
@ 2018-04-10 13:50 ` Sasha Levin
1 sibling, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2018-04-10 13:50 UTC (permalink / raw)
To: Sasha Levin, Colin King, Colin Ian King, Peter Huewe
Cc: kernel-janitors, linux-kernel, stable
Hi,
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag,
fixing commit: 9e0d39d8a6a0 tpm: Remove useless priv field in struct tpm_vendor_specific.
The bot has also determined it's probably a bug fixing patch. (score: 19.6716)
The bot has tested the following trees: v4.16.1, v4.15.16, v4.14.33, v4.9.93.
v4.16.1: Build OK!
v4.15.16: Build OK!
v4.14.33: Build OK!
v4.9.93: Build OK!
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-10 13:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-06 16:05 [PATCH] tpm: st33zp24: check if chip is null before dereferencing Colin King
2018-04-06 16:07 ` Jason Gunthorpe
2018-04-10 13:50 ` Sasha Levin
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 NNTP newsgroup(s).