Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3017419rwb; Mon, 15 Aug 2022 16:14:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR4XkxYE7kv5VY8HMqv0R6CGl7oiXwtBBEb7WMi4v9Fqce6iDeG9jPT0IpagC26bVOtN/eyb X-Received: by 2002:a05:6402:194e:b0:442:c81c:ca25 with SMTP id f14-20020a056402194e00b00442c81cca25mr16881116edz.137.1660605243189; Mon, 15 Aug 2022 16:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605243; cv=none; d=google.com; s=arc-20160816; b=ptS1OQd2heTpiaQ/DTH40Z5x/zrIDTgvB9D+2sqpp+D+c718L7kI0WF89zA+/5oMFw IBPrbjlhxowutRcQu/WuCnpKG27RxF9PrY5WP+CW+QsXNHFjIgnZFuBq8r59cvfmEMbF pcQfdMS9ARkDKdBUqXUw5k/TC2EBY/u9heo4DMQE/2x5xgzoqzKVLY7T44lj7D0IzhVY cIAU8wHA6ygBKvK3t5qmalKrk97WUf1T0oOAbiTo7MqBHX+ct1tXhCJLykktF5aS9h3v vbLJYl7wRI7t2AX9tCzSGK5S2pAMaBRdtbmBA8CVeMwfM/t7Uwk3Cnrqg2jCGm2wcuuD Sipg== 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=mVZNZsU+GZAnZEiqAW7tKm1kflKBu/CfmP0nlkmEeuw=; b=A+Xfkg+k3Ptb2NjrEU++7KRJtfuBQjbRQ9M1V1DoHV54b6b8B6bfE9y7eJpTZz64UJ 9UeGw7daEeNQkhGtBFLNKWKTzkC90/0tJqATCPRVs+ydpZyvk+1lV0SoGfZJaHPpIUbC ObZjs88QFganLZ6h8AZTYHBkA85OQRMsXvjAD0zh+WmaROlrJVTjcB8LjBG0bfNsSaZx FMAqYZLZ4jDlDKRCaxyqjVYGNzcHgkM/JeDCvY965baFg/4P21CHWsk0wlkNB3vv8ymS sLAyURrVQP0YtmKZaLZNwiAm4J/k1JRJrlrGbBXOjStVeEgQxLiuymyjdowcNsJxPSET O5iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PhUu8cL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a056402428e00b00443ccd1dd45si2647718edc.189.2022.08.15.16.13.37; Mon, 15 Aug 2022 16:14:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PhUu8cL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1348743AbiHOWYv (ORCPT + 99 others); Mon, 15 Aug 2022 18:24:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350803AbiHOWSg (ORCPT ); Mon, 15 Aug 2022 18:18:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F3D565658; Mon, 15 Aug 2022 12:42:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2BCF5B80EA9; Mon, 15 Aug 2022 19:42:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DF55C433D6; Mon, 15 Aug 2022 19:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592523; bh=USaoXt23dkPCUkqdy9sXfYf2lS1Nk6uh96T3TB7tnc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PhUu8cL8MxSm/1fbx8Paz5FyYwYK5XXB8vwouMiPbZc6mmto8E+qzs3AqnlVDuBzM H/9Zng8lDJhV4RVqaHufuBpV4rOhi1YXfVoZGdSbIvg9/dcfRBGgOmSXwZhAfGVXY4 MO66A/Us22DMQFdvShOQeeAwfmq/39fmLmfzW7VE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Chen , Andrey Strachuk , Sasha Levin Subject: [PATCH 5.18 0794/1095] usb: cdns3: change place of priv_ep assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable() Date: Mon, 15 Aug 2022 20:03:13 +0200 Message-Id: <20220815180502.091601971@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Strachuk [ Upstream commit c3ffc9c4ca44bfe9562166793d133e1fb0630ea6 ] If 'ep' is NULL, result of ep_to_cdns3_ep(ep) is invalid pointer and its dereference with priv_ep->cdns3_dev may cause panic. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver") Acked-by: Peter Chen Signed-off-by: Andrey Strachuk Link: https://lore.kernel.org/r/20220718160052.4188-1-strochuk@ispras.ru Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/cdns3/cdns3-gadget.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c index d6d515d598dc..e0cf62e65075 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -2281,14 +2281,15 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, int val; priv_ep = ep_to_cdns3_ep(ep); - priv_dev = priv_ep->cdns3_dev; - comp_desc = priv_ep->endpoint.comp_desc; if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); return -EINVAL; } + comp_desc = priv_ep->endpoint.comp_desc; + priv_dev = priv_ep->cdns3_dev; + if (!desc->wMaxPacketSize) { dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n"); return -EINVAL; @@ -2596,7 +2597,7 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request) { struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct cdns3_device *priv_dev; struct usb_request *req, *req_temp; struct cdns3_request *priv_req; struct cdns3_trb *link_trb; @@ -2607,6 +2608,8 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep, if (!ep || !request || !ep->desc) return -EINVAL; + priv_dev = priv_ep->cdns3_dev; + spin_lock_irqsave(&priv_dev->lock, flags); priv_req = to_cdns3_request(request); -- 2.35.1