From khali@linux-fr.org Mon Nov 14 13:55:35 2005 Date: Mon, 14 Nov 2005 23:08:38 +0100 From: Jean Delvare To: Greg KH Cc: Yuan Mu Subject: [PATCH] hwmon: Fix missing boundary check when setting W83627THF in0 limits Message-Id: <20051114230838.37a9f2d8.khali@linux-fr.org> Content-Disposition: inline; filename=hwmon-w83627hf-missing-in0-limit-check.patch From: Yuan Mu Add SENSORS_LIMIT in store VCore limit functions. This fixes a potential u8 overflow on out-of-range user input. Signed-off-by: Jean Delvare Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/w83627hf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- gregkh-2.6.orig/drivers/hwmon/w83627hf.c +++ gregkh-2.6/drivers/hwmon/w83627hf.c @@ -456,7 +456,9 @@ static ssize_t store_regs_in_min0(struct (w83627thf == data->type || w83637hf == data->type)) /* use VRM9 calculation */ - data->in_min[0] = (u8)(((val * 100) - 70000 + 244) / 488); + data->in_min[0] = + SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, + 255); else /* use VRM8 (standard) calculation */ data->in_min[0] = IN_TO_REG(val); @@ -481,7 +483,9 @@ static ssize_t store_regs_in_max0(struct (w83627thf == data->type || w83637hf == data->type)) /* use VRM9 calculation */ - data->in_max[0] = (u8)(((val * 100) - 70000 + 244) / 488); + data->in_max[0] = + SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, + 255); else /* use VRM8 (standard) calculation */ data->in_max[0] = IN_TO_REG(val);