From: Kees Cook <kees@kernel.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH] usb: ehci-fsl: Fix use of private data to avoid -Wflex-array-member-not-at-end warning
Date: Mon, 7 Apr 2025 12:15:33 -0700 [thread overview]
Message-ID: <202504071215.DED5FA3535@keescook> (raw)
In-Reply-To: <8139e4cc-4e5c-40e2-9c4b-717ad3215868@rowland.harvard.edu>
On Thu, Mar 27, 2025 at 03:31:15PM -0400, Alan Stern wrote:
> In the course of fixing up the usages of flexible arrays, Gustavo
> submitted a patch updating the ehci-fsl driver. However, the patch
> was wrong because the driver was using the .priv member of the
> ehci_hcd structure incorrectly. The private data is not supposed to
> be a wrapper containing the ehci_hcd structure; it is supposed to be a
> sub-structure stored in the .priv member.
>
> Fix the problem by replacing the ehci_fsl structure with
> ehci_fsl_priv, containing only the private data, along with a suitable
> conversion macro for accessing it. This removes the problem of having
> data follow a flexible array member.
Thanks for figuring out the right solution! :)
>
> Reported-by: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> Link: https://lore.kernel.org/linux-usb/Z-R9BcnSzrRv5FX_@kspp/
Reviewed-by: Kees Cook <kees@kernel.org>
-Kees
>
> ---
>
> drivers/usb/host/ehci-fsl.c | 25 ++++++++-----------------
> 1 file changed, 8 insertions(+), 17 deletions(-)
>
> Index: usb-devel/drivers/usb/host/ehci-fsl.c
> ===================================================================
> --- usb-devel.orig/drivers/usb/host/ehci-fsl.c
> +++ usb-devel/drivers/usb/host/ehci-fsl.c
> @@ -410,15 +410,13 @@ static int ehci_fsl_setup(struct usb_hcd
> return retval;
> }
>
> -struct ehci_fsl {
> - struct ehci_hcd ehci;
> -
> -#ifdef CONFIG_PM
> +struct ehci_fsl_priv {
> /* Saved USB PHY settings, need to restore after deep sleep. */
> u32 usb_ctrl;
> -#endif
> };
>
> +#define hcd_to_ehci_fsl_priv(h) ((struct ehci_fsl_priv *) hcd_to_ehci(h)->priv)
> +
> #ifdef CONFIG_PM
>
> #ifdef CONFIG_PPC_MPC512x
> @@ -566,17 +564,10 @@ static inline int ehci_fsl_mpc512x_drv_r
> }
> #endif /* CONFIG_PPC_MPC512x */
>
> -static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
> -{
> - struct ehci_hcd *ehci = hcd_to_ehci(hcd);
> -
> - return container_of(ehci, struct ehci_fsl, ehci);
> -}
> -
> static int ehci_fsl_drv_suspend(struct device *dev)
> {
> struct usb_hcd *hcd = dev_get_drvdata(dev);
> - struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
> + struct ehci_fsl_priv *priv = hcd_to_ehci_fsl_priv(hcd);
> void __iomem *non_ehci = hcd->regs;
>
> if (of_device_is_compatible(dev->parent->of_node,
> @@ -589,14 +580,14 @@ static int ehci_fsl_drv_suspend(struct d
> if (!fsl_deep_sleep())
> return 0;
>
> - ehci_fsl->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
> + priv->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
> return 0;
> }
>
> static int ehci_fsl_drv_resume(struct device *dev)
> {
> struct usb_hcd *hcd = dev_get_drvdata(dev);
> - struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
> + struct ehci_fsl_priv *priv = hcd_to_ehci_fsl_priv(hcd);
> struct ehci_hcd *ehci = hcd_to_ehci(hcd);
> void __iomem *non_ehci = hcd->regs;
>
> @@ -612,7 +603,7 @@ static int ehci_fsl_drv_resume(struct de
> usb_root_hub_lost_power(hcd->self.root_hub);
>
> /* Restore USB PHY settings and enable the controller. */
> - iowrite32be(ehci_fsl->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL);
> + iowrite32be(priv->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL);
>
> ehci_reset(ehci);
> ehci_fsl_reinit(ehci);
> @@ -671,7 +662,7 @@ static int ehci_start_port_reset(struct
> #endif /* CONFIG_USB_OTG */
>
> static const struct ehci_driver_overrides ehci_fsl_overrides __initconst = {
> - .extra_priv_size = sizeof(struct ehci_fsl),
> + .extra_priv_size = sizeof(struct ehci_fsl_priv),
> .reset = ehci_fsl_setup,
> };
>
--
Kees Cook
prev parent reply other threads:[~2025-04-07 19:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 22:17 [PATCH][next] usb: ehci-fsl: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-03-27 2:09 ` Alan Stern
2025-03-27 19:31 ` [PATCH] usb: ehci-fsl: Fix use of private data to avoid " Alan Stern
2025-04-07 19:15 ` Kees Cook [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202504071215.DED5FA3535@keescook \
--to=kees@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=gustavoars@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox