Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9097430pxu; Mon, 28 Dec 2020 06:34:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGRZIziJM2vZlV7dQDbW9G3ZRrrfv3OOt5jRPHAB1Qx1S4EQJv8TiLqhBlNf45uq+Dn6b1 X-Received: by 2002:a17:906:4c85:: with SMTP id q5mr41717891eju.375.1609166073197; Mon, 28 Dec 2020 06:34:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609166073; cv=none; d=google.com; s=arc-20160816; b=vXSnfxrtZG1o0xDNgqJO2X1yI9tpSncdp8cRhby+YSz+Y/qejlNhdYrxH0b3QuUsb2 ruyLAvtoQuJRkVpakGaO/73aTBNko54xh57tElfGOH5iZ0Wp2I4cDF6VLKs6CF2GfaQF HcWL3IV+2BWFBw0SmHKhC5wcFhzYy4CI+tQb3GjhEndVqtSS1+6H0OTIEMCxkOvVBp9y ksdGSU1UHLQ/cUhxzKHNUEgT3Jrbr8MxDJKsOdp7VTrJccCDB916vuoSVvnQaY4tLno1 /mFePeELrWnyYRAntj2jThRIOIaDYAVKz2P/X1C3jIzNvvtulAEgpcpnkodJqoQ8KRAz YE3w== 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=TddME9IC0pqnN0ZLNGA39ReDps65hhdkfCt3pKlo6kk=; b=ZgkEKMLmt2MoRuMM7yFWc/Uq5hK9Zs5HPr7BfJCS/ofAS2D5T6c0J215FClssYjDRr FQLWhauLK/ERZjyetEae3uivn2zJvCOvd5Y6tKYBiogH0rMWvkblTnJchcthlcetKEPE Vt0lwN9pE/PXONURhnIo5Olbpe9TweSxHeyLHrgj2733f7lFbWyku4VHRRoPLGkLHZfT Xog/ERTVKSlWfn8S0hyawrTN2IAVqohmVJkA8M5phRiVf++Y5TKWoQXBRlTRaqobdo88 HEcu4402wI1ONjkEQJQ0WhuTgaK4WJ5fDyhmRU7xR9zMHHCXmHc6a1Ja3oZljA1CgEMF 2L1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="aIuXJv/A"; 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 j23si18515105eja.53.2020.12.28.06.34.10; Mon, 28 Dec 2020 06:34:33 -0800 (PST) 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="aIuXJv/A"; 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 S2503706AbgL1Oaf (ORCPT + 99 others); Mon, 28 Dec 2020 09:30:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:38520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503622AbgL1Oa2 (ORCPT ); Mon, 28 Dec 2020 09:30:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 01A5C2242A; Mon, 28 Dec 2020 14:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165787; bh=H687u38BdewT2k778Tn/ubWbvkUT6uOb7eSRMJA/J28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aIuXJv/A969tdMtBEvll/Jg+Bbx/qgc/VFdcWkq70S4YRQMwUoDseU+ClywSBCbmZ cUDY/CkVbtfNLft0PoUfa+xJLTc2N8kZhZVpFX/mjla80qVeSRCMtxkPFrYglDmsmx MDZdWDv7tQ4G8MVvPWBBuLMtlX9A/FBl+Iis8tQA= 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.10 655/717] spi: spi-geni-qcom: Fix use-after-free on unbind Date: Mon, 28 Dec 2020 13:50:53 +0100 Message-Id: <20201228125052.331545389@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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 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 @@ -603,7 +603,7 @@ static int spi_geni_probe(struct platfor if (IS_ERR(clk)) return PTR_ERR(clk); - spi = spi_alloc_master(dev, sizeof(*mas)); + spi = devm_spi_alloc_master(dev, sizeof(*mas)); if (!spi) return -ENOMEM; @@ -673,7 +673,6 @@ spi_geni_probe_free_irq: free_irq(mas->irq, spi); spi_geni_probe_runtime_disable: pm_runtime_disable(dev); - spi_master_put(spi); dev_pm_opp_of_remove_table(&pdev->dev); put_clkname: dev_pm_opp_put_clkname(mas->se.opp_table);