Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3009193pxb; Mon, 18 Oct 2021 06:31:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrEA5W4I0+stewx86vcWSQ21s7JG5WcQsbffyKTmYXQ4xatYNZNtxbq5KTw3FZZdf+gAnl X-Received: by 2002:a17:903:41c9:b0:13e:e11e:cde7 with SMTP id u9-20020a17090341c900b0013ee11ecde7mr27315267ple.19.1634563910408; Mon, 18 Oct 2021 06:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634563910; cv=none; d=google.com; s=arc-20160816; b=l+lLRFtY6Z6nJrQeS8S4CUa6OoZXZNBMgU4iDdUmRv9h5BUq/mdYqq4RboeBCXvmzE eIq/K9wtW2CAnyLtqeM7S2iWRHTE6pDJRB5EQDQTaTpPKKwhBLtKe9y1JAg1gA8RUfRR pOCLwJ7UE54yW8ncreNC3nQbPC6dojyFN8jG7Jv+l+jtk/wHD+FJs/lCMloBs6BCX90H mbgik8iooiH5eB1XbX+GUxk8eIXGtxsxB6abBgyl2zqr7QKWVGOdzreHRFJPBdJ4jcMK yYFugb/3ECMjZU2xPfp24LCfe9ygo+5Zy9kF14xyxu1IxEtcd2mvuJW56u9QUWhEPx/H v16Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mjoBbxRVpkL1GnjUzlQzroMEzuhinV7/mkHNA5+gq+g=; b=iPaIZGbWCQJg73T0xPB4QHGeM67A1itr0ZUyxL13NeVRQpy7MTwFNWxkwyuDLODb81 qBebglK7TLUHPjRRgPilJdBlVjX9zpUWlRQLEcOjSbaVo1YCu3gvVnboULYMqclckzYf BSyoOvG7JIY2r+1sYKL+xBSMr2Y5H0UwaJt7Y7mOhVYaSaO5MVUXBNMZtXV6pDdRa1ER R7mOdpoperjSi9/HUMks5q8Y43KR+5sb77TE1qixM4LdLJPhXKL9FtIVhVWePMdOpaOQ smMJRP1hb49tB0Cxli759yu7sPjX6y7jARn1fzNmMBfmVvplVcqRZCNEHZ5pSYiJoeYu umng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gp7smcmo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g12si18306482pjl.69.2021.10.18.06.31.36; Mon, 18 Oct 2021 06:31:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gp7smcmo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbhJRNbd (ORCPT + 99 others); Mon, 18 Oct 2021 09:31:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:42838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232256AbhJRN3q (ORCPT ); Mon, 18 Oct 2021 09:29:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 066186134F; Mon, 18 Oct 2021 13:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563655; bh=cuF6qoX845GPbrXvYCyGXSuzswlFTkRg9SUzLdl0FDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gp7smcmonrLlBJKEGS/dmigBcZWqBVI3swZWpHsyPpKDEAMgqSba+T3GWcNynIaTF 6ap3HT7Xb6NihFM4MlvFVsu4taLtk1bKj0/Yri9KBi22zed64vjD4h13JdtGQ+v/qd cJ3fwwikLR3498FGjLlcHdI46eb1TTzCjnNt+tuU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jonathan Bell , Mathias Nyman Subject: [PATCH 4.19 12/50] xhci: guard accesses to ep_state in xhci_endpoint_reset() Date: Mon, 18 Oct 2021 15:24:19 +0200 Message-Id: <20211018132326.935583884@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132326.529486647@linuxfoundation.org> References: <20211018132326.529486647@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Bell commit a01ba2a3378be85538e0183ae5367c1bc1d5aaf3 upstream. See https://github.com/raspberrypi/linux/issues/3981 Two read-modify-write cycles on ep->ep_state are not guarded by xhci->lock. Fix these. Fixes: f5249461b504 ("xhci: Clear the host side toggle manually when endpoint is soft reset") Cc: stable@vger.kernel.org Signed-off-by: Jonathan Bell Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20211008092547.3996295-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -3093,10 +3093,13 @@ static void xhci_endpoint_reset(struct u ep = &vdev->eps[ep_index]; /* Bail out if toggle is already being cleared by a endpoint reset */ + spin_lock_irqsave(&xhci->lock, flags); if (ep->ep_state & EP_HARD_CLEAR_TOGGLE) { ep->ep_state &= ~EP_HARD_CLEAR_TOGGLE; + spin_unlock_irqrestore(&xhci->lock, flags); return; } + spin_unlock_irqrestore(&xhci->lock, flags); /* Only interrupt and bulk ep's use data toggle, USB2 spec 5.5.4-> */ if (usb_endpoint_xfer_control(&host_ep->desc) || usb_endpoint_xfer_isoc(&host_ep->desc)) @@ -3182,8 +3185,10 @@ static void xhci_endpoint_reset(struct u xhci_free_command(xhci, cfg_cmd); cleanup: xhci_free_command(xhci, stop_cmd); + spin_lock_irqsave(&xhci->lock, flags); if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; + spin_unlock_irqrestore(&xhci->lock, flags); } static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,