All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH stable-5.4 0/3] USB: stable backports to 5.4
@ 2022-09-06 13:34 Johan Hovold
  2022-09-06 13:34 ` [PATCH stable-5.4 1/3] usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup Johan Hovold
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Johan Hovold @ 2022-09-06 13:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: stable, linux-kernel, Johan Hovold

Here are backports of the three patches that didn't apply to 5.4.

Johan


Johan Hovold (3):
  usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup
  USB: serial: ch341: fix lost character on LCR updates
  USB: serial: ch341: fix disabled rx timer on older devices

 drivers/usb/dwc3/dwc3-qcom.c | 14 +++++++++++++-
 drivers/usb/dwc3/host.c      |  1 +
 drivers/usb/serial/ch341.c   | 15 +++++++++++++--
 3 files changed, 27 insertions(+), 3 deletions(-)

-- 
2.35.1


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

* [PATCH stable-5.4 1/3] usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup
  2022-09-06 13:34 [PATCH stable-5.4 0/3] USB: stable backports to 5.4 Johan Hovold
@ 2022-09-06 13:34 ` Johan Hovold
  2022-09-06 13:34 ` [PATCH stable-5.4 2/3] USB: serial: ch341: fix lost character on LCR updates Johan Hovold
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2022-09-06 13:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: stable, linux-kernel, Johan Hovold, Matthias Kaehlcke,
	Manivannan Sadhasivam, Johan Hovold

From: Johan Hovold <johan+linaro@kernel.org>

commit  a872ab303d5ddd4c965f9cd868677781a33ce35a upstream.

The Qualcomm dwc3 runtime-PM implementation checks the xhci
platform-device pointer in the wakeup-interrupt handler to determine
whether the controller is in host mode and if so triggers a resume.

After a role switch in OTG mode the xhci platform-device would have been
freed and the next wakeup from runtime suspend would access the freed
memory.

Note that role switching is executed from a freezable workqueue, which
guarantees that the pointer is stable during suspend.

Also note that runtime PM has been broken since commit 2664deb09306
("usb: dwc3: qcom: Honor wakeup enabled/disabled state"), which
incidentally also prevents this issue from being triggered.

Fixes: a4333c3a6ba9 ("usb: dwc3: Add Qualcomm DWC3 glue driver")
Cc: stable@vger.kernel.org      # 4.18
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Link: https://lore.kernel.org/r/20220804151001.23612-5-johan+linaro@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[ johan: adjust context for 5.4 ]
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/dwc3/dwc3-qcom.c | 14 +++++++++++++-
 drivers/usb/dwc3/host.c      |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 7874b97e3322..aed35276e0e0 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -190,6 +190,14 @@ static int dwc3_qcom_register_extcon(struct dwc3_qcom *qcom)
 	return 0;
 }
 
+/* Only usable in contexts where the role can not change. */
+static bool dwc3_qcom_is_host(struct dwc3_qcom *qcom)
+{
+	struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
+
+	return dwc->xhci;
+}
+
 static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
 {
 	if (qcom->hs_phy_irq) {
@@ -297,7 +305,11 @@ static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data)
 	if (qcom->pm_suspended)
 		return IRQ_HANDLED;
 
-	if (dwc->xhci)
+	/*
+	 * This is safe as role switching is done from a freezable workqueue
+	 * and the wakeup interrupts are disabled as part of resume.
+	 */
+	if (dwc3_qcom_is_host(qcom))
 		pm_runtime_resume(&dwc->xhci->dev);
 
 	return IRQ_HANDLED;
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index fa252870c926..38bcb079ffc7 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -128,4 +128,5 @@ int dwc3_host_init(struct dwc3 *dwc)
 void dwc3_host_exit(struct dwc3 *dwc)
 {
 	platform_device_unregister(dwc->xhci);
+	dwc->xhci = NULL;
 }
-- 
2.35.1


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

* [PATCH stable-5.4 2/3] USB: serial: ch341: fix lost character on LCR updates
  2022-09-06 13:34 [PATCH stable-5.4 0/3] USB: stable backports to 5.4 Johan Hovold
  2022-09-06 13:34 ` [PATCH stable-5.4 1/3] usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup Johan Hovold
@ 2022-09-06 13:34 ` Johan Hovold
  2022-09-06 13:34 ` [PATCH stable-5.4 3/3] USB: serial: ch341: fix disabled rx timer on older devices Johan Hovold
  2022-09-06 13:41 ` [PATCH stable-5.4 0/3] USB: stable backports to 5.4 Greg Kroah-Hartman
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2022-09-06 13:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: stable, linux-kernel, Johan Hovold, Jonathan Woithe

commit 8e83622ae7ca481c76c8fd9579877f6abae64ca2 upstream.

Disable LCR updates for pre-0x30 devices which use a different (unknown)
protocol for line control and where the current register write causes
the next received character to be lost.

Note that updating LCR using the INIT command has no effect on these
devices either.

Reported-by: Jonathan Woithe <jwoithe@just42.net>
Tested-by: Jonathan Woithe <jwoithe@just42.net>
Link: https://lore.kernel.org/r/Ys1iPTfiZRWj2gXs@marvin.atrad.com.au
Fixes: 4e46c410e050 ("USB: serial: ch341: reinitialize chip on reconfiguration")
Fixes: 55fa15b5987d ("USB: serial: ch341: fix baud rate and line-control handling")
Cc: stable@vger.kernel.org      # 4.10
Signed-off-by: Johan Hovold <johan@kernel.org>
[ johan: adjust context to 5.4 ]
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/ch341.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index f06a09e59d8b..be44d6c28df6 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -96,7 +96,9 @@ struct ch341_private {
 	u8 mcr;
 	u8 msr;
 	u8 lcr;
+
 	unsigned long quirks;
+	u8 version;
 };
 
 static void ch341_set_termios(struct tty_struct *tty,
@@ -182,6 +184,9 @@ static int ch341_set_baudrate_lcr(struct usb_device *dev,
 	if (r)
 		return r;
 
+	if (priv->version < 0x30)
+		return 0;
+
 	r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x2518, lcr);
 	if (r)
 		return r;
@@ -233,7 +238,9 @@ static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
 	r = ch341_control_in(dev, CH341_REQ_READ_VERSION, 0, 0, buffer, size);
 	if (r < 0)
 		goto out;
-	dev_dbg(&dev->dev, "Chip version: 0x%02x\n", buffer[0]);
+
+	priv->version = buffer[0];
+	dev_dbg(&dev->dev, "Chip version: 0x%02x\n", priv->version);
 
 	r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT, 0, 0);
 	if (r < 0)
-- 
2.35.1


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

* [PATCH stable-5.4 3/3] USB: serial: ch341: fix disabled rx timer on older devices
  2022-09-06 13:34 [PATCH stable-5.4 0/3] USB: stable backports to 5.4 Johan Hovold
  2022-09-06 13:34 ` [PATCH stable-5.4 1/3] usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup Johan Hovold
  2022-09-06 13:34 ` [PATCH stable-5.4 2/3] USB: serial: ch341: fix lost character on LCR updates Johan Hovold
@ 2022-09-06 13:34 ` Johan Hovold
  2022-09-06 13:41 ` [PATCH stable-5.4 0/3] USB: stable backports to 5.4 Greg Kroah-Hartman
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2022-09-06 13:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: stable, linux-kernel, Johan Hovold, Jonathan Woithe

commit 41ca302a697b64a3dab4676e01d0d11bb184737d upstream.

At least one older CH341 appears to have the RX timer enable bit
inverted so that setting it disables the RX timer and prevents the FIFO
from emptying until it is full.

Only set the RX timer enable bit for devices with version newer than
0x27 (even though this probably affects all pre-0x30 devices).

Reported-by: Jonathan Woithe <jwoithe@just42.net>
Tested-by: Jonathan Woithe <jwoithe@just42.net>
Link: https://lore.kernel.org/r/Ys1iPTfiZRWj2gXs@marvin.atrad.com.au
Fixes: 4e46c410e050 ("USB: serial: ch341: reinitialize chip on reconfiguration")
Cc: stable@vger.kernel.org      # 4.10
Signed-off-by: Johan Hovold <johan@kernel.org>
[ johan: backport to 5.4 ]
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/ch341.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index be44d6c28df6..f37bde88eb5d 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -177,8 +177,12 @@ static int ch341_set_baudrate_lcr(struct usb_device *dev,
 	/*
 	 * CH341A buffers data until a full endpoint-size packet (32 bytes)
 	 * has been received unless bit 7 is set.
+	 *
+	 * At least one device with version 0x27 appears to have this bit
+	 * inverted.
 	 */
-	a |= BIT(7);
+	if (priv->version > 0x27)
+		a |= BIT(7);
 
 	r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x1312, a);
 	if (r)
-- 
2.35.1


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

* Re: [PATCH stable-5.4 0/3] USB: stable backports to 5.4
  2022-09-06 13:34 [PATCH stable-5.4 0/3] USB: stable backports to 5.4 Johan Hovold
                   ` (2 preceding siblings ...)
  2022-09-06 13:34 ` [PATCH stable-5.4 3/3] USB: serial: ch341: fix disabled rx timer on older devices Johan Hovold
@ 2022-09-06 13:41 ` Greg Kroah-Hartman
  3 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2022-09-06 13:41 UTC (permalink / raw)
  To: Johan Hovold; +Cc: stable, linux-kernel

On Tue, Sep 06, 2022 at 03:34:32PM +0200, Johan Hovold wrote:
> Here are backports of the three patches that didn't apply to 5.4.
> 
> Johan
> 
> 
> Johan Hovold (3):
>   usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup
>   USB: serial: ch341: fix lost character on LCR updates
>   USB: serial: ch341: fix disabled rx timer on older devices
> 
>  drivers/usb/dwc3/dwc3-qcom.c | 14 +++++++++++++-
>  drivers/usb/dwc3/host.c      |  1 +
>  drivers/usb/serial/ch341.c   | 15 +++++++++++++--
>  3 files changed, 27 insertions(+), 3 deletions(-)
> 
> -- 
> 2.35.1
> 

All now queued up, thanks!

greg k-h

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

end of thread, other threads:[~2022-09-06 14:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-06 13:34 [PATCH stable-5.4 0/3] USB: stable backports to 5.4 Johan Hovold
2022-09-06 13:34 ` [PATCH stable-5.4 1/3] usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup Johan Hovold
2022-09-06 13:34 ` [PATCH stable-5.4 2/3] USB: serial: ch341: fix lost character on LCR updates Johan Hovold
2022-09-06 13:34 ` [PATCH stable-5.4 3/3] USB: serial: ch341: fix disabled rx timer on older devices Johan Hovold
2022-09-06 13:41 ` [PATCH stable-5.4 0/3] USB: stable backports to 5.4 Greg Kroah-Hartman

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.