lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201105141549.GA1389@roeck-us.net>
Date:   Thu, 5 Nov 2020 06:15:49 -0800
From:   Guenter Roeck <linux@...ck-us.net>
To:     Wilken Gottwalt <wilken.gottwalt@...teo.net>
Cc:     Colin King <colin.king@...onical.com>,
        Jean Delvare <jdelvare@...e.com>, linux-hwmon@...r.kernel.org,
        kernel-janitors@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH][next] hwmon: corsair-psu: fix unintentional sign
 extension issue

On Thu, Nov 05, 2020 at 01:32:33PM +0100, Wilken Gottwalt wrote:
> On Thu,  5 Nov 2020 11:50:19 +0000
> Colin King <colin.king@...onical.com> wrote:
> 
> > From: Colin Ian King <colin.king@...onical.com>
> > 
> > The shifting of the u8 integer data[3] by 24 bits to the left will
> > be promoted to a 32 bit signed int and then sign-extended to a
> > long. In the event that the top bit of data[3] is set then all
> > then all the upper 32 bits of a 64 bit long end up as also being
> > set because of the sign-extension. Fix this by casting data[3] to
> > a long before the shift.
> > 
> > Addresses-Coverity: ("Unintended sign extension")
> > Fixes: ce15cd2cee8b ("hwmon: add Corsair PSU HID controller driver")
> > Signed-off-by: Colin Ian King <colin.king@...onical.com>
> > ---
> >  drivers/hwmon/corsair-psu.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
> > index e92d0376e7ac..5d19a888231a 100644
> > --- a/drivers/hwmon/corsair-psu.c
> > +++ b/drivers/hwmon/corsair-psu.c
> > @@ -241,7 +241,7 @@ static int corsairpsu_get_value(struct corsairpsu_data *priv, u8 cmd, u8
> > rail, l
> >  	 * the LINEAR11 conversion are the watts values which are about 1200 for the strongest
> > psu
> >  	 * supported (HX1200i)
> >  	 */
> > -	tmp = (data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0];
> > +	tmp = ((long)data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0];
> >  	switch (cmd) {
> >  	case PSU_CMD_IN_VOLTS:
> >  	case PSU_CMD_IN_AMPS:
> 
> Yeah, this could happen if the uptime value in the micro-controller gets bigger
> than 68 years (in seconds), and it is the only value which actually uses more
> than 2 bytes for the representation. So what about architectures which are 32 bit
> wide and where a long has 32 bits? I guess this simple cast is not enough.
> 

The hwmon subsystem uses 'long' to pass values back to the core.
While that may be a bit unfortunate as it doesn't support uptimes
of more than 68 years in seconds, we are not going to change the
hwmon core to accommodate it. If the incoming data is always
expected to be positive, and you don't want to risk the overflow,
feel free to either use "data[3] & 0x7f" instead, or max out the
result at INT_MAX (from <linux/limits.h>).

Thanks,
Guenter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ