Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2928413rwb; Mon, 15 Aug 2022 14:14:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Z8AIsaJmcaN1EzGgTsNcL0hi0uSHCzyX1C1iURmSTdiib7pZ+NkjRdREVGdaCnAWPQCqs X-Received: by 2002:a17:90b:3a88:b0:1f5:59e0:437 with SMTP id om8-20020a17090b3a8800b001f559e00437mr30333073pjb.199.1660597957224; Mon, 15 Aug 2022 14:12:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597957; cv=none; d=google.com; s=arc-20160816; b=PkS4xS1dJxFHvbh4R4YqMyE8+LQCsHzU9Z0dBjXyPAbhrQcF//HcoUgBNhwr6E2R5n Ge+0oATZ7vRl8EQkWSh2CinJ9AED2MvR8ElLKu9XdKInpHJUFR1qBJxPNMkCbNZU6mrs /mBMjp8QpTetJksUeL5y/UyVtxbNxL5JDhmmCU5L+/Dcb7sO7B+Aix69eKxIamfGU6FO 3cZE9BzXZI/ehIG0PSRcbsgFDhOCLDLc8rDuPqKOabeb0bUxZvWWukBmMEKCOlRF/C4a JIVusmY39zUgpzsNchTbHd/c4mtfbegz2P9Qx3Cs2k9lUoTpW6P+mHI0vznyKkeT+THM hdJQ== 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=71Qfs3CnGAeyv7AP19HZU6XzrF3HI7pJplfRo0sMmq8=; b=LpyhhRFfyP7FX/AS0ObNhHR9Rxmgjbgj7dbDNV3dPfX56w1xfSL2O+l0jk6uEuq26X sHEkzGGXWfzxCuXiFrQ42K7oKHkMsS3Wd+xvaMlAD/PEWEreOb1SfRFcubffJ4sg0ikH b5RCQPjXWNEk5c1D24iAyrilR/59zPZWxQfrXp3L9tcZFlcWPUaWZ0NiRzO0g6Do2ITg MsLSF+fKlxkCr23XqhOCWuW6118ocyitBYkjcR9OvGcILc5gEgfpdlsjRph9Pwc1zqF7 5p1MyxFJbr9do2adO05W02+fZxRFrfhA6xXve0BcjARbfRAj2iZMYsV4NN8KDxNlnlKc 1KTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lhnZMuiU; 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 h13-20020a63f90d000000b0041a07672852si12606430pgi.824.2022.08.15.14.12.25; Mon, 15 Aug 2022 14:12:37 -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=lhnZMuiU; 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 S1346123AbiHOUwF (ORCPT + 99 others); Mon, 15 Aug 2022 16:52:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344794AbiHOUuH (ORCPT ); Mon, 15 Aug 2022 16:50:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF612B941D; Mon, 15 Aug 2022 12:09: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 D451860ACE; Mon, 15 Aug 2022 19:09:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE3B5C433D7; Mon, 15 Aug 2022 19:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590567; bh=/uKj4bZT2Rz2nPV+izWAzKndVaMfU7WxZb3+M0tctJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lhnZMuiURcUKhKWlhwRNlZMK/lkJQShhA9IC957u7Wb4pZaSD4T6s+pB3K8rDOocm oWreS3Mt5YgBCNty8CXJpgW/1dI6D+LuU8cjxJPA0XeH5gP0xiL/V9WzY2KFQ77hq1 NFeKjuR2aXxdqO3CCoWip/bdXWHg35mLustLui3U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yang Yingliang , Mark Brown , Sasha Levin Subject: [PATCH 5.18 0270/1095] spi: tegra20-slink: fix UAF in tegra_slink_remove() Date: Mon, 15 Aug 2022 19:54:29 +0200 Message-Id: <20220815180440.927393378@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: Yang Yingliang [ Upstream commit 7e9984d183bb1e99e766c5c2b950ff21f7f7b6c0 ] After calling spi_unregister_master(), the refcount of master will be decrease to 0, and it will be freed in spi_controller_release(), the device data also will be freed, so it will lead a UAF when using 'tspi'. To fix this, get the master before unregister and put it when finish using it. Fixes: 26c863418221 ("spi: tegra20-slink: Don't use resource-managed spi_register helper") Signed-off-by: Yang Yingliang Link: https://lore.kernel.org/r/20220713094024.1508869-1-yangyingliang@huawei.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-tegra20-slink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-tegra20-slink.c b/drivers/spi/spi-tegra20-slink.c index 80c3787deea9..c91c226be69e 100644 --- a/drivers/spi/spi-tegra20-slink.c +++ b/drivers/spi/spi-tegra20-slink.c @@ -1137,7 +1137,7 @@ static int tegra_slink_probe(struct platform_device *pdev) static int tegra_slink_remove(struct platform_device *pdev) { - struct spi_master *master = platform_get_drvdata(pdev); + struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); struct tegra_slink_data *tspi = spi_master_get_devdata(master); spi_unregister_master(master); @@ -1152,6 +1152,7 @@ static int tegra_slink_remove(struct platform_device *pdev) if (tspi->rx_dma_chan) tegra_slink_deinit_dma_param(tspi, true); + spi_master_put(master); return 0; } -- 2.35.1