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 23F5D481B3; Mon, 14 Oct 2024 15:31:29 +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=1728919889; cv=none; b=AuU9Jsor8ISVtiRrcPySSaOuh82V6RLOqrytxfWOi8BtGyGLm211Qs8f2IIra17ImCnhnq5rlyzcwd2Qhgb0ZI2LReHL2D8C7m3Wyra8/tP8cVa9pC8yF5nlPEQMdL4uTKzoxnmMrz1S1MSbRwndYto8I9Qe8oXsro4BihlT4JM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728919889; c=relaxed/simple; bh=cqzVAKRfOP8Fsto1QUE/rGzV789jrEYbPsygkvgbvkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vEl4gbUZhFLWXm9YjlEMCtVzSw9aDjpsMGsbpRyl9TuxRTx9b5H4UdsrMX7fSosywMBYPKEC9wXHIyhfmwlSUBstnmkHYWoGXXxafbYODroutuBgPt579IvQ3NY/CslyXrKngyhds2CfS9IpufLDOh8XnYa7lzyJavnu3ud5PaI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2T9y64tI; 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="2T9y64tI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9690FC4CEC7; Mon, 14 Oct 2024 15:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728919889; bh=cqzVAKRfOP8Fsto1QUE/rGzV789jrEYbPsygkvgbvkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2T9y64tIrKRiEzYkcArL+CQPMZFP37B0GZyP4o5Zozbk7ekNxZVV9HomlgLlBkdVL TTuHWtWcJWdDNKHkkPrzUi+ctf6I+brS82q1pGNjRgnoFCYOOSfO6W7WzELa1Hv1m7 UKYHo0a5SH8B+Pzjpy1S7ce0zTGwD36Kwg6xuV4A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kaixin Wang , Logan Gunthorpe , Jon Mason , Sasha Levin Subject: [PATCH 6.1 705/798] ntb: ntb_hw_switchtec: Fix use after free vulnerability in switchtec_ntb_remove due to race condition Date: Mon, 14 Oct 2024 16:20:59 +0200 Message-ID: <20241014141245.765401872@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241014141217.941104064@linuxfoundation.org> References: <20241014141217.941104064@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kaixin Wang [ Upstream commit e51aded92d42784313ba16c12f4f88cc4f973bbb ] In the switchtec_ntb_add function, it can call switchtec_ntb_init_sndev function, then &sndev->check_link_status_work is bound with check_link_status_work. switchtec_ntb_link_notification may be called to start the work. If we remove the module which will call switchtec_ntb_remove to make cleanup, it will free sndev through kfree(sndev), while the work mentioned above will be used. The sequence of operations that may lead to a UAF bug is as follows: CPU0 CPU1 | check_link_status_work switchtec_ntb_remove | kfree(sndev); | | if (sndev->link_force_down) | // use sndev Fix it by ensuring that the work is canceled before proceeding with the cleanup in switchtec_ntb_remove. Signed-off-by: Kaixin Wang Reviewed-by: Logan Gunthorpe Signed-off-by: Jon Mason Signed-off-by: Sasha Levin --- drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c index 88ae18b0efa8d..7ce65a00db56b 100644 --- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c +++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c @@ -1556,6 +1556,7 @@ static void switchtec_ntb_remove(struct device *dev, switchtec_ntb_deinit_db_msg_irq(sndev); switchtec_ntb_deinit_shared_mw(sndev); switchtec_ntb_deinit_crosslink(sndev); + cancel_work_sync(&sndev->check_link_status_work); kfree(sndev); dev_info(dev, "ntb device unregistered\n"); } -- 2.43.0