Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3323308rwa; Tue, 23 Aug 2022 02:50:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR48UM0HY1nhe6i4pakWWGhMnwaZCzeI3i0fGqYKzmKscy6CFcgG5FeeUSI/T/lRGZ4hAGp1 X-Received: by 2002:a17:90b:17c2:b0:1fb:707e:8ffb with SMTP id me2-20020a17090b17c200b001fb707e8ffbmr482559pjb.71.1661248228345; Tue, 23 Aug 2022 02:50:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248228; cv=none; d=google.com; s=arc-20160816; b=zv0VD3YqnLt7D+1VOm/7tdIrgW6wnNLF8NcFMtoc5xDFVwyvGwL1MY7hPgeB3WQgRL aTfpNrnOfNrNjoAH2mv1EfjrIZMkYT5GTG8O5cK/J1I4ZQQDR6qwqXn6ta/QDAtJPw/D miBSTjvoxFbOU1psyMSMHsBjVcbA7Z7fCO6GDwQukgeWtRGy45kznRVElFoMj8HIOuu4 BJ7bPRTutbRZlA+q9bYRkLOtBkOk5jjKyyFkse2AfpJ7/B6b9JyZHrx+9YNXA+bNVFBU pnPojCPBhgiPM6fa+mW7A4n94o4LD8YQgRK91NYbyLpSk+NnQJfIZJ6FlPbceDKChOal Qpag== 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=/RzV5BTNnbNYMlOaH0bq3bTngAKxSUYDRihZUFiQYsM=; b=MLHoFXz70P4nFClPtdZkSRgzkl/8fhu+/F4GEYebAKhFKkYMKFuhGoEgUBapeFDfSy w62ReaSJBckgcFH1vmDnybfYZpABXHPM0W5vaGvWuVh7D3UE+EXXOoVAaeYSSctVuaNS 7zAPiH/delhMCxv4Xk4DsrVXITODrDQLrBm07wkHB+xEOFMSY1dZg9zF9/LUH/XiZSRp 1xf8XWX7vpoh8LwvM48svwKwGG2lCi96z+mH/cuG0apWwPBrSmOsaxrQrjZRfIoU/b8O i+PKg/1LX89iETnAV9zJ4rVWQ4eM1/TlkoUYdutLA2rU7XwMZp2W5sV+oMCHAlnsPUxu sK2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NIU1UaD5; 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 s35-20020a634523000000b004161e72a055si9941406pga.310.2022.08.23.02.50.17; Tue, 23 Aug 2022 02:50:28 -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=NIU1UaD5; 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 S1349136AbiHWJRl (ORCPT + 99 others); Tue, 23 Aug 2022 05:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349256AbiHWJO7 (ORCPT ); Tue, 23 Aug 2022 05:14:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F27E6CD30; Tue, 23 Aug 2022 01:32:07 -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 DC010B81C48; Tue, 23 Aug 2022 08:32:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 406BEC433C1; Tue, 23 Aug 2022 08:32:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243524; bh=p8YLk0fXbdEGd5ts6snZ/bCE06HJyPgd8xx/jdf47A4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NIU1UaD5miu96wYN/E6OkhN22hmh3Lc7+0vHVXQOgEhzCU3kB7xtr3pSPT2fSONmg roKTaK0J8mCW0KpQkWafniwGBYEzqi9NniqcHtM28kiil/CfkEdwNh6mBDHrJnzf85 Fi5M6jZ2Yhihc7QFaxaGUWlsiVvLyk5k5FHBHihg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Frank Li , Faqiang Zhu , Sasha Levin Subject: [PATCH 5.19 264/365] usb: cdns3 fix use-after-free at workaround 2 Date: Tue, 23 Aug 2022 10:02:45 +0200 Message-Id: <20220823080129.222428320@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@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: 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 87cfa91a758d..d21b69997e75 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