summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Vasilyev <vasilyev@ispras.ru>2017-08-10 12:46:32 -0400
committerGuenter Roeck <linux@roeck-us.net>2017-08-13 11:24:08 -0400
commit3be6bd690da0dafa55eb65279fb25297fcfe19d5 (patch)
tree8334fcb24a1feafc8fbb7672e4cfc5a01d84c144
parent7576750f036b5ec913aac2a165ce75ab3b7beee3 (diff)
hwmon: (stts751) buffer overrun on wrong chip configuration
If stts751 hw by some reason reports conversion rate bigger then 9: ret = i2c_smbus_read_byte_data(priv->client, STTS751_REG_RATE); then dereferencing stts751_intervals[priv->interval] leads to buffer overrun. The patch adds sanity check for value stored on chip. Found by Linux Driver Verification project (linuxtesting.org). Fixes: 7f07ec0fa17a ("hwmon: new driver for ST stts751 thermal sensor") Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/stts751.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c
index d56251d6eec2..3f940fb67dc6 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)
718 ret = i2c_smbus_read_byte_data(priv->client, STTS751_REG_RATE); 718 ret = i2c_smbus_read_byte_data(priv->client, STTS751_REG_RATE);
719 if (ret < 0) 719 if (ret < 0)
720 return ret; 720 return ret;
721 if (ret >= ARRAY_SIZE(stts751_intervals)) {
722 dev_err(priv->dev, "Unrecognized conversion rate 0x%x\n", ret);
723 return -ENODEV;
724 }
721 priv->interval = ret; 725 priv->interval = ret;
722 726
723 ret = stts751_read_reg16(priv, &priv->event_max, 727 ret = stts751_read_reg16(priv, &priv->event_max,