linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: ch9: Replace 1-element array with flexible array
@ 2023-06-13 21:04 Kees Cook
  2023-06-13 22:52 ` Gustavo A. R. Silva
  0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2023-06-13 21:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Kees Cook, kernel test robot, kernel test robot,
	Gustavo A. R. Silva, Dan Williams, Jó Ágila Bitsch,
	linux-kernel, linux-hardening

With "-fstrict-flex-arrays=3" enabled, UBSAN_BOUNDS no longer pretends
1-element arrays are unbounded. Walking wData will trigger a warning,
so make it a proper flexible array. Add a union to keep the struct size
identical for userspace in case anything was depending on the old size.

Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202306102333.8f5a7443-oliver.sang@intel.com
Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: kernel test robot <lkp@intel.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: "Jó Ágila Bitsch" <jgilab@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/uapi/linux/usb/ch9.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h
index b17e3a21b15f..82ec6af71a1d 100644
--- a/include/uapi/linux/usb/ch9.h
+++ b/include/uapi/linux/usb/ch9.h
@@ -376,7 +376,10 @@ struct usb_string_descriptor {
 	__u8  bLength;
 	__u8  bDescriptorType;
 
-	__le16 wData[1];		/* UTF-16LE encoded */
+	union {
+		__le16 legacy_padding;
+		__DECLARE_FLEX_ARRAY(__le16, wData);	/* UTF-16LE encoded */
+	};
 } __attribute__ ((packed));
 
 /* note that "string" zero is special, it holds language codes that
-- 
2.34.1


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

* Re: [PATCH] usb: ch9: Replace 1-element array with flexible array
  2023-06-13 21:04 [PATCH] usb: ch9: Replace 1-element array with flexible array Kees Cook
@ 2023-06-13 22:52 ` Gustavo A. R. Silva
  2023-06-14  6:10   ` Greg Kroah-Hartman
  2023-06-14 17:47   ` Kees Cook
  0 siblings, 2 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-06-13 22:52 UTC (permalink / raw)
  To: Kees Cook
  Cc: Greg Kroah-Hartman, kernel test robot, kernel test robot,
	Dan Williams, Jó Ágila Bitsch, linux-kernel,
	linux-hardening

On Tue, Jun 13, 2023 at 02:04:04PM -0700, Kees Cook wrote:
> With "-fstrict-flex-arrays=3" enabled, UBSAN_BOUNDS no longer pretends
> 1-element arrays are unbounded. Walking wData will trigger a warning,
> so make it a proper flexible array. Add a union to keep the struct size
> identical for userspace in case anything was depending on the old size.
> 
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202306102333.8f5a7443-oliver.sang@intel.com
> Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")

I always have mixed feelings about a 'Fixes' tag applied to a commit
like this (one that enables a compiler option that avoids the introduction
of buggy code), when we are addressing the potentially buggy code that
the option is inteded to prevent. (thinkingface)

> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: kernel test robot <lkp@intel.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: "Jó Ágila Bitsch" <jgilab@gmail.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
--
Gustavo

> ---
>  include/uapi/linux/usb/ch9.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h
> index b17e3a21b15f..82ec6af71a1d 100644
> --- a/include/uapi/linux/usb/ch9.h
> +++ b/include/uapi/linux/usb/ch9.h
> @@ -376,7 +376,10 @@ struct usb_string_descriptor {
>  	__u8  bLength;
>  	__u8  bDescriptorType;
>  
> -	__le16 wData[1];		/* UTF-16LE encoded */
> +	union {
> +		__le16 legacy_padding;
> +		__DECLARE_FLEX_ARRAY(__le16, wData);	/* UTF-16LE encoded */
> +	};
>  } __attribute__ ((packed));
>  
>  /* note that "string" zero is special, it holds language codes that
> -- 
> 2.34.1
> 

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

* Re: [PATCH] usb: ch9: Replace 1-element array with flexible array
  2023-06-13 22:52 ` Gustavo A. R. Silva
@ 2023-06-14  6:10   ` Greg Kroah-Hartman
  2023-06-14 17:47   ` Kees Cook
  1 sibling, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-14  6:10 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Kees Cook, kernel test robot, kernel test robot, Dan Williams,
	Jó Ágila Bitsch, linux-kernel, linux-hardening

On Tue, Jun 13, 2023 at 04:52:08PM -0600, Gustavo A. R. Silva wrote:
> On Tue, Jun 13, 2023 at 02:04:04PM -0700, Kees Cook wrote:
> > With "-fstrict-flex-arrays=3" enabled, UBSAN_BOUNDS no longer pretends
> > 1-element arrays are unbounded. Walking wData will trigger a warning,
> > so make it a proper flexible array. Add a union to keep the struct size
> > identical for userspace in case anything was depending on the old size.
> > 
> > Reported-by: kernel test robot <oliver.sang@intel.com>
> > Closes: https://lore.kernel.org/oe-lkp/202306102333.8f5a7443-oliver.sang@intel.com
> > Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
> 
> I always have mixed feelings about a 'Fixes' tag applied to a commit
> like this (one that enables a compiler option that avoids the introduction
> of buggy code), when we are addressing the potentially buggy code that
> the option is inteded to prevent. (thinkingface)

Yeah, the original code here is not incorrect, it's that you added a new
build warning, so this is more like an "update" :)

> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: kernel test robot <lkp@intel.com>
> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> > Cc: Dan Williams <dan.j.williams@intel.com>
> > Cc: "Jó Ágila Bitsch" <jgilab@gmail.com>
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> 
> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Odd that checkpatch.pl doesn't cc: the usb lists for this file.  I'll go
update the MAINTAINERS file with this location...

thanks,

greg k-h

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

* Re: [PATCH] usb: ch9: Replace 1-element array with flexible array
  2023-06-13 22:52 ` Gustavo A. R. Silva
  2023-06-14  6:10   ` Greg Kroah-Hartman
@ 2023-06-14 17:47   ` Kees Cook
  1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2023-06-14 17:47 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Greg Kroah-Hartman, kernel test robot, kernel test robot,
	Dan Williams, Jó Ágila Bitsch, linux-kernel,
	linux-hardening

On Tue, Jun 13, 2023 at 04:52:08PM -0600, Gustavo A. R. Silva wrote:
> On Tue, Jun 13, 2023 at 02:04:04PM -0700, Kees Cook wrote:
> > With "-fstrict-flex-arrays=3" enabled, UBSAN_BOUNDS no longer pretends
> > 1-element arrays are unbounded. Walking wData will trigger a warning,
> > so make it a proper flexible array. Add a union to keep the struct size
> > identical for userspace in case anything was depending on the old size.
> > 
> > Reported-by: kernel test robot <oliver.sang@intel.com>
> > Closes: https://lore.kernel.org/oe-lkp/202306102333.8f5a7443-oliver.sang@intel.com
> > Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
> 
> I always have mixed feelings about a 'Fixes' tag applied to a commit
> like this (one that enables a compiler option that avoids the introduction
> of buggy code), when we are addressing the potentially buggy code that
> the option is inteded to prevent. (thinkingface)

Yeah, I've been on the fence about this too. Since it's fixing a
(modern) coding style issue, there's nothing wrong technically. i.e. I
can't say "Fixes: ...usb commit..." since this isn't a bug. But it's
fixing a warning introduced by the fstrict-flex-arrays=3, and tracking
those issues is useful. But, it's not really fixing _that_ commit, as
it's doing exactly what it should be doing. So, perhaps, in the future I
can just mention it more directly in the commit log without a Fixes tag.
For example, this should probably have been written as:

 Since commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3"),
 UBSAN_BOUNDS no longer pretends 1-element arrays are unbounded. Walking
 wData will trigger a warning, so make it a proper flexible array. Add a
 union to keep the struct size identical for userspace in case anything
 was depending on the old size.

 Reported-by: kernel test robot <oliver.sang@intel.com> Closes:
 https://lore.kernel.org/oe-lkp/202306102333.8f5a7443-oliver.sang@intel.com

-Kees

-- 
Kees Cook

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

end of thread, other threads:[~2023-06-14 17:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-13 21:04 [PATCH] usb: ch9: Replace 1-element array with flexible array Kees Cook
2023-06-13 22:52 ` Gustavo A. R. Silva
2023-06-14  6:10   ` Greg Kroah-Hartman
2023-06-14 17:47   ` Kees Cook

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