linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* nct6775: UBSAN: shift exponent 32 is too large for 32-bit type 'long unsigned int'
@ 2018-06-12 21:50 Paul Menzel
  2018-06-12 22:12 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Menzel @ 2018-06-12 21:50 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare; +Cc: linux-hwmon, linux-kernel

Dear Guenther, dear Jean,


Building Linux with the undefined behavior sanitizer (UBSAN), loading 
the module *nct6775* on the ASRock E350M1 shows the error below.

```
[   28.322775] UBSAN: Undefined behaviour in drivers/hwmon/nct6775.c:4179:27
[   28.322833] shift exponent 32 is too large for 32-bit type 'long 
unsigned int'
```

I believe this was introduced by commit cc66b3038254 (hwmon: (nct6775) 
Rework temperature source and label handling), but the same issue was 
already present before.

```
-       for (i = 0; i < data->temp_label_num - 1; i++) {
+       for (i = 0; i < 32; i++) {
+               if (!(data->temp_mask & BIT(i + 1)))
+                       continue;
```

`include/linux/bitops.h` has the macros below.

```
#define BIT(nr)                 (1UL << (nr))
#define BIT_ULL(nr)             (1ULL << (nr))
```

Maybe `BIT_ULL` should be used, but I do not know, if that’d would work 
with `data->temp_mask`, which has type `u32`.


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: nct6775: UBSAN: shift exponent 32 is too large for 32-bit type 'long unsigned int'
  2018-06-12 21:50 nct6775: UBSAN: shift exponent 32 is too large for 32-bit type 'long unsigned int' Paul Menzel
@ 2018-06-12 22:12 ` Guenter Roeck
  2018-06-13  6:57   ` Paul Menzel
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2018-06-12 22:12 UTC (permalink / raw)
  To: Paul Menzel; +Cc: Jean Delvare, linux-hwmon, linux-kernel

Hi Paul,

On Tue, Jun 12, 2018 at 11:50:45PM +0200, Paul Menzel wrote:
> Dear Guenther, dear Jean,
> 
> 
> Building Linux with the undefined behavior sanitizer (UBSAN), loading the
> module *nct6775* on the ASRock E350M1 shows the error below.
> 
> ```
> [   28.322775] UBSAN: Undefined behaviour in drivers/hwmon/nct6775.c:4179:27
> [   28.322833] shift exponent 32 is too large for 32-bit type 'long unsigned
> int'
> ```
> 
> I believe this was introduced by commit cc66b3038254 (hwmon: (nct6775)
> Rework temperature source and label handling), but the same issue was
> already present before.
> 

I don't think so. The code used to be
	for (i = 0; i < data->temp_label_num - 1; i++) {
Notice the "- 1". So it should be
	for (i = 0; i < 31; i++) {

In practice it doesn't matter because "data->temp_mask & BIT(31 + 1)"
will always be false, causing the last loop iteration to abort, but
it is nevertheless wrong.

Thanks a lot for the report. I'll prepare a patch.

Guenter

> ```
> -       for (i = 0; i < data->temp_label_num - 1; i++) {
> +       for (i = 0; i < 32; i++) {
> +               if (!(data->temp_mask & BIT(i + 1)))
> +                       continue;
> ```
> 
> `include/linux/bitops.h` has the macros below.
> 
> ```
> #define BIT(nr)                 (1UL << (nr))
> #define BIT_ULL(nr)             (1ULL << (nr))
> ```
> 
> Maybe `BIT_ULL` should be used, but I do not know, if that’d would work with
> `data->temp_mask`, which has type `u32`.
> 
> 
> Kind regards,
> 
> Paul

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: nct6775: UBSAN: shift exponent 32 is too large for 32-bit type 'long unsigned int'
  2018-06-12 22:12 ` Guenter Roeck
@ 2018-06-13  6:57   ` Paul Menzel
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Menzel @ 2018-06-13  6:57 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Jean Delvare, linux-hwmon, linux-kernel

Dear Guenter,


Am 13.06.2018 um 00:12 schrieb Guenter Roeck:

> On Tue, Jun 12, 2018 at 11:50:45PM +0200, Paul Menzel wrote:

>> Building Linux with the undefined behavior sanitizer (UBSAN), loading the
>> module *nct6775* on the ASRock E350M1 shows the error below.
>>
>> ```
>> [   28.322775] UBSAN: Undefined behaviour in drivers/hwmon/nct6775.c:4179:27
>> [   28.322833] shift exponent 32 is too large for 32-bit type 'long unsigned int'
>> ```
>>
>> I believe this was introduced by commit cc66b3038254 (hwmon: (nct6775)
>> Rework temperature source and label handling), but the same issue was
>> already present before.
> 
> I don't think so. The code used to be
> 	for (i = 0; i < data->temp_label_num - 1; i++) {
> Notice the "- 1". So it should be
> 	for (i = 0; i < 31; i++) {
> 
> In practice it doesn't matter because "data->temp_mask & BIT(31 + 1)"
> will always be false, causing the last loop iteration to abort, but
> it is nevertheless wrong.
> 
> Thanks a lot for the report. I'll prepare a patch.

Thank you for the instant response. I tested your proposed change, and, 
as expected, the error is gone.


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-13  6:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12 21:50 nct6775: UBSAN: shift exponent 32 is too large for 32-bit type 'long unsigned int' Paul Menzel
2018-06-12 22:12 ` Guenter Roeck
2018-06-13  6:57   ` Paul Menzel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).