Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp494757yba; Mon, 1 Apr 2019 10:25:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqz186EV0ZjUkT7nrS70VOIaGr3sNKTaTxptmrxtdsEfDOLkg/u4Qv0ShSxDl0U38Qci87yy X-Received: by 2002:aa7:9211:: with SMTP id 17mr63333952pfo.220.1554139553025; Mon, 01 Apr 2019 10:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554139553; cv=none; d=google.com; s=arc-20160816; b=XRaG3nIot+Dz/rJY3waJFw0RxjW5iSvp9mewbGityYu2RuIHEMQUY/j3A+rMDbzHYm fu0ANGdx8hy0E/KnUZW4597qDvDKSNqjnYUKNF05U+CZTz1PEkxNbbkHCuITTU/nD5m4 QQqW6Go84np4nKnme/dJkjNfulOTxTkUNtGFpe8fEvp6Jr5q7/8UQRvO7sAWTUBNrVQD H8JZDhZ9CLYNn13G2hNTuOd8UM90iqt/J0SxgPbufGA3e/QI0vuEVRFkiz+B/0lupS2S TjKmjND2qdXKJIHsCCVj8JP7hEOKf2areMN6sieg8SLaLEwpegCbYx+0NqTflyAtVyCw nSiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VwwZUiE++Fb4RbgqHced9w4tdLPWIfkbxntC+hjjpMU=; b=fhNtzCvcfg8KWvCrOLvQxfs2SbrIlo6dLbEFzRLmX70bepg89/2mCKqxqnzFDCjauD 0lPGTQnwx6xlfwTatD4z41gEGzAFXwdqCnsZ9bF3iFVe//2010gN28jE4YdGEZEVvf66 wE8QpDZxaLh2D2c3mfSmi2GoIJ24k2buXcNQLB8JIgTIzMe33N2ksON/+qejoDXODJGq oUp1PvmsWuR5zPZrdHNLhuClptqZjhNknPVY2VNfSleY7lcHGbXijBDo/+mfxIqLoGrH d3HnMhMqrcW1EHUVEhABwggBCnm6x9bZtIG7hVaymGjdGIuivUfafv6U6zdVmdj1ZrJa UFEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VRl3D7Vo; 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 w14si8900686plq.262.2019.04.01.10.25.37; Mon, 01 Apr 2019 10:25:53 -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=VRl3D7Vo; 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 S1732361AbfDARZD (ORCPT + 99 others); Mon, 1 Apr 2019 13:25:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:56042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731920AbfDARZC (ORCPT ); Mon, 1 Apr 2019 13:25:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 2EB8D2063F; Mon, 1 Apr 2019 17:25:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554139501; bh=QZNfD9wHLm0jzv4B8jV8bbltKWZFOiHuW/lTLwXvtC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VRl3D7VogXvP5ChZk0EjJcSaF6YjlhCE+xEEU0J4qLw6RIhCW2a039CN9SrL6rYNr jmbETTc8nuvXpWyz7WW0VgxTeUElhoV4s5MKTo54dLSeKYHCzvGAkEQdZ/HR7OwoEh 3LAA0Q4RQ6qp9va+65f2YaElJi8MGwQ3E4nBaDlo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Bottomley , Radoslav Gerganov , Felipe Balbi Subject: [PATCH 4.14 095/107] USB: gadget: f_hid: fix deadlock in f_hidg_write() Date: Mon, 1 Apr 2019 19:02:50 +0200 Message-Id: <20190401170054.326432350@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170045.246405031@linuxfoundation.org> References: <20190401170045.246405031@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Radoslav Gerganov commit 072684e8c58d17e853f8e8b9f6d9ce2e58d2b036 upstream. In f_hidg_write() the write_spinlock is acquired before calling usb_ep_queue() which causes a deadlock when dummy_hcd is being used. This is because dummy_queue() callbacks into f_hidg_req_complete() which tries to acquire the same spinlock. This is (part of) the backtrace when the deadlock occurs: 0xffffffffc06b1410 in f_hidg_req_complete 0xffffffffc06a590a in usb_gadget_giveback_request 0xffffffffc06cfff2 in dummy_queue 0xffffffffc06a4b96 in usb_ep_queue 0xffffffffc06b1eb6 in f_hidg_write 0xffffffff8127730b in __vfs_write 0xffffffff812774d1 in vfs_write 0xffffffff81277725 in SYSC_write Fix this by releasing the write_spinlock before calling usb_ep_queue() Reviewed-by: James Bottomley Tested-by: James Bottomley Cc: stable@vger.kernel.org # 4.11+ Fixes: 749494b6bdbb ("usb: gadget: f_hid: fix: Move IN request allocation to set_alt()") Signed-off-by: Radoslav Gerganov Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_hid.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -395,20 +395,20 @@ try_again: req->complete = f_hidg_req_complete; req->context = hidg; + spin_unlock_irqrestore(&hidg->write_spinlock, flags); + status = usb_ep_queue(hidg->in_ep, req, GFP_ATOMIC); if (status < 0) { ERROR(hidg->func.config->cdev, "usb_ep_queue error on int endpoint %zd\n", status); - goto release_write_pending_unlocked; + goto release_write_pending; } else { status = count; } - spin_unlock_irqrestore(&hidg->write_spinlock, flags); return status; release_write_pending: spin_lock_irqsave(&hidg->write_spinlock, flags); -release_write_pending_unlocked: hidg->write_pending = 0; spin_unlock_irqrestore(&hidg->write_spinlock, flags);