diff mbox

[v2] hwmon:(stts751) buffer overread on wrong chip configuration

Message ID 1502383592-14389-1-git-send-email-vasilyev@ispras.ru (mailing list archive)
State Accepted
Headers show

Commit Message

Anton Vasilyev Aug. 10, 2017, 4:46 p.m. UTC
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 stored on chip.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
---
v2: Fixed Guenter's remark about comparison
---
 drivers/hwmon/stts751.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Guenter Roeck Aug. 13, 2017, 1:34 p.m. UTC | #1
On Thu, Aug 10, 2017 at 07:46:32PM +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 stored on chip.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>

Applied (after s/path/patch/)

Thanks,
Guenter

> ---
> v2: Fixed Guenter's remark about comparison
> ---
>  drivers/hwmon/stts751.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c
> index d56251d..3f940fb 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,
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c
index d56251d..3f940fb 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,