Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3015398pxb; Mon, 18 Oct 2021 06:39:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+t4FO8A2S3GLxb56zyHQ/e4Dq8+v8HZO2/DfgVY3NAraiLKTbdWGowmqEXejpWS6EQG0k X-Received: by 2002:a17:90b:4c86:: with SMTP id my6mr33781987pjb.203.1634564342502; Mon, 18 Oct 2021 06:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564342; cv=none; d=google.com; s=arc-20160816; b=WkrzHvbfERcUn0YU8me66UXz/++UC0rVT7ZqR7P8ruqGPi9yMWKwQ6lglFc305bA8C 9SbRDGKyEMvONVDbePnYZm5Io0VKGdVpP64gaOvbAcnBLZnqxcHg0wWULybtF2+9BNFr 9645uJXlqCdaiqZ6e6ND+uMDzB4IoJQ/hjoG59Yn4mbPBvwEBxeGqtkauc8GMZyoQJ27 EPRlstL8YSuWarZnLPmJxY7/y6rpHkxdXxknjkz5FBxB5i3GLEcQv9rBIR7YgKXoU0EW t5Q1C18S4NSbAniYnMbZXJZCCKe7d9l14Jy5drmL8s+dxAxTtDH49WSmdBC8OabjZoV0 pnUQ== 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=OhUjEy3yS8U1lHuoNuF83R8fI41yxK3WJoMmS4B47b0=; b=n8czWXJ7vzbxjCwmCL5K4SQcg27kzbeWZd8ot7qfw13mu9MOzyG2xg2syULqFVIzWb U0k4YZwfH/2hfru6JVwORd1IKAq2VhuJLUTincWpa+EM9AY0GvdYGoqGtnYyNBqvm0pv eJT0tgf32p/wrkhOA26TgGQFr6iWNDrhjqTR7WSdTi3UHZGwJLbXjHU1+APFXF7n9nyQ zBoXixyK8xeLckCQGLle1BD56NWDPqOowDkx4GMOwUlMhCqUzwSJzHvhbos1HmrAi2kW PnqU9/OHorReQsFrDI4ASKkiXOn1FvjprB5e186HP6FfOSxWPEmDYII/16g3rEFBWoIE uQVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LXAFg59e; 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 pf3si25749983pjb.53.2021.10.18.06.38.49; Mon, 18 Oct 2021 06:39:02 -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=LXAFg59e; 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 S232568AbhJRNja (ORCPT + 99 others); Mon, 18 Oct 2021 09:39:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:56376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233119AbhJRNg5 (ORCPT ); Mon, 18 Oct 2021 09:36:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 35ACD60295; Mon, 18 Oct 2021 13:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563884; bh=uU1dajyjx+Uyi5D5/TdGmN40awWfzaNcGUHRGW8Tb7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LXAFg59eRYZFgOCbIsHrq8d/NYTxGg1StbSwmBySutCn59UKvLLdYyVPt9MPLRNeK O0j4NT0iqJhC7jPxLYjtYI4IPG1EzbrmL0gHTHfokyhVanDjw1tniMMmV2Rukj3541 SnWtReVdhOynbufNYZiFXxVqfwvoObdO/60zXyq0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jonathan Bell , Mathias Nyman Subject: [PATCH 5.4 19/69] xhci: guard accesses to ep_state in xhci_endpoint_reset() Date: Mon, 18 Oct 2021 15:24:17 +0200 Message-Id: <20211018132330.106182147@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132329.453964125@linuxfoundation.org> References: <20211018132329.453964125@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 @@ -3173,10 +3173,13 @@ static void xhci_endpoint_reset(struct u return; /* 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)) @@ -3262,8 +3265,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,