Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1645328rwb; Sun, 14 Aug 2022 08:37:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR5u57FFwJU5eNWmhRSewkAQZQhA3LYu5iPB1n4q4ov9oJH3eotRTMRMPctRpOcuWY8ggXvc X-Received: by 2002:a17:906:cc15:b0:731:6cc2:7a85 with SMTP id ml21-20020a170906cc1500b007316cc27a85mr7925342ejb.512.1660491454127; Sun, 14 Aug 2022 08:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660491454; cv=none; d=google.com; s=arc-20160816; b=oXqzHl0MX2e98Z7SBVbQDHtjKf9wBSGZes6iQKC1v3oLdkWj5mFsxzlvZKSPdtZMV6 07MOMvCgEYtJb22aBzbd9puobjx9m6Pf6xBo1uB9gkGucOziKKQ5XY1x3mYNFiltw7Zj VsiogR7Y0YphHhn5ZUQuNF8fF78ZRMYYGEOp892f+ZKb0tVVG0rsLLSxcG5cRQFSR8t7 sZsYay6EK9g3cUF70vGRwZVFwcX/lQqhqlphY84ZYRKaxM2J0dY7NKiFesU8YPgKjVOV T9eJyM+i73T91iQFs4diNzJH7RfIP/nkzCQmwYOAr65wGo3V2jZznZwzigiQPJmBscXM jdgQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v7jvlQWZBwA4j5R+q8Dto01GF1ZxkRq5wTjaD9Vvx5E=; b=pGVV332ACeVTbPmU+PCRFuKKZ7jN6A1nelpvXclQNILpcu+vLp5404+UyUmzpuquD5 3x8qPRtqcbJVPNFDUkLH/JP1uI30wufc6EDjldJtoTb6hEUV6i9CdRetR9tub6aRomZB GAZY1DBDw1swBHar8O45MYgZ+aaDcWCIJTtUDIPj3+Zx2tlpK+B474tuac2/TFJvDCS6 yrFqLNetUedPy3/Ch2UVnGxGCs4pi7xml5ljQTmT4cFnZm2UVIzRs8UDYLwn120hkRdl N5jrKTNP5MvZMeUZnqGjScCOuZe8IKVEWfzjWUg796jCbmmjGNBKiHaR2qxs/TIvOxtS V0Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CLuwqcaA; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i36-20020a0564020f2400b0044398d621f1si1534153eda.424.2022.08.14.08.37.07; Sun, 14 Aug 2022 08:37:34 -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=@kernel.org header.s=k20201202 header.b=CLuwqcaA; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235437AbiHNP1a (ORCPT + 99 others); Sun, 14 Aug 2022 11:27:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231348AbiHNP12 (ORCPT ); Sun, 14 Aug 2022 11:27:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A152A47E; Sun, 14 Aug 2022 08:27:28 -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 dfw.source.kernel.org (Postfix) with ESMTPS id CABFD60C11; Sun, 14 Aug 2022 15:27:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D5DCC433D6; Sun, 14 Aug 2022 15:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660490847; bh=X9sRqLYKUy0Gntp+6nbq3BmEZ36eBVNhzdKaXzyPWZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CLuwqcaA0os0iyzs8V+fiU76v+cKHdKjBjsF+s5IbmbtovG7dbldiCifWMu21Iyf8 R8o2G8exGgu1MeIN3ECSvOXtjQfCIIr0sUuvQXoKzQnz7kSVhOz74hKi9QDFNB4Wx0 AUQigWEueoffb23dqLn7QwO8qk4jNIgOCILabX8RIlyYmkmG/zHOQvVTScZmZTg+UR NibR9dHS74WZa54j0kxYwkfJnwF/s9LTBQ8gaSQe4sQzINJrsUGZQ7q4s2OoKxcZuG wv0C6Cw412sdtY93XGV7dCxFnkNrUfmbiXhcjrq6w/lQwxUZf9hDmAGGzXb+L/HmYS 7+Gi0+QKLwJRw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Frank Li , Faqiang Zhu , Greg Kroah-Hartman , Sasha Levin , peter.chen@kernel.org, pawell@cadence.com, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 5.19 08/64] usb: cdns3 fix use-after-free at workaround 2 Date: Sun, 14 Aug 2022 11:23:41 -0400 Message-Id: <20220814152437.2374207-8-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220814152437.2374207-1-sashal@kernel.org> References: <20220814152437.2374207-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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: Frank Li [ Upstream commit 7d602f30149a117eea260208b1661bc404c21dfd ] BUG: KFENCE: use-after-free read in __list_del_entry_valid+0x10/0xac cdns3_wa2_remove_old_request() { ... kfree(priv_req->request.buf); cdns3_gadget_ep_free_request(&priv_ep->endpoint, &priv_req->request); list_del_init(&priv_req->list); ^^^ use after free ... } cdns3_gadget_ep_free_request() free the space pointed by priv_req, but priv_req is used in the following list_del_init(). This patch move list_del_init() before cdns3_gadget_ep_free_request(). Signed-off-by: Frank Li Signed-off-by: Faqiang Zhu Link: https://lore.kernel.org/r/20220608190430.2814358-1-Frank.Li@nxp.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/cdns3/cdns3-gadget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c index 5c15c48952a6..29662c8ac024 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -625,9 +625,9 @@ static void cdns3_wa2_remove_old_request(struct cdns3_endpoint *priv_ep) trace_cdns3_wa2(priv_ep, "removes eldest request"); kfree(priv_req->request.buf); + list_del_init(&priv_req->list); cdns3_gadget_ep_free_request(&priv_ep->endpoint, &priv_req->request); - list_del_init(&priv_req->list); --priv_ep->wa2_counter; if (!chain) -- 2.35.1