public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Pavankumar Kondeti <quic_pkondeti@quicinc.com>,
	Udipto Goswami <quic_ugoswami@quicinc.com>
Subject: [PATCH 4.14 34/44] usb: dwc3: gadget: Prevent core from processing stale TRBs
Date: Mon, 14 Feb 2022 10:25:57 +0100	[thread overview]
Message-ID: <20220214092449.011455274@linuxfoundation.org> (raw)
In-Reply-To: <20220214092447.897544753@linuxfoundation.org>

From: Udipto Goswami <quic_ugoswami@quicinc.com>

commit 117b4e96c7f362eb6459543883fc07f77662472c upstream.

With CPU re-ordering on write instructions, there might
be a chance that the HWO is set before the TRB is updated
with the new mapped buffer address.
And in the case where core is processing a list of TRBs
it is possible that it fetched the TRBs when the HWO is set
but before the buffer address is updated.
Prevent this by adding a memory barrier before the HWO
is updated to ensure that the core always process the
updated TRBs.

Fixes: f6bafc6a1c9d ("usb: dwc3: convert TRBs into bitshifts")
Cc: stable <stable@vger.kernel.org>
Reviewed-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
Signed-off-by: Udipto Goswami <quic_ugoswami@quicinc.com>
Link: https://lore.kernel.org/r/1644207958-18287-1-git-send-email-quic_ugoswami@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/dwc3/gadget.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)

--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1004,6 +1004,19 @@ static void __dwc3_prepare_one_trb(struc
 	if (usb_endpoint_xfer_bulk(dep->endpoint.desc) && dep->stream_capable)
 		trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(stream_id);
 
+	/*
+	 * As per data book 4.2.3.2TRB Control Bit Rules section
+	 *
+	 * The controller autonomously checks the HWO field of a TRB to determine if the
+	 * entire TRB is valid. Therefore, software must ensure that the rest of the TRB
+	 * is valid before setting the HWO field to '1'. In most systems, this means that
+	 * software must update the fourth DWORD of a TRB last.
+	 *
+	 * However there is a possibility of CPU re-ordering here which can cause
+	 * controller to observe the HWO bit set prematurely.
+	 * Add a write memory barrier to prevent CPU re-ordering.
+	 */
+	wmb();
 	trb->ctrl |= DWC3_TRB_CTRL_HWO;
 
 	dwc3_ep_inc_enq(dep);



  parent reply	other threads:[~2022-02-14  9:33 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-14  9:25 [PATCH 4.14 00/44] 4.14.267-rc1 review Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 01/44] integrity: check the return value of audit_log_start() Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 02/44] ima: Remove ima_policy file before directory Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 03/44] ima: Allow template selection with ima_template[_fmt]= after ima_hash= Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 04/44] mmc: sdhci-of-esdhc: Check for error num after setting mask Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 05/44] net: phy: marvell: Fix MDI-x polarity setting in 88e1118-compatible PHYs Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 06/44] NFS: Fix initialisation of nfs_client cl_flags field Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 07/44] NFSD: Clamp WRITE offsets Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 08/44] NFSv4 only print the label when its queried Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 09/44] nfs: nfs4clinet: check the return value of kstrdup() Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 10/44] NFSv4.1: Fix uninitialised variable in devicenotify Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 11/44] NFSv4 remove zero number of fs_locations entries error check Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 12/44] NFSv4 expose nfs_parse_server_name function Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 13/44] scsi: target: iscsi: Make sure the np under each tpg is unique Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 14/44] usb: dwc2: gadget: dont try to disable ep0 in dwc2_hsotg_suspend Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 15/44] net: stmmac: dwmac-sun8i: use return val of readl_poll_timeout() Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 16/44] Revert "net: axienet: Wait for PhyRstCmplt after core reset" Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 17/44] bpf: Add kconfig knob for disabling unpriv bpf by default Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 18/44] ARM: dts: imx23-evk: Remove MX23_PAD_SSP1_DETECT from hog group Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 19/44] ARM: dts: meson: Fix the UART compatible strings Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 20/44] staging: fbtft: Fix error path in fbtft_driver_module_init() Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 21/44] ARM: dts: imx6qdl-udoo: Properly describe the SD card detect Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 22/44] usb: f_fs: Fix use-after-free for epfile Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 23/44] bonding: pair enable_port with slave_arr_updates Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 24/44] ipmr,ip6mr: acquire RTNL before calling ip[6]mr_free_table() on failure path Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 25/44] net: do not keep the dst cache when uncloning an skb dst and its metadata Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 26/44] net: fix a memleak " Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 27/44] tipc: rate limit warning for received illegal binding update Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 28/44] net: amd-xgbe: disable interrupts during pci removal Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 29/44] vt_ioctl: fix array_index_nospec in vt_setactivate Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 30/44] vt_ioctl: add array_index_nospec to VT_ACTIVATE Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 31/44] n_tty: wake up poll(POLLRDNORM) on receiving data Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 32/44] usb: ulpi: Move of_node_put to ulpi_dev_release Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 33/44] usb: ulpi: Call of_node_put correctly Greg Kroah-Hartman
2022-02-14  9:25 ` Greg Kroah-Hartman [this message]
2022-02-14  9:25 ` [PATCH 4.14 35/44] USB: gadget: validate interface OS descriptor requests Greg Kroah-Hartman
2022-02-14  9:25 ` [PATCH 4.14 36/44] usb: gadget: rndis: check size of RNDIS_MSG_SET command Greg Kroah-Hartman
2022-02-14  9:26 ` [PATCH 4.14 37/44] USB: serial: ftdi_sio: add support for Brainboxes US-159/235/320 Greg Kroah-Hartman
2022-02-14  9:26 ` [PATCH 4.14 38/44] USB: serial: option: add ZTE MF286D modem Greg Kroah-Hartman
2022-02-14  9:26 ` [PATCH 4.14 39/44] USB: serial: ch341: add support for GW Instek USB2.0-Serial devices Greg Kroah-Hartman
2022-02-14  9:26 ` [PATCH 4.14 40/44] USB: serial: cp210x: add NCR Retail IO box id Greg Kroah-Hartman
2022-02-14  9:26 ` [PATCH 4.14 41/44] USB: serial: cp210x: add CPI Bulk Coin Recycler id Greg Kroah-Hartman
2022-02-14  9:26 ` [PATCH 4.14 42/44] seccomp: Invalidate seccomp mode to catch death failures Greg Kroah-Hartman
2022-02-14  9:26 ` [PATCH 4.14 43/44] hwmon: (dell-smm) Speed up setting of fan speed Greg Kroah-Hartman
2022-02-14  9:26 ` [PATCH 4.14 44/44] perf: Fix list corruption in perf_cgroup_switch() Greg Kroah-Hartman
2022-02-14 14:21 ` [PATCH 4.14 00/44] 4.14.267-rc1 review Jon Hunter
2022-02-14 20:42 ` Slade Watkins
2022-02-15  1:50 ` Guenter Roeck
2022-02-15  9:34 ` Naresh Kamboju

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=20220214092449.011455274@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_pkondeti@quicinc.com \
    --cc=quic_ugoswami@quicinc.com \
    --cc=stable@vger.kernel.org \
    /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