Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1918484imm; Thu, 24 May 2018 02:56:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpZ6MhY/loj+ltW0Wgzdo4ulULAu6v/DMNBrltMfGdbo7gM8Nlsrj7+9q588Vui8NyTAIbv X-Received: by 2002:a62:49d7:: with SMTP id r84-v6mr6537416pfi.146.1527155760642; Thu, 24 May 2018 02:56:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527155760; cv=none; d=google.com; s=arc-20160816; b=tcNf8ux0Wi/h0MoggQB3JKQaW7YgaOgF7rghgjzO/hxzk3j8xzdUiqzxHpxjf90D9U ZYepyiLFFArrg0z/w8cyI5wos5Glxp0xx2LQ1Y82PrpHak46ET2HFRsPwv20U1fzIRKo bCig32kWlmWCwsrg3SNgSLb5Ma0mxjxq4YmEYelSWcu2ZKPWmRorrLZMZhDAITukz4Vo eoC3VHaYmfX6BkpSXK+nB8UYagSzRrkWa6IuVD7S3QUWtQZfP1PFNITc8tOzWyCiciy/ kfuCGA5f179YiKSa/QWlok5qqD7jrGkjgkKHu7IuD9HkaCQnfo4f0Fqz4GeavlknnHFz aIqQ== 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=/gGmirxjTDbbkyJCjMAP8nszjnig9NMdl0k7u4SyavM=; b=YM7KI4Cg2sgRZ23mqHVIapPchpeNX+45zYvMc0lTqEgtCSDCPNlZHddehLKZGuMV84 eFxhoN5oyzpM9/1LcZrZtF41ItFaN9uC6y6T2ZfS2XRoeyxC5lMsrHq6vdShv5clp76M eU+44EUEubJ9rPpxrNxINZwW7NsL8ZaoxtHQLhi2LpwsM+kJHtElfvuRAMNOPmuVgyyy YiJznuGG8X8TNMgwYRF+/TaDy9Fn7PITRiVNFkjZVhWUj49WdAWGsf8/V/8WEGqgVWsF e3bAprW7IQnfkp0LnyAHilqeuQ9uKMYUo0ReDyBH0cNVd0tRc2cofWEXOGFaqORgu4Nd yiLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B9el9k+u; 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 d75-v6si9333017pga.322.2018.05.24.02.55.46; Thu, 24 May 2018 02:56:00 -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=B9el9k+u; 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 S968146AbeEXJyQ (ORCPT + 99 others); Thu, 24 May 2018 05:54:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:32918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966770AbeEXJxx (ORCPT ); Thu, 24 May 2018 05:53:53 -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 D6FB720891; Thu, 24 May 2018 09:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155633; bh=pj7lF/OD/24sHbkFK7OecqmdA/UrKd4ut52nbbr+eaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B9el9k+uvOBltmCvlnqtd1oViNxfwbCfL+N9jlk7igii9wZ6Ys8AuhDd2ncQY9mU6 Uue9rReBRjn5/njVCJqz3oEKiE9R18WmDgj2xEf0V8aTmIFo1KINjlXJ03YEJYLQCD xZ9/a7Wyhptc+lMSNispDsk1ncaOULfT8if486So= 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.14 060/165] usb: cdc_acm: prevent race at write to acm while system resumes Date: Thu, 24 May 2018 11:37:46 +0200 Message-Id: <20180524093624.443683603@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@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.14-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 @@ -187,6 +187,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; @@ -818,16 +819,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;