From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDA9813B2B4; Tue, 27 Feb 2024 14:24:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709043852; cv=none; b=V31lI8a5Ox0nbZTDrFq1+iGRfh3ipeF0y3xww/AdgdyYPb1nKfj9HvVNcC0Kc/uJCXpXDsy8ncjVAGmnT0tYU6sNRRWz8Edq0TLhdFMgzKke+9SgiaVi0AEvB18NJH475fA9RaZWwBk1LTM2b4xv3pntyfEg/FFANULcmBNzSqA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709043852; c=relaxed/simple; bh=PKjYFojhrMNMd5sxK0GgJSvN1pB6lCctC0BnVOwvCpU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SV6AaBYUCTS1XApTB7v4DePMTgiTHCZoa80OwRZZMo0P6Bu6Ot/7RWnhW7/6Re6kuJjZPTav5K6XCrZFruCpgj+8Jc5QLABmnqD53IUbUPHXqkBqGrU8sv0UzSwS9P6IdJyZZigcs6WBeVUxgHm4EmjSrlMjje9X/MY63NFyILo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=THkuP3bL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="THkuP3bL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D0DBC43390; Tue, 27 Feb 2024 14:24:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709043851; bh=PKjYFojhrMNMd5sxK0GgJSvN1pB6lCctC0BnVOwvCpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THkuP3bL8B10BvUAyxTtXsRMzPkZiYNoxWm6ZgJYP4uaYrO3qmCXb0IftjjJboDHI d5WvHT8A1y9pF5TjVuwAYwglnk1CI8laIkV5hc4rKkzPW2cC+0TapLrvhjkdnWgCgB WEvP95jnFDJSuG3rVYbCk2BpKgwN/7J/Vj5+dNHI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Frank Li , Roger Quadros , Peter Chen Subject: [PATCH 5.4 59/84] usb: cdns3: fixed memory use after free at cdns3_gadget_ep_disable() Date: Tue, 27 Feb 2024 14:27:26 +0100 Message-ID: <20240227131554.792748345@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227131552.864701583@linuxfoundation.org> References: <20240227131552.864701583@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Frank Li commit cd45f99034b0c8c9cb346dd0d6407a95ca3d36f6 upstream. ... cdns3_gadget_ep_free_request(&priv_ep->endpoint, &priv_req->request); list_del_init(&priv_req->list); ... 'priv_req' actually free at cdns3_gadget_ep_free_request(). But list_del_init() use priv_req->list after it. [ 1542.642868][ T534] BUG: KFENCE: use-after-free read in __list_del_entry_valid+0x10/0xd4 [ 1542.642868][ T534] [ 1542.653162][ T534] Use-after-free read at 0x000000009ed0ba99 (in kfence-#3): [ 1542.660311][ T534] __list_del_entry_valid+0x10/0xd4 [ 1542.665375][ T534] cdns3_gadget_ep_disable+0x1f8/0x388 [cdns3] [ 1542.671571][ T534] usb_ep_disable+0x44/0xe4 [ 1542.675948][ T534] ffs_func_eps_disable+0x64/0xc8 [ 1542.680839][ T534] ffs_func_set_alt+0x74/0x368 [ 1542.685478][ T534] ffs_func_disable+0x18/0x28 Move list_del_init() before cdns3_gadget_ep_free_request() to resolve this problem. Cc: stable@vger.kernel.org Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver") Signed-off-by: Frank Li Reviewed-by: Roger Quadros Acked-by: Peter Chen Link: https://lore.kernel.org/r/20240202154217.661867-1-Frank.Li@nxp.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/cdns3/gadget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -1951,11 +1951,11 @@ static int cdns3_gadget_ep_disable(struc while (!list_empty(&priv_ep->wa2_descmiss_req_list)) { priv_req = cdns3_next_priv_request(&priv_ep->wa2_descmiss_req_list); + list_del_init(&priv_req->list); kfree(priv_req->request.buf); cdns3_gadget_ep_free_request(&priv_ep->endpoint, &priv_req->request); - list_del_init(&priv_req->list); --priv_ep->wa2_counter; }