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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 6 Jun 2019 08:33:20 +0200
From:   Hans Verkuil <hverkuil-cisco@...all.nl>
To:     Shuah Khan <skhan@...uxfoundation.org>, mchehab@...nel.org,
        sakari.ailus@...ux.intel.com,
        niklas.soderlund+renesas@...natech.se, ezequiel@...labora.com,
        paul.kocialkowski@...tlin.com
Cc:     Randy Dunlap <rdunlap@...radead.org>, linux-media@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] media: v4l2-core: Shifting signed 32-bit value by 31
 bits error

On 6/6/19 5:22 AM, Randy Dunlap wrote:
> On 6/5/19 2:53 PM, Shuah Khan wrote:
>> Fix the following cppcheck error:
>>
>> Checking drivers/media/v4l2-core/v4l2-ioctl.c ...
>> [drivers/media/v4l2-core/v4l2-ioctl.c:1370]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour
>>
>> Signed-off-by: Shuah Khan <skhan@...uxfoundation.org>
>> ---
>>  drivers/media/v4l2-core/v4l2-ioctl.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
>> index 6859bdac86fe..333e387bafeb 100644
>> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
>> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
>> @@ -1364,7 +1364,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>>  					(char)((fmt->pixelformat >> 8) & 0x7f),
>>  					(char)((fmt->pixelformat >> 16) & 0x7f),
>>  					(char)((fmt->pixelformat >> 24) & 0x7f),
>> -					(fmt->pixelformat & (1 << 31)) ? "-BE" : "");
>> +					(fmt->pixelformat & BIT(31)) ? "-BE" : "");
>>  			break;
>>  		}
>>  	}
>>
> 
> If this builds, I guess #define BIT(x) got pulled in indirectly
> since bits.h nor bitops.h is currently #included in that source file.
> 
> Documentation/process/submit-checklist.rst rule #1 says:
> 1) If you use a facility then #include the file that defines/declares
>    that facility.  Don't depend on other header files pulling in ones
>    that you use.
> 
> Please add #include <linux/bits or bitops.h>
> 

I'm not sure about this patch. '1 << 31' is used all over in the kernel,
including in public headers (e.g. media.h, videodev2.h).

It seems arbitrary to change it only here, but not anywhere else.

In this particular example for the fourcc handling I would prefer to just
use '1U << 31', both in v4l2-ioctl.c and videodev2.h.

A separate patch doing the same for MEDIA_ENT_ID_FLAG_NEXT in media.h would
probably be a good idea either: that way the public API at least will do
the right thing.

Regards,

	Hans

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ