stable.vger.kernel.org archive mirror
 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, Dominik Bozek <dominikx.bozek@intel.com>,
	Kuppuswamy Sathyanarayanan
	<sathyanarayanan.kuppuswamy@linux.intel.com>,
	Oliver Neukum <oneukum@suse.com>,
	Sasha Levin <alexander.levin@microsoft.com>
Subject: [PATCH 4.9 30/96] usb: cdc_acm: prevent race at write to acm while system resumes
Date: Thu, 24 May 2018 11:38:13 +0200	[thread overview]
Message-ID: <20180524093607.272458772@linuxfoundation.org> (raw)
In-Reply-To: <20180524093605.602125311@linuxfoundation.org>

4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Dominik Bozek <dominikx.bozek@intel.com>

[ Upstream commit b86b8eb6fecb5a4bac1ed0ca925c4082a61ea6e9 ]

ACM driver may accept data to transmit while system is not fully
resumed. In this case ACM driver buffers data and prepare URBs
on usb anchor list.
There is a little chance that two tasks put a char and initiate
acm_tty_flush_chars(). In such a case, driver will put one URB
twice on usb anchor list.
This patch also reset length of data before resue of a buffer.
This not only prevent sending rubbish, but also lower risc of race.

Without this patch we hit following kernel panic in one of our
stabilty/stress tests.

[   46.884442] *list_add double add*: new=ffff9b2ab7289330, prev=ffff9b2ab7289330, next=ffff9b2ab81e28e0.
[   46.884476] Modules linked in: hci_uart btbcm bluetooth rfkill_gpio igb_avb(O) cfg80211 snd_soc_sst_bxt_tdf8532 snd_soc_skl snd_soc_skl_ipc snd_soc_sst_ipc snd_soc_sst_dsp snd_soc_sst_acpi snd_soc_sst_match snd_hda_ext_core snd_hda_core trusty_timer trusty_wall trusty_log trusty_virtio trusty_ipc trusty_mem trusty_irq trusty virtio_ring virtio intel_ipu4_mmu_bxtB0 lib2600_mod_bxtB0 intel_ipu4_isys_mod_bxtB0 lib2600psys_mod_bxtB0 intel_ipu4_psys_mod_bxtB0 intel_ipu4_mod_bxtB0 intel_ipu4_wrapper_bxtB0 intel_ipu4_acpi videobuf2_dma_contig as3638 dw9714 lm3643 crlmodule smiapp smiapp_pll
[   46.884480] CPU: 1 PID: 33 Comm: kworker/u8:1 Tainted: G     U  W  O    4.9.56-quilt-2e5dc0ac-g618ed69ced6e-dirty #4
[   46.884489] Workqueue: events_unbound flush_to_ldisc
[   46.884494]  ffffb98ac012bb08 ffffffffad3e82e5 ffffb98ac012bb58 0000000000000000
[   46.884497]  ffffb98ac012bb48 ffffffffad0a23d1 00000024ad6374dd ffff9b2ab7289330
[   46.884500]  ffff9b2ab81e28e0 ffff9b2ab7289330 0000000000000002 0000000000000000
[   46.884501] Call Trace:
[   46.884507]  [<ffffffffad3e82e5>] dump_stack+0x67/0x92
[   46.884511]  [<ffffffffad0a23d1>] __warn+0xd1/0xf0
[   46.884513]  [<ffffffffad0a244f>] warn_slowpath_fmt+0x5f/0x80
[   46.884516]  [<ffffffffad407443>] __list_add+0xb3/0xc0
[   46.884521]  [<ffffffffad71133c>] *usb_anchor_urb*+0x4c/0xa0
[   46.884524]  [<ffffffffad782c6f>] *acm_tty_flush_chars*+0x8f/0xb0
[   46.884527]  [<ffffffffad782cd1>] *acm_tty_put_char*+0x41/0x100
[   46.884530]  [<ffffffffad4ced34>] tty_put_char+0x24/0x40
[   46.884533]  [<ffffffffad4d3bf5>] do_output_char+0xa5/0x200
[   46.884535]  [<ffffffffad4d3e98>] __process_echoes+0x148/0x290
[   46.884538]  [<ffffffffad4d654c>] n_tty_receive_buf_common+0x57c/0xb00
[   46.884541]  [<ffffffffad4d6ae4>] n_tty_receive_buf2+0x14/0x20
[   46.884543]  [<ffffffffad4d9662>] tty_ldisc_receive_buf+0x22/0x50
[   46.884545]  [<ffffffffad4d9c05>] flush_to_ldisc+0xc5/0xe0
[   46.884549]  [<ffffffffad0bcfe8>] process_one_work+0x148/0x440
[   46.884551]  [<ffffffffad0bdc19>] worker_thread+0x69/0x4a0
[   46.884554]  [<ffffffffad0bdbb0>] ? max_active_store+0x80/0x80
[   46.884556]  [<ffffffffad0c2e10>] kthread+0x110/0x130
[   46.884559]  [<ffffffffad0c2d00>] ? kthread_park+0x60/0x60
[   46.884563]  [<ffffffffadad9917>] ret_from_fork+0x27/0x40
[   46.884566] ---[ end trace 3bd599058b8a9eb3 ]---

Signed-off-by: Dominik Bozek <dominikx.bozek@intel.com>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Acked-by: Oliver Neukum <oneukum@suse.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/class/cdc-acm.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -174,6 +174,7 @@ static int acm_wb_alloc(struct acm *acm)
 		wb = &acm->wb[wbn];
 		if (!wb->use) {
 			wb->use = 1;
+			wb->len = 0;
 			return wbn;
 		}
 		wbn = (wbn + 1) % ACM_NW;
@@ -731,16 +732,18 @@ static int acm_tty_write(struct tty_stru
 static void acm_tty_flush_chars(struct tty_struct *tty)
 {
 	struct acm *acm = tty->driver_data;
-	struct acm_wb *cur = acm->putbuffer;
+	struct acm_wb *cur;
 	int err;
 	unsigned long flags;
 
+	spin_lock_irqsave(&acm->write_lock, flags);
+
+	cur = acm->putbuffer;
 	if (!cur) /* nothing to do */
-		return;
+		goto out;
 
 	acm->putbuffer = NULL;
 	err = usb_autopm_get_interface_async(acm->control);
-	spin_lock_irqsave(&acm->write_lock, flags);
 	if (err < 0) {
 		cur->use = 0;
 		acm->putbuffer = cur;

  parent reply	other threads:[~2018-05-24  9:49 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-24  9:37 [PATCH 4.9 00/96] 4.9.103-stable review Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 01/96] net/mlx4_core: Fix error handling in mlx4_init_port_info Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 02/96] net: test tailroom before appending to linear skb Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 03/96] packet: in packet_snd start writing at link layer allocation Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 04/96] sock_diag: fix use-after-free read in __sk_free Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 05/96] tcp: purge write queue in tcp_connect_init() Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 06/96] vmxnet3: set the DMA mask before the first DMA map operation Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 07/96] vmxnet3: use DMA memory barriers where required Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 08/96] ext2: fix a block leak Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 09/96] s390: add assembler macros for CPU alternatives Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 10/96] s390: move expoline assembler macros to a header Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 11/96] s390/crc32-vx: use expoline for indirect branches Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 12/96] s390/lib: " Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 13/96] s390/ftrace: " Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 14/96] s390/kernel: " Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 15/96] s390: move spectre sysfs attribute code Greg Kroah-Hartman
2018-05-24  9:37 ` [PATCH 4.9 16/96] s390: extend expoline to BC instructions Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 17/96] s390: use expoline thunks in the BPF JIT Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 18/96] scsi: libsas: defer ata device eh commands to libata Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 19/96] scsi: sg: allocate with __GFP_ZERO in sg_build_indirect() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 20/96] scsi: zfcp: fix infinite iteration on ERP ready list Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 21/96] cfg80211: limit wiphy names to 128 bytes Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 22/96] hfsplus: stop workqueue when fill_super() failed Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 23/96] x86/kexec: Avoid double free_page() upon do_kexec_load() failure Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 24/96] usb: gadget: f_uac2: fix bFirstInterface in composite gadget Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 25/96] usb: dwc3: Undo PHY init if soft reset fails Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 26/96] usb: dwc3: omap: dont miss events during suspend/resume Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 27/96] usb: gadget: core: Fix use-after-free of usb_request Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 28/96] usb: gadget: fsl_udc_core: fix ep valid checks Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 29/96] usb: dwc2: Fix dwc2_hsotg_core_init_disconnected() Greg Kroah-Hartman
2018-05-24  9:38 ` Greg Kroah-Hartman [this message]
2018-05-24  9:38 ` [PATCH 4.9 31/96] USB: OHCI: Fix NULL dereference in HCDs using HCD_LOCAL_MEM Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 32/96] net/usb/qmi_wwan.c: Add USB id for lt4120 modem Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 33/96] net-usb: add qmi_wwan if on lte modem wistron neweb d18q1 Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 34/96] Bluetooth: btusb: Add USB ID 7392:a611 for Edimax EW-7611ULB Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 35/96] ALSA: usb-audio: Add native DSD support for Luxman DA-06 Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 36/96] usb: dwc3: Add SoftReset PHY synchonization delay Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 37/96] usb: dwc3: Update DWC_usb31 GTXFIFOSIZ reg fields Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 38/96] xhci: zero usb device slot_id member when disabling and freeing a xhci slot Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 39/96] usb: dwc2: Fix interval type issue Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 40/96] usb: dwc2: host: Fix transaction errors in host mode Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 41/96] usb: gadget: ffs: Let setup() return USB_GADGET_DELAYED_STATUS Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 42/96] usb: gadget: ffs: Execute copy_to_user() with USER_DS set Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 43/96] usb: gadget: udc: change comparison to bitshift when dealing with a mask Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 44/96] usb: gadget: composite: fix incorrect handling of OS desc requests Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 45/96] media: em28xx: USB bulk packet size fix Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 46/96] Bluetooth: btusb: Add device ID for RTL8822BE Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 47/96] staging: lustre: fix bug in osc_enter_cache_try Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 48/96] staging: rtl8192u: return -ENOMEM on failed allocation of priv->oldaddr Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 49/96] staging: lustre: lmv: correctly iput lmo_root Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 50/96] crypto: sunxi-ss - Add MODULE_ALIAS to sun4i-ss Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 51/96] scsi: fas216: fix sense buffer initialization Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 52/96] scsi: ufs: Enable quirk to ignore sending WRITE_SAME command Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 53/96] scsi: bnx2fc: Fix check in SCSI completion handler for timed out request Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 54/96] scsi: sym53c8xx_2: iterator underflow in sym_getsync() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 55/96] scsi: mptfusion: Add bounds check in mptctl_hp_targetinfo() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 56/96] scsi: qla2xxx: Avoid triggering undefined behavior in qla2x00_mbx_completion() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 57/96] scsi: storvsc: Increase cmd_per_lun for higher speed devices Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 58/96] scsi: aacraid: fix shutdown crash when init fails Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 59/96] scsi: qla4xxx: skip error recovery in case of register disconnect Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 60/96] scsi: mpt3sas: Do not mark fw_event workqueue as WQ_MEM_RECLAIM Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 61/96] scsi: sd: Keep disk read-only when re-reading partition Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 62/96] scsi: aacraid: Insure command thread is not recursively stopped Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 63/96] scsi: mvsas: fix wrong endianness of sgpio api Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 64/96] scsi: lpfc: Fix issue_lip if link is disabled Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 65/96] scsi: lpfc: Fix soft lockup in lpfc worker thread during LIP testing Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 66/96] scsi: lpfc: Fix frequency of Release WQE CQEs Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 67/96] ASoC: au1x: Fix timeout tests in au1xac97c_ac97_read() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 68/96] ASoC: topology: create TLV data for dapm widgets Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 69/96] ASoC: samsung: i2s: Ensure the RCLK rate is properly determined Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 70/96] clk: rockchip: Fix wrong parent for SDMMC phase clock for rk3228 Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 71/96] clk: Dont show the incorrect clock phase Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 72/96] clk: tegra: Fix pll_u rate configuration Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 73/96] media: cx23885: Set subdev host data to clk_freq pointer Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 74/96] clk: rockchip: Prevent calculating mmc phase if clock rate is zero Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 75/96] clk: samsung: s3c2410: Fix PLL rates Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 4.9 76/96] clk: samsung: exynos7: " Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 77/96] clk: samsung: exynos5260: " Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 78/96] clk: samsung: exynos5433: " Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 79/96] clk: samsung: exynos5250: " Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 80/96] clk: samsung: exynos3250: " Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 81/96] media: dmxdev: fix error code for invalid ioctls Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 82/96] media: cx23885: Override 888 ImpactVCBe crystal frequency Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 83/96] media: s3c-camif: fix out-of-bounds array access Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 84/96] media: vb2: Fix videobuf2 to map correct area Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 85/96] media: vivid: fix incorrect capabilities for radio Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 86/96] media: cx25821: prevent out-of-bounds read on array card Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 87/96] serial: xuartps: Fix out-of-bounds access through DT alias Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 88/96] serial: samsung: Fix out-of-bounds access through serial port index Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 89/96] serial: mxs-auart: " Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 91/96] serial: fsl_lpuart: Fix out-of-bounds access through DT alias Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 92/96] serial: arc_uart: " Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 93/96] serial: 8250: Dont service RX FIFO if interrupts are disabled Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 94/96] rtc: snvs: Fix usage of snvs_rtc_enable Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 95/96] rtc: hctosys: Ensure system time doesnt overflow time_t Greg Kroah-Hartman
2018-05-24  9:39 ` [PATCH 4.9 96/96] rtc: tx4939: avoid unintended sign extension on a 24 bit shift Greg Kroah-Hartman
2018-05-24 17:32 ` [PATCH 4.9 00/96] 4.9.103-stable review Guenter Roeck
2018-05-24 18:04 ` Dan Rue
2018-05-24 19:26 ` Shuah Khan

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=20180524093607.272458772@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=alexander.levin@microsoft.com \
    --cc=dominikx.bozek@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.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;
as well as URLs for NNTP newsgroup(s).