LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] staging: vc04_services: shut up out-of-range warning
@ 2021-09-27 11:36 Arnd Bergmann
  2021-09-27 12:26 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2021-09-27 11:36 UTC (permalink / raw)
  To: Nicolas Saenz Julienne, Greg Kroah-Hartman, Dan Carpenter
  Cc: Arnd Bergmann, Stefan Wahren, Ojaswin Mujoo, Phil Elwell,
	Amarjargal Gundjalam, bcm-kernel-feedback-list, linux-rpi-kernel,
	linux-arm-kernel, linux-staging, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

The comparison against SIZE_MAX produces a harmless warning on 64-bit
architectures:

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c:185:16: error: result of comparison of constant 419244183493398898 with expression of type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
        if (num_pages > (SIZE_MAX - sizeof(struct pagelist) -
            ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Shut up that warning by adding a cast to a longer type.

Fixes: ca641bae6da9 ("staging: vc04_services: prevent integer overflow in create_pagelist()")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index b25369a13452..967f10b9582a 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -182,7 +182,7 @@ create_pagelist(char *buf, char __user *ubuf,
 		offset = (uintptr_t)ubuf & (PAGE_SIZE - 1);
 	num_pages = DIV_ROUND_UP(count + offset, PAGE_SIZE);
 
-	if (num_pages > (SIZE_MAX - sizeof(struct pagelist) -
+	if ((size_t)num_pages > (SIZE_MAX - sizeof(struct pagelist) -
 			 sizeof(struct vchiq_pagelist_info)) /
 			(sizeof(u32) + sizeof(pages[0]) +
 			 sizeof(struct scatterlist)))
-- 
2.29.2


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

* Re: [PATCH] staging: vc04_services: shut up out-of-range warning
  2021-09-27 11:36 [PATCH] staging: vc04_services: shut up out-of-range warning Arnd Bergmann
@ 2021-09-27 12:26 ` Dan Carpenter
  2021-09-27 13:21   ` Phil Elwell
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-09-27 12:26 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Nicolas Saenz Julienne, Greg Kroah-Hartman, Arnd Bergmann,
	Stefan Wahren, Ojaswin Mujoo, Phil Elwell, Amarjargal Gundjalam,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	linux-staging, linux-kernel

On Mon, Sep 27, 2021 at 01:36:56PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> The comparison against SIZE_MAX produces a harmless warning on 64-bit
> architectures:
> 
> drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c:185:16: error: result of comparison of constant 419244183493398898 with expression of type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
>         if (num_pages > (SIZE_MAX - sizeof(struct pagelist) -
>             ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Shut up that warning by adding a cast to a longer type.
> 
> Fixes: ca641bae6da9 ("staging: vc04_services: prevent integer overflow in create_pagelist()")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index b25369a13452..967f10b9582a 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -182,7 +182,7 @@ create_pagelist(char *buf, char __user *ubuf,
>  		offset = (uintptr_t)ubuf & (PAGE_SIZE - 1);
>  	num_pages = DIV_ROUND_UP(count + offset, PAGE_SIZE);
>  
> -	if (num_pages > (SIZE_MAX - sizeof(struct pagelist) -
> +	if ((size_t)num_pages > (SIZE_MAX - sizeof(struct pagelist) -
>  			 sizeof(struct vchiq_pagelist_info)) /
>  			(sizeof(u32) + sizeof(pages[0]) +
>  			 sizeof(struct scatterlist)))

The temptation would be to declare "num_pages" as size_t instead of
adding this cost.  But then something will complain about the
"pagelistinfo->num_pages = num_pages;" assignment because
"pagelistinfo->num_pages" is a u32.

The next temptation is to change the SIZE_MAX to UINT_MAX.  I didn't
do that originally because I can't test this and I was trying not to
break things...  We probably still don't want to break things, but maybe
there is someone who is more familiar with this who knows if UINT_MAX is
okay?

regards,
dan carpenter


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

* Re: [PATCH] staging: vc04_services: shut up out-of-range warning
  2021-09-27 12:26 ` Dan Carpenter
@ 2021-09-27 13:21   ` Phil Elwell
  2021-09-27 20:37     ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Elwell @ 2021-09-27 13:21 UTC (permalink / raw)
  To: Dan Carpenter, Arnd Bergmann
  Cc: Nicolas Saenz Julienne, Greg Kroah-Hartman, Arnd Bergmann,
	Stefan Wahren, Ojaswin Mujoo, Amarjargal Gundjalam,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	linux-staging, linux-kernel

Hi Dan,

On 27/09/2021 13:26, Dan Carpenter wrote:
> On Mon, Sep 27, 2021 at 01:36:56PM +0200, Arnd Bergmann wrote:
>> From: Arnd Bergmann <arnd@arndb.de>
>>
>> The comparison against SIZE_MAX produces a harmless warning on 64-bit
>> architectures:
>>
>> drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c:185:16: error: result of comparison of constant 419244183493398898 with expression of type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
>>          if (num_pages > (SIZE_MAX - sizeof(struct pagelist) -
>>              ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> Shut up that warning by adding a cast to a longer type.
>>
>> Fixes: ca641bae6da9 ("staging: vc04_services: prevent integer overflow in create_pagelist()")
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> ---
>>   drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> index b25369a13452..967f10b9582a 100644
>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> @@ -182,7 +182,7 @@ create_pagelist(char *buf, char __user *ubuf,
>>   		offset = (uintptr_t)ubuf & (PAGE_SIZE - 1);
>>   	num_pages = DIV_ROUND_UP(count + offset, PAGE_SIZE);
>>   
>> -	if (num_pages > (SIZE_MAX - sizeof(struct pagelist) -
>> +	if ((size_t)num_pages > (SIZE_MAX - sizeof(struct pagelist) -
>>   			 sizeof(struct vchiq_pagelist_info)) /
>>   			(sizeof(u32) + sizeof(pages[0]) +
>>   			 sizeof(struct scatterlist)))
> 
> The temptation would be to declare "num_pages" as size_t instead of
> adding this cost.  But then something will complain about the
> "pagelistinfo->num_pages = num_pages;" assignment because
> "pagelistinfo->num_pages" is a u32.
> 
> The next temptation is to change the SIZE_MAX to UINT_MAX.  I didn't
> do that originally because I can't test this and I was trying not to
> break things...  We probably still don't want to break things, but maybe
> there is someone who is more familiar with this who knows if UINT_MAX is
> okay?

The VPU can't address more than 1GB directly, so UINT_MAX is more than sufficient.

Phil

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

* Re: [PATCH] staging: vc04_services: shut up out-of-range warning
  2021-09-27 13:21   ` Phil Elwell
@ 2021-09-27 20:37     ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2021-09-27 20:37 UTC (permalink / raw)
  To: Phil Elwell
  Cc: Dan Carpenter, Nicolas Saenz Julienne, Greg Kroah-Hartman,
	Arnd Bergmann, Stefan Wahren, Ojaswin Mujoo,
	Amarjargal Gundjalam, bcm-kernel-feedback-list,
	moderated list:BROADCOM BCM2835 ARM ARCHITECTURE, Linux ARM,
	linux-staging, Linux Kernel Mailing List

On Mon, Sep 27, 2021 at 3:22 PM Phil Elwell <phil@raspberrypi.com> wrote:
> On 27/09/2021 13:26, Dan Carpenter wrote:
> > On Mon, Sep 27, 2021 at 01:36:56PM +0200, Arnd Bergmann wrote:
> >> From: Arnd Bergmann <arnd@arndb.de>
> >>
> >> -    if (num_pages > (SIZE_MAX - sizeof(struct pagelist) -
> >> +    if ((size_t)num_pages > (SIZE_MAX - sizeof(struct pagelist) -
> >>                       sizeof(struct vchiq_pagelist_info)) /
> >>                      (sizeof(u32) + sizeof(pages[0]) +
> >>                       sizeof(struct scatterlist)))
> >
> > The temptation would be to declare "num_pages" as size_t instead of
> > adding this cost.  But then something will complain about the
> > "pagelistinfo->num_pages = num_pages;" assignment because
> > "pagelistinfo->num_pages" is a u32.
> >
> > The next temptation is to change the SIZE_MAX to UINT_MAX.  I didn't
> > do that originally because I can't test this and I was trying not to
> > break things...  We probably still don't want to break things, but maybe
> > there is someone who is more familiar with this who knows if UINT_MAX is
> > okay?
>
> The VPU can't address more than 1GB directly, so UINT_MAX is more than sufficient.

Is there a macro that already defines that 1GB size, or maybe an even smaller
value that makes sense as an upper bound?

         Arnd

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

end of thread, other threads:[~2021-09-27 20:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 11:36 [PATCH] staging: vc04_services: shut up out-of-range warning Arnd Bergmann
2021-09-27 12:26 ` Dan Carpenter
2021-09-27 13:21   ` Phil Elwell
2021-09-27 20:37     ` Arnd Bergmann

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).