Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3085105rwb; Mon, 15 Aug 2022 17:45:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR7QZTHVvLtITCpWTEIpnz5XxcFwlZPFpz46ypwEWrTHFx59ELPPutEkOvnNr2wdg52Kp1Uj X-Received: by 2002:a17:907:a07b:b0:735:6744:c6be with SMTP id ia27-20020a170907a07b00b007356744c6bemr8346155ejc.685.1660610750905; Mon, 15 Aug 2022 17:45:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610750; cv=none; d=google.com; s=arc-20160816; b=PBYtb1c/oYJEFrUAQTfkXmkTcvjRkueK76zBvok2L36Zm/7X5FPQjAfDElddr3D92/ o9jV63z5eZs3FPaL5zfAfcAuk3YO5MUOxUjs7bVAyEHXCFACQ6UTUuBZT2rrCqzgrNZd aKSN9+aLoGXOcVOZ8lpJPOZCDu5K8xxFgGLeVdzdU/GjxlSNCsXCGd032pgJhqsbFX3k TZ0rQUQnhD2IXaz0Qr4M7yGjR8EkMtC/UhUgYO1TFMo6Ft9WFYA3pMtDrr0AgR++U+Kt gteeTCo1L4vel3K8P1zqo/fV2UghhuUvqsIRuQdJFf1IEVEkjBbn0PH5kZ9QFKdiIrKe U/FA== 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=CkuS5nL7H/DEDx2aoA7I+TNMIU7w56hTKW6/Ornkf0E=; b=gcj81K7b/23Kdvsrd9cafzOOmD59qJpqNEyza1nfgOyeOVSaDFOyR38+11meerW7c/ k3/9o5d9T8i/2PC4LaIXb4QpmgA3m305A+c2z5HjESyWaT2/9P4O3wwWf2W95vCtdvJ4 d1p8nMuWkd7XNEiVQEtZDFSiAnLHy5prVUcozg4bB4o5SdkD0vzgkRS/0YfuWOtB5R2F 6sMQd2Sx9KEmEao5WFRAsN9angzeLGmuyyocXYRzVKKCw0pxOxu9t7/8mk637e1SZRbJ 7b+gDi2SJBcg27k1W6/Xt4FrUZXg7dICa04jB2Es1s39uqCA0vmv4evJXmSa2LsUclMg 7bOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yrplVk32; 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 dn14-20020a17090794ce00b00730a0ca675asi7379339ejc.380.2022.08.15.17.45.25; Mon, 15 Aug 2022 17:45:50 -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=yrplVk32; 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 S1346411AbiHOXC1 (ORCPT + 99 others); Mon, 15 Aug 2022 19:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352761AbiHOXBC (ORCPT ); Mon, 15 Aug 2022 19:01:02 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FACB857D4; Mon, 15 Aug 2022 12:57:45 -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 0BDB8CE12C3; Mon, 15 Aug 2022 19:57:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFD77C433D7; Mon, 15 Aug 2022 19:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593462; bh=8RXkZKFvrd2qoUJvhKiv/H00JN0pGT/nZea2GiKVapQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yrplVk32eZl66qa3h0/nvB82/ojqns/qNJYh9muaWeYfxTtK+zmhZRkIsohaHE1R3 d14JueIWlY1sWYSuTqdVKpBa3QsRg1x/k8ifL/jicN/ycqn5VJ06DjGjQX3lmZU4vz RapsK5zPEisYQJKYPwPd/Ogu+c4DeLvI1rUFIpsA= 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.19 0271/1157] spi: tegra20-slink: fix UAF in tegra_slink_remove() Date: Mon, 15 Aug 2022 19:53:47 +0200 Message-Id: <20220815180450.455627043@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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 38360434d6e9..148043d0c2b8 100644 --- a/drivers/spi/spi-tegra20-slink.c +++ b/drivers/spi/spi-tegra20-slink.c @@ -1136,7 +1136,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); @@ -1151,6 +1151,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