All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] USB: gadget: u_f: Unbreak offset calculation in VLAs
@ 2020-08-26 16:24 Andy Shevchenko
  2020-08-26 16:28 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2020-08-26 16:24 UTC (permalink / raw)
  To: Felipe Balbi, linux-usb, Greg Kroah-Hartman, Brooke Basile,
	Kees Cook
  Cc: Andy Shevchenko, Marek Szyprowski

Inadvertently the commit b1cd1b65afba ("USB: gadget: u_f: add overflow checks
to VLA macros") makes VLA macros to always return 0 due to different scope of
two variables of the same name. Obviously we need to have only one.

Fixes: b1cd1b65afba ("USB: gadget: u_f: add overflow checks to VLA macros")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/gadget/u_f.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
index df4e1dcb357d..0b5c5f0dd073 100644
--- a/drivers/usb/gadget/u_f.h
+++ b/drivers/usb/gadget/u_f.h
@@ -25,8 +25,8 @@
 		size_t offset = 0;					       \
 		if (groupname##__next != SIZE_MAX) {			       \
 			size_t align_mask = __alignof__(type) - 1;	       \
-			size_t offset = (groupname##__next + align_mask)       \
-					 & ~align_mask;			       \
+			offset = (groupname##__next + align_mask) &	       \
+				  ~align_mask;				       \
 			size_t size = array_size(n, sizeof(type));	       \
 			if (check_add_overflow(offset, size,		       \
 					       &groupname##__next)) {          \
@@ -43,8 +43,8 @@
 		size_t offset = 0;						\
 		if (groupname##__next != SIZE_MAX) {				\
 			size_t align_mask = __alignof__(type) - 1;		\
-			size_t offset = (groupname##__next + align_mask)	\
-					 & ~align_mask;				\
+			offset = (groupname##__next + align_mask) &		\
+				  ~align_mask;					\
 			if (check_add_overflow(offset, groupname##_##name##__sz,\
 							&groupname##__next)) {	\
 				groupname##__next = SIZE_MAX;			\
-- 
2.28.0


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

* Re: [PATCH v1] USB: gadget: u_f: Unbreak offset calculation in VLAs
  2020-08-26 16:24 [PATCH v1] USB: gadget: u_f: Unbreak offset calculation in VLAs Andy Shevchenko
@ 2020-08-26 16:28 ` Greg Kroah-Hartman
  2020-08-26 16:31   ` Marek Szyprowski
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2020-08-26 16:28 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Felipe Balbi, linux-usb, Brooke Basile, Kees Cook,
	Marek Szyprowski

On Wed, Aug 26, 2020 at 07:24:13PM +0300, Andy Shevchenko wrote:
> Inadvertently the commit b1cd1b65afba ("USB: gadget: u_f: add overflow checks
> to VLA macros") makes VLA macros to always return 0 due to different scope of
> two variables of the same name. Obviously we need to have only one.
> 
> Fixes: b1cd1b65afba ("USB: gadget: u_f: add overflow checks to VLA macros")
> Cc: stable <stable@kernel.org>
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/usb/gadget/u_f.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
> index df4e1dcb357d..0b5c5f0dd073 100644
> --- a/drivers/usb/gadget/u_f.h
> +++ b/drivers/usb/gadget/u_f.h
> @@ -25,8 +25,8 @@
>  		size_t offset = 0;					       \
>  		if (groupname##__next != SIZE_MAX) {			       \
>  			size_t align_mask = __alignof__(type) - 1;	       \
> -			size_t offset = (groupname##__next + align_mask)       \
> -					 & ~align_mask;			       \
> +			offset = (groupname##__next + align_mask) &	       \
> +				  ~align_mask;				       \
>  			size_t size = array_size(n, sizeof(type));	       \
>  			if (check_add_overflow(offset, size,		       \
>  					       &groupname##__next)) {          \
> @@ -43,8 +43,8 @@
>  		size_t offset = 0;						\
>  		if (groupname##__next != SIZE_MAX) {				\
>  			size_t align_mask = __alignof__(type) - 1;		\
> -			size_t offset = (groupname##__next + align_mask)	\
> -					 & ~align_mask;				\
> +			offset = (groupname##__next + align_mask) &		\
> +				  ~align_mask;					\
>  			if (check_add_overflow(offset, groupname##_##name##__sz,\
>  							&groupname##__next)) {	\
>  				groupname##__next = SIZE_MAX;			\

This patch, while maybe fixing the issue, has a bunch of build warnings
so I can't take it as-is:

$ make drivers/usb/gadget/
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh
  DESCEND  objtool
  CC [M]  drivers/usb/gadget/configfs.o
In file included from drivers/usb/gadget/configfs.c:10:
drivers/usb/gadget/configfs.c: In function ‘ext_prop_make’:
drivers/usb/gadget/u_f.h:30:4: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   30 |    size_t size = array_size(n, sizeof(type));        \
      |    ^~~~~~
drivers/usb/gadget/configfs.c:1066:2: note: in expansion of macro ‘vla_item’
 1066 |  vla_item(data_chunk, struct usb_os_desc_ext_prop, ext_prop, 1);
      |  ^~~~~~~~
drivers/usb/gadget/u_f.h:30:4: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   30 |    size_t size = array_size(n, sizeof(type));        \
      |    ^~~~~~
drivers/usb/gadget/configfs.c:1067:2: note: in expansion of macro ‘vla_item’
 1067 |  vla_item(data_chunk, struct config_item_type, ext_prop_type, 1);
      |  ^~~~~~~~
drivers/usb/gadget/configfs.c: In function ‘usb_os_desc_prepare_interf_dir’:
drivers/usb/gadget/u_f.h:30:4: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   30 |    size_t size = array_size(n, sizeof(type));        \
      |    ^~~~~~
drivers/usb/gadget/configfs.c:1194:2: note: in expansion of macro ‘vla_item’
 1194 |  vla_item(data_chunk, struct config_group, os_desc_group, 1);
      |  ^~~~~~~~
drivers/usb/gadget/u_f.h:30:4: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   30 |    size_t size = array_size(n, sizeof(type));        \
      |    ^~~~~~
drivers/usb/gadget/configfs.c:1195:2: note: in expansion of macro ‘vla_item’
 1195 |  vla_item(data_chunk, struct config_item_type, os_desc_type, 1);
      |  ^~~~~~~~
drivers/usb/gadget/u_f.h:30:4: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   30 |    size_t size = array_size(n, sizeof(type));        \
      |    ^~~~~~
drivers/usb/gadget/configfs.c:1196:2: note: in expansion of macro ‘vla_item’
 1196 |  vla_item(data_chunk, struct config_item_type, interface_type, 1);
      |  ^~~~~~~~

Care to try it again?

thanks,

greg k-h

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

* Re: [PATCH v1] USB: gadget: u_f: Unbreak offset calculation in VLAs
  2020-08-26 16:28 ` Greg Kroah-Hartman
@ 2020-08-26 16:31   ` Marek Szyprowski
  2020-08-26 19:22     ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Szyprowski @ 2020-08-26 16:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Andy Shevchenko
  Cc: Felipe Balbi, linux-usb, Brooke Basile, Kees Cook


On 26.08.2020 18:28, Greg Kroah-Hartman wrote:
> On Wed, Aug 26, 2020 at 07:24:13PM +0300, Andy Shevchenko wrote:
>> Inadvertently the commit b1cd1b65afba ("USB: gadget: u_f: add overflow checks
>> to VLA macros") makes VLA macros to always return 0 due to different scope of
>> two variables of the same name. Obviously we need to have only one.
>>
>> Fixes: b1cd1b65afba ("USB: gadget: u_f: add overflow checks to VLA macros")
>> Cc: stable <stable@kernel.org>
>> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
>> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> ---
>>   drivers/usb/gadget/u_f.h | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
>> index df4e1dcb357d..0b5c5f0dd073 100644
>> --- a/drivers/usb/gadget/u_f.h
>> +++ b/drivers/usb/gadget/u_f.h
>> @@ -25,8 +25,8 @@
>>   		size_t offset = 0;					       \
>>   		if (groupname##__next != SIZE_MAX) {			       \
>>   			size_t align_mask = __alignof__(type) - 1;	       \
>> -			size_t offset = (groupname##__next + align_mask)       \
>> -					 & ~align_mask;			       \
>> +			offset = (groupname##__next + align_mask) &	       \
>> +				  ~align_mask;				       \
>>   			size_t size = array_size(n, sizeof(type));	       \
>>   			if (check_add_overflow(offset, size,		       \
>>   					       &groupname##__next)) {          \
>> @@ -43,8 +43,8 @@
>>   		size_t offset = 0;						\
>>   		if (groupname##__next != SIZE_MAX) {				\
>>   			size_t align_mask = __alignof__(type) - 1;		\
>> -			size_t offset = (groupname##__next + align_mask)	\
>> -					 & ~align_mask;				\
>> +			offset = (groupname##__next + align_mask) &		\
>> +				  ~align_mask;					\
>>   			if (check_add_overflow(offset, groupname##_##name##__sz,\
>>   							&groupname##__next)) {	\
>>   				groupname##__next = SIZE_MAX;			\
> This patch, while maybe fixing the issue, has a bunch of build warnings
> so I can't take it as-is:

That's why I said that I've moved offset assignment in the first part of 
the patch after size_t size = array_size(n, sizeof(type));

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


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

* Re: [PATCH v1] USB: gadget: u_f: Unbreak offset calculation in VLAs
  2020-08-26 16:31   ` Marek Szyprowski
@ 2020-08-26 19:22     ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2020-08-26 19:22 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: Greg Kroah-Hartman, Felipe Balbi, linux-usb, Brooke Basile,
	Kees Cook

On Wed, Aug 26, 2020 at 06:31:01PM +0200, Marek Szyprowski wrote:
> On 26.08.2020 18:28, Greg Kroah-Hartman wrote:
> > On Wed, Aug 26, 2020 at 07:24:13PM +0300, Andy Shevchenko wrote:

> That's why I said that I've moved offset assignment in the first part of 
> the patch after size_t size = array_size(n, sizeof(type));

v2 has been sent.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2020-08-26 19:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-26 16:24 [PATCH v1] USB: gadget: u_f: Unbreak offset calculation in VLAs Andy Shevchenko
2020-08-26 16:28 ` Greg Kroah-Hartman
2020-08-26 16:31   ` Marek Szyprowski
2020-08-26 19:22     ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.