Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp743959pxu; Fri, 11 Dec 2020 13:14:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4yC8/q80w9Zn7BEY+F5YLngtybFASWq+qKUbIrlbE8r2d1YO6xTtr/9JTiyNBU8YWv0A8 X-Received: by 2002:a17:906:a197:: with SMTP id s23mr12581209ejy.463.1607721280271; Fri, 11 Dec 2020 13:14:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607721280; cv=none; d=google.com; s=arc-20160816; b=avppHXG3jQ3IDEqfY3/+cXRx75rZVYXMgzwnMbMVNCEerK9O0CKDxZHZH9+J0yUWol NiUp3u6DfH8W2GWGcw0z6SnUG8PZFStGrCdXqZEvgmXo+k2qX3Cx50GxYzNCxt6Bbu+D PH89sdIno9Z28tTjKejCgW6sJsJ2/56Xeghz44nBaencc5DS9lYAmBSCH2pZnoAWaeEj SXKuwi6IWofiOcyrrm7MHPs6Qu16NcE3NeEdgMkzsmTrm98v7JQ1f0xCOT8JQC81Kt+L loWObEcv+SyZOmIQNJVHRNs1/rsIpaQGp+3HwTSaIUf1f/UcciLSrc0jTy6mHDTAkX9A XtSg== 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; bh=jb65pCqv/kZ0QqyMte65K9wXstpvqfyvwwZSC1PvglU=; b=ghT1Jt+Yt1k1NRMGt7vSJYVVCdywx4zj9dRJsb4/zqF0KmrGOVIHi5H3fVls5TTfZB 3+x3YB7XDM0f5sROuIIG7S1ZN40iIOjd9jgONHbGNxdotiKqidepfOZawp+vFBiGDzi8 iI02mrhkTZK/VwGfZfKWPUkRPHqRViegnHCabjhyciSJ/TARg0cZ59LzGVHbZw9P3rhB g0SaQA4uunkGsNIuP0mQG1F5cQSlPoZVthYlb+tngjVnAL4gpMI8G9u7GLCTkvavxBa3 hMpzGt1RvUuaHx2vIVe0xsmW3Cio6iBEnDM2xnCWhb0spwelj9TDljJ5h+osbJwaYIX1 8mqw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 gb13si5198081ejc.320.2020.12.11.13.14.16; Fri, 11 Dec 2020 13:14:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391665AbgLJStO (ORCPT + 99 others); Thu, 10 Dec 2020 13:49:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:39602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389217AbgLJOcG (ORCPT ); Thu, 10 Dec 2020 09:32:06 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sascha Hauer , Florian Fainelli , Lukas Wunner , Vladimir Oltean , Mark Brown Subject: [PATCH 4.14 25/31] spi: bcm2835: Fix use-after-free on unbind Date: Thu, 10 Dec 2020 15:27:02 +0100 Message-Id: <20201210142603.354267181@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142602.099683598@linuxfoundation.org> References: <20201210142602.099683598@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 [ Upstream commit e1483ac030fb4c57734289742f1c1d38dca61e22 ] bcm2835_spi_remove() accesses the driver's private data after calling spi_unregister_controller() even though that function releases the last reference on the spi_controller and thereby frees the private data. Fix by switching over to the new devm_spi_alloc_master() helper which keeps the private data accessible until the driver has unbound. Fixes: f8043872e796 ("spi: add driver for BCM2835") Reported-by: Sascha Hauer Reported-by: Florian Fainelli Signed-off-by: Lukas Wunner Cc: # v3.10+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v3.10+ Cc: Vladimir Oltean Tested-by: Florian Fainelli Acked-by: Florian Fainelli Link: https://lore.kernel.org/r/ad66e0a0ad96feb848814842ecf5b6a4539ef35c.1605121038.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-bcm2835.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -737,7 +737,7 @@ static int bcm2835_spi_probe(struct plat struct resource *res; int err; - master = spi_alloc_master(&pdev->dev, sizeof(*bs)); + master = devm_spi_alloc_master(&pdev->dev, sizeof(*bs)); if (!master) { dev_err(&pdev->dev, "spi_alloc_master() failed\n"); return -ENOMEM; @@ -759,23 +759,20 @@ static int bcm2835_spi_probe(struct plat res = platform_get_resource(pdev, IORESOURCE_MEM, 0); bs->regs = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(bs->regs)) { - err = PTR_ERR(bs->regs); - goto out_master_put; - } + if (IS_ERR(bs->regs)) + return PTR_ERR(bs->regs); bs->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(bs->clk)) { err = PTR_ERR(bs->clk); dev_err(&pdev->dev, "could not get clk: %d\n", err); - goto out_master_put; + return err; } bs->irq = platform_get_irq(pdev, 0); if (bs->irq <= 0) { dev_err(&pdev->dev, "could not get IRQ: %d\n", bs->irq); - err = bs->irq ? bs->irq : -ENODEV; - goto out_master_put; + return bs->irq ? bs->irq : -ENODEV; } clk_prepare_enable(bs->clk); @@ -803,8 +800,6 @@ static int bcm2835_spi_probe(struct plat out_clk_disable: clk_disable_unprepare(bs->clk); -out_master_put: - spi_master_put(master); return err; }