Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2813501rwb; Mon, 15 Aug 2022 11:52:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR7jtw5LHjwdzIF6KyGWvZ3Edum+yiCVqMot8Ca17nYQeYBd2q0ASK5JKyvuINN4v7gr4UxB X-Received: by 2002:a17:906:ee8e:b0:730:3646:d178 with SMTP id wt14-20020a170906ee8e00b007303646d178mr11285714ejb.426.1660589545237; Mon, 15 Aug 2022 11:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660589545; cv=none; d=google.com; s=arc-20160816; b=UvmXHLbvaCGUDzXiEIC8Y/usZpNMIfjEUTporL/Oq2Rba7EGd5AO/m6nkB7laEkN1a eKWii//GwDnMeGvRC+b9F+ZKQsp259vI9XDDi4V3MGGLbE5fJAhhTk50BZY5Vbcs71QN hremPFY96EQ5KpdDomXasroj817JZJW/Rq3MJpZVdnZxpQPOxB9vz0YY6uE3oC2Z/0SF B3lQ31bu0I4t5m8mGiq/m6LEIwielFNxwhuG3x1ylUWuTRvEuegOAnpAl4tmqStblcaF ZQDy6/SHuIQFCMRtrVfmEJI/oPeifKzR8b6fGC7a7F4eB3JgikfKq+a311OoD4UvHDs9 /YQw== 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=bXjKzTLfOUugixzhsjsVgjm3pYnxhLfIyvazTT94mak=; b=QxToU0u9omnxfN+a27Z08FCM+hlSttOCzsxszM/VeYTSdmFfsp9WLuyHX4wjo+xsR1 JEVM1XDsectJEK1K0M9mtWoShwwP4Y2Ax58C0hpFVFsyrdIE4MPWOgzKk6a/fSVxF6HH A56T2mdfkH1da41vKZgcZq/CI/cYhJv2kte0hUCS8V0vKsrvSU2rD7aMUndxX1wTq+zs 6Fr6cr064VcaeCR5xA7Z9gMVs6DBKMof/5cBtOUcQR+A4pCeB2IP28YrOThccn1g+bPu fyK7CmImyC20ktRiFQB9Pw9sF7eRr24JU/+BOdgpPOuqRtBIDH+LLNfovUOq4TY8ldN6 Znlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FWyf6+E1; 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 qw40-20020a1709066a2800b00733126dd33dsi8939470ejc.643.2022.08.15.11.51.58; Mon, 15 Aug 2022 11:52:25 -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=FWyf6+E1; 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 S242290AbiHOSka (ORCPT + 99 others); Mon, 15 Aug 2022 14:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242853AbiHOSj3 (ORCPT ); Mon, 15 Aug 2022 14:39:29 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CAFE2E9DA; Mon, 15 Aug 2022 11:24:00 -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 sin.source.kernel.org (Postfix) with ESMTPS id 7927DCE125D; Mon, 15 Aug 2022 18:23:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59E83C433D6; Mon, 15 Aug 2022 18:23:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660587836; bh=aYfBpaDeef5Znhw5Y3gET+gcNL4/+NCrvZDXnC7zbfs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FWyf6+E1YidnHic1n8UjkaiIiMXPqt/2/X4iyhwLCjb0G2y+vgil2LRcqv7CCXDF7 hYjiiih/kOJxUT9ot+MUqj00mqzjfPj64pu6qAPVaDvErm7HCxYlox/2RI9r/6a0G+ YLsHtkdIZH7wOFHj36HEZMNTn4ve37/8SfJM9PdU= 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.15 210/779] spi: tegra20-slink: fix UAF in tegra_slink_remove() Date: Mon, 15 Aug 2022 19:57:34 +0200 Message-Id: <20220815180346.251985427@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 3b44ca455049..cf61bf302a05 100644 --- a/drivers/spi/spi-tegra20-slink.c +++ b/drivers/spi/spi-tegra20-slink.c @@ -1130,7 +1130,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); @@ -1145,6 +1145,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