Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2697696pxj; Mon, 31 May 2021 08:30:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT/WJk/NHWZ/Ql4vO7+nQ1zWca6stdsEiiye/7iUx4Suwe6u/j63chzKcKDadJwkmRNOTK X-Received: by 2002:a17:906:71d2:: with SMTP id i18mr4090078ejk.373.1622475041389; Mon, 31 May 2021 08:30:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475041; cv=none; d=google.com; s=arc-20160816; b=r7KTyijm5s4xPzfddM0Nvm3N3YCfMBBY3R3jhiibdtYRqnHwSX+vpnLcVv/bVNWjoJ K0K+gndXGpHkE4cuxyWLm+b+aKrXNzI2oNEW7021xyJgDNmggao5YS9JSgkt9chgUxlE qbREY3au3d8uX1v3+uptafUyEL5sufPHFaOaIX+Q1eVidIHqW8n1btF+NsCArLc1lFUl 8kVlftEi8qSiFhWY2Zp7e23kd83CpYkuiJQbvqzcOv1NWAnl54Ec9Dis/BTmpbBpdqa3 JenSSCpHR72801qnDoRW/pCFP5nLyDJ0mkWY2pfqGty4f279r3EU0HdFfi3eBj/i9/bA nw0w== 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=A6WY6EQScvTYUYpHGd1V/RbGNMf8NGCPF5OSK7TlGOM=; b=dpa4sf5rA3KvTnclV/zwKBLyRidouAGrDnZKpKlwGEhIm0pex8vpcdfW7RRk269aFB AvCNC3jyqRb2Cec3M9ndCb+Tp2IjYZRXxUJmpcMjU+MMegXsF2DrWF7SsifUw2j/MIOd KWleEROjqtKF1213Jge6yxwpgq178Pxwdjh6EmA0AZFzHvSQbCWIFHTR4Kw/GlTerKqs 3xo7fKWTYUuUyAfbDj3/lZjtuV/PdbAhtKYMyaaUNvmNpY3EG7jYO9xfLy/NXD6Lg8gY N6zYkhfPAXCcfppl318EY7euQWRoI1VXBKakQnsrLmZ0o8p+h3ecHwQqX06QJyXaTzjs njqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M16pAr8K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx5si13244129edb.473.2021.05.31.08.30.18; Mon, 31 May 2021 08:30:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M16pAr8K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233940AbhEaPaf (ORCPT + 99 others); Mon, 31 May 2021 11:30:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:43308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233033AbhEaORl (ORCPT ); Mon, 31 May 2021 10:17:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 13363619AF; Mon, 31 May 2021 13:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468626; bh=Tw1m8lGwCOODsUpAjhAhIZd9AtVXP8hkFAvRZXBJgo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M16pAr8KmSRnDQCZAq6NvoZ0JQmFbPBpHANHg0bwQVS1i4mYIdS9NnDx6NQjNy1t6 XOBBx5suwYOPaDR4YM1mIVyBzDSz6hEEueleinZHIUraW1BOo/RPLm4yMUdQ1Wrwme +Y98PvblLQVnGR8cYD1CM29up/POU3MJIDUOr8/0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Rajendra Nayak , Girish Mahadevan , Mark Brown Subject: [PATCH 5.4 064/177] spi: spi-geni-qcom: Fix use-after-free on unbind Date: Mon, 31 May 2021 15:13:41 +0200 Message-Id: <20210531130650.118413088@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner commit 8f96c434dfbc85ffa755d6634c8c1cb2233fcf24 upstream. spi_geni_remove() accesses the driver's private data after calling spi_unregister_master() even though that function releases the last reference on the spi_master and thereby frees the private data. Moreover, since commit 1a9e489e6128 ("spi: spi-geni-qcom: Use OPP API to set clk/perf state"), spi_geni_probe() leaks the spi_master allocation if the calls to dev_pm_opp_set_clkname() or dev_pm_opp_of_add_table() fail. Fix by switching over to the new devm_spi_alloc_master() helper which keeps the private data accessible until the driver has unbound and also avoids the spi_master leak on probe. Fixes: 561de45f72bd ("spi: spi-geni-qcom: Add SPI driver support for GENI based QUP") Signed-off-by: Lukas Wunner Cc: # v4.20+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v4.20+ Cc: Rajendra Nayak Cc: Girish Mahadevan Link: https://lore.kernel.org/r/dfa1d8c41b8acdfad87ec8654cd124e6e3cb3f31.1607286887.git.lukas@wunner.de Signed-off-by: Mark Brown [lukas: backport to v5.4.123] Signed-off-by: Lukas Wunner Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-geni-qcom.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/drivers/spi/spi-geni-qcom.c +++ b/drivers/spi/spi-geni-qcom.c @@ -552,7 +552,7 @@ static int spi_geni_probe(struct platfor return PTR_ERR(clk); } - spi = spi_alloc_master(&pdev->dev, sizeof(*mas)); + spi = devm_spi_alloc_master(&pdev->dev, sizeof(*mas)); if (!spi) return -ENOMEM; @@ -599,7 +599,6 @@ spi_geni_probe_free_irq: free_irq(mas->irq, spi); spi_geni_probe_runtime_disable: pm_runtime_disable(&pdev->dev); - spi_master_put(spi); return ret; }