* [PATCH] hwmon:(stts751) buffer overread on wrong chip configuration
@ 2017-08-10 15:23 Anton Vasilyev
2017-08-10 16:15 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Anton Vasilyev @ 2017-08-10 15:23 UTC (permalink / raw)
To: Jean Delvare
Cc: Anton Vasilyev, Guenter Roeck, linux-hwmon, linux-kernel, ldv-project
If stts751 hw by some reason reports conversion rate bigger then 9:
ret = i2c_smbus_read_byte_data(priv->client, STTS751_REG_RATE);
then dereference stts751_intervals[priv->interval] leads to buffer
overread.
The path adds sanity check for value read from chip.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
---
drivers/hwmon/stts751.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c
index d56251d..f6eddbd 100644
--- a/drivers/hwmon/stts751.c
+++ b/drivers/hwmon/stts751.c
@@ -718,6 +718,10 @@ static int stts751_read_chip_config(struct stts751_priv *priv)
ret = i2c_smbus_read_byte_data(priv->client, STTS751_REG_RATE);
if (ret < 0)
return ret;
+ if (ret > ARRAY_SIZE(stts751_intervals)) {
+ dev_err(priv->dev, "Unrecognized conversion rate 0x%x\n", ret);
+ return -ENODEV;
+ }
priv->interval = ret;
ret = stts751_read_reg16(priv, &priv->event_max,
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] hwmon:(stts751) buffer overread on wrong chip configuration
2017-08-10 15:23 [PATCH] hwmon:(stts751) buffer overread on wrong chip configuration Anton Vasilyev
@ 2017-08-10 16:15 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2017-08-10 16:15 UTC (permalink / raw)
To: Anton Vasilyev; +Cc: Jean Delvare, linux-hwmon, linux-kernel, ldv-project
On Thu, Aug 10, 2017 at 06:23:34PM +0300, Anton Vasilyev wrote:
> If stts751 hw by some reason reports conversion rate bigger then 9:
> ret = i2c_smbus_read_byte_data(priv->client, STTS751_REG_RATE);
> then dereference stts751_intervals[priv->interval] leads to buffer
> overread.
>
> The path adds sanity check for value read from chip.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
> ---
> drivers/hwmon/stts751.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c
> index d56251d..f6eddbd 100644
> --- a/drivers/hwmon/stts751.c
> +++ b/drivers/hwmon/stts751.c
> @@ -718,6 +718,10 @@ static int stts751_read_chip_config(struct stts751_priv *priv)
> ret = i2c_smbus_read_byte_data(priv->client, STTS751_REG_RATE);
> if (ret < 0)
> return ret;
> + if (ret > ARRAY_SIZE(stts751_intervals)) {
Great catch, but should this be >= ?
Guenter
> + dev_err(priv->dev, "Unrecognized conversion rate 0x%x\n", ret);
> + return -ENODEV;
> + }
> priv->interval = ret;
>
> ret = stts751_read_reg16(priv, &priv->event_max,
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-08-10 16:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-10 15:23 [PATCH] hwmon:(stts751) buffer overread on wrong chip configuration Anton Vasilyev
2017-08-10 16:15 ` Guenter Roeck
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).