Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3319893imu; Sun, 11 Nov 2018 12:17:18 -0800 (PST) X-Google-Smtp-Source: AJdET5e1/ZaGbz3d7nkrfuUQQHrC30vFBDVs7mX1A7OhBpaklOd4ChKzr7Aoz28ou8pEqoHfvQ0m X-Received: by 2002:a63:d40a:: with SMTP id a10mr14752031pgh.394.1541967438350; Sun, 11 Nov 2018 12:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967438; cv=none; d=google.com; s=arc-20160816; b=V+yObVN/lnReQVe07cznOOSpOuqfGFvEPbTN//aaNsjs2NYOKPv+S2efvcIBp4A2Ur 5HHFW5Rw9YbwLRhcTL6axM+pkpOiOcGOEbXAkzly/AbCaz0bT8Gn3RjombxEfN6qD+P7 QOcQ53erbEunsqhzaIW77yO8WTqmOfSijLFu2eJEzbNR0NbM9uL2GnrP39ldKmitAMi+ SeUgphg3BxsARsboaM2qzzmv0JlPNYGHEp+Dg/Uh/A33Y81oY6kNtL4qlOuZl3PPLq2x 42nLZFQBz1cCAHC6fgnW5estNb84+GNs19te2ikunN5wnHJzK6Yj02O/f9jBwvAIfq5t x0Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=ljmg5x1GdxvCfwUCk37h1+2eCzsnfmQxvNHZ/3r/sJ8=; b=q+/6htiRxOKTAclHgrfcdOUaEhrbgt2/i3NL2W0N9SD4Sf7rful6FDNbN17Tg5RHWv CRFcFt8IUH8EDiuH4Os5XQ0j2uMPFKRnLXJoSVy2nnxBub/QA7BQzhOwYoxEy9o1Btce kc7d1mqxwPI5S2e0YJKVNeHoZKXq1bQPkTPsxz6Ufi0tp5ZFSDJuAgFf1YIOlAQsa2Lw QFmlK7F5ncSDwhlUZ0oWhwY2pvGzK7DsjnCsZSVb8xEBvEdj0Q+OkMNs6wFCdQQLwdWS rQ/1tye6WTv4X8+XiUPViKEsCIFp/FayCOnoPIckkx9+e3G8AiT1QlBNcEiReu9Qabdh WaLA== ARC-Authentication-Results: i=1; mx.google.com; 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 k19-v6si15101042pls.211.2018.11.11.12.17.03; Sun, 11 Nov 2018 12:17:18 -0800 (PST) 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; 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 S1731125AbeKLGFC (ORCPT + 99 others); Mon, 12 Nov 2018 01:05:02 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:53016 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725905AbeKLGFA (ORCPT ); Mon, 12 Nov 2018 01:05:00 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvt6-0000l5-OC; Sun, 11 Nov 2018 19:59:16 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsQ-0001TN-9U; Sun, 11 Nov 2018 19:58:34 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Felipe Balbi" , "Yoshihiro Shimoda" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 085/366] usb: gadget: function: printer: avoid spinlock recursion In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Yoshihiro Shimoda commit 9ada8c582088d32bd5c071c17213bc6edf37443a upstream. If usb_gadget_giveback_request() is called in usb_ep_queue(), this printer_write() is possible to cause spinlock recursion. So, this patch adds spin_unlock() before calls usb_ep_queue() to avoid it. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Felipe Balbi [bwh: Backported to 3.16: adjust filename] Signed-off-by: Ben Hutchings --- drivers/usb/gadget/printer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c @@ -587,6 +587,7 @@ printer_write(struct file *fd, const cha size_t size; /* Amount of data in a TX request. */ size_t bytes_copied = 0; struct usb_request *req; + int value; DBG(dev, "printer_write trying to send %d bytes\n", (int)len); @@ -666,7 +667,11 @@ printer_write(struct file *fd, const cha return -EAGAIN; } - if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) { + /* here, we unlock, and only unlock, to avoid deadlock. */ + spin_unlock(&dev->lock); + value = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC); + spin_lock(&dev->lock); + if (value) { list_add(&req->list, &dev->tx_reqs); spin_unlock_irqrestore(&dev->lock, flags); mutex_unlock(&dev->lock_printer_io);