Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2019618imm; Thu, 24 May 2018 04:37:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrIOth3itihABFoZkf3dDH85HRk2rntD6nmFcTkDxEBVGeKiDdcgwqxJ46nZyoyrzH0aT4h X-Received: by 2002:a62:3a1c:: with SMTP id h28-v6mr6883946pfa.209.1527161857506; Thu, 24 May 2018 04:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527161857; cv=none; d=google.com; s=arc-20160816; b=ItViLdT/rJMqzm0lLSPEFi3P+y0QEyLBQp84w44QSWS1ybcwxDGmHOF4DbacZf1CGU zJ5XQyl7dRYCBF4aN1Lcd4Vpg9NGNTSOOxunT4Eg8PuTO0SMKkravbwnbJSFR5dZSIki zV+08NU2rGNOlSb8IwZuNpefDKJ7I1CL6W7p+R0htppuA3vJ50A3av/PPhK7Tk14DVku syolVN9yOulSZkli9Ec/MvybgrDZ4LIsswSL/ba63Z6pkG04M3hodcVv8Tg25hzFpQ/2 u8gHckWTgKC40OFeD9ZaONSIZwLz2yd8G/UaeRpZmhM5FuesF8Z7HKNenSpJkOFWWDZ2 Vpig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Zv+sVwY8qvcaLqcLUQRV3+sWPMzRiorFUS/eoQ3Ij6A=; b=juBHB/ED8vh4FZyAk+MTyn1LVIml2M9nt4unmCsG3dJP+0qihusRJeyeVeDAk5NmoV cjIsr1Fl4w2PyePG1WX8qGXxYFs4JHfxpGCSftOssHsa6C48xL90KrdtqxTH9N2qRHbw KJPOhmxeIh7/PXdjegQb7XiNRYiFGmzgAvsFoPZm0r+T4yZUBFvCK20HB/tXTfs6Jkd2 9sYGGQ1b/DWsvM+2yjsHPbJHPN/ZeK8dbigvoJwkuA5IWUV3y9dH4uVjvXmCulPCec3s UZfiCT8eqZfrrQ7BHAMohjY+zQX+EjFSMr2Gkwg8shcE7DBupR+mJ4yZX/mWSc9clLq7 1/uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S5GrSDsc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si16702814pgr.167.2018.05.24.04.37.22; Thu, 24 May 2018 04:37:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S5GrSDsc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967123AbeEXJtl (ORCPT + 99 others); Thu, 24 May 2018 05:49:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:38652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967093AbeEXJtg (ORCPT ); Thu, 24 May 2018 05:49:36 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B14ED20847; Thu, 24 May 2018 09:49:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155376; bh=eoX7Q87qXYDetVa/gRGSELfExh4dJNZxh9dL6YDufsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S5GrSDscm20+fhnYBToJP72S8JYMVMVhdwpXP/QKimgGGLsYL+JlgWGfctMUNy4m5 FqHEa0fHCCV1/MamI4hdZcrMzFzQA1l2qbYpkjPJz2TtaE+pJ8vmSO28PPQFGMfS1a 8zKkvyzJu+yYWJfFTr74RckXRaJXqj0THHB3IWC4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominik Bozek , Kuppuswamy Sathyanarayanan , Oliver Neukum , Sasha Levin 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 Message-Id: <20180524093607.272458772@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dominik Bozek [ 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] [] dump_stack+0x67/0x92 [ 46.884511] [] __warn+0xd1/0xf0 [ 46.884513] [] warn_slowpath_fmt+0x5f/0x80 [ 46.884516] [] __list_add+0xb3/0xc0 [ 46.884521] [] *usb_anchor_urb*+0x4c/0xa0 [ 46.884524] [] *acm_tty_flush_chars*+0x8f/0xb0 [ 46.884527] [] *acm_tty_put_char*+0x41/0x100 [ 46.884530] [] tty_put_char+0x24/0x40 [ 46.884533] [] do_output_char+0xa5/0x200 [ 46.884535] [] __process_echoes+0x148/0x290 [ 46.884538] [] n_tty_receive_buf_common+0x57c/0xb00 [ 46.884541] [] n_tty_receive_buf2+0x14/0x20 [ 46.884543] [] tty_ldisc_receive_buf+0x22/0x50 [ 46.884545] [] flush_to_ldisc+0xc5/0xe0 [ 46.884549] [] process_one_work+0x148/0x440 [ 46.884551] [] worker_thread+0x69/0x4a0 [ 46.884554] [] ? max_active_store+0x80/0x80 [ 46.884556] [] kthread+0x110/0x130 [ 46.884559] [] ? kthread_park+0x60/0x60 [ 46.884563] [] ret_from_fork+0x27/0x40 [ 46.884566] ---[ end trace 3bd599058b8a9eb3 ]--- Signed-off-by: Dominik Bozek Signed-off-by: Kuppuswamy Sathyanarayanan Acked-by: Oliver Neukum Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- 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;