Skip to content

Commit 2cc0b1a

Browse files
Nicolas Pitredlezcano
authored andcommitted
thermal/drivers/mediatek/lvts_thermal: Guard against efuse data buffer overflow
We don't want to silently fetch garbage past the actual buffer. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5b3367e commit 2cc0b1a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/thermal/mediatek/lvts_thermal.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,14 +672,20 @@ static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
672672
*/
673673
static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
674674
const struct lvts_ctrl_data *lvts_ctrl_data,
675-
u8 *efuse_calibration)
675+
u8 *efuse_calibration,
676+
size_t calib_len)
676677
{
677678
int i;
678679

679680
for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++) {
680681
const struct lvts_sensor_data *sensor =
681682
&lvts_ctrl_data->lvts_sensor[i];
682683

684+
if (sensor->cal_offsets[0] >= calib_len ||
685+
sensor->cal_offsets[1] >= calib_len ||
686+
sensor->cal_offsets[2] >= calib_len)
687+
return -EINVAL;
688+
683689
lvts_ctrl->calibration[i] =
684690
(efuse_calibration[sensor->cal_offsets[0]] << 0) +
685691
(efuse_calibration[sensor->cal_offsets[1]] << 8) +
@@ -791,7 +797,8 @@ static int lvts_ctrl_init(struct device *dev, struct lvts_domain *lvts_td,
791797

792798
ret = lvts_calibration_init(dev, &lvts_ctrl[i],
793799
&lvts_data->lvts_ctrl[i],
794-
lvts_td->calib);
800+
lvts_td->calib,
801+
lvts_td->calib_len);
795802
if (ret)
796803
return ret;
797804

0 commit comments

Comments
 (0)