Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp163311pxu; Thu, 10 Dec 2020 22:13:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGDVJpBB45qkbnfRxVMrEMtE2OIwZ6Ie3YQUC8x0pQv3arLMkcKef1ZDmiafOLpAmICqwt X-Received: by 2002:a50:ee97:: with SMTP id f23mr9858996edr.311.1607667183360; Thu, 10 Dec 2020 22:13:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607667183; cv=none; d=google.com; s=arc-20160816; b=jwQffkVoAebcjvw+Je2nG7BLX1wZ+r6xuxE+u9xDn8qvguD0J6JU10hMsRcyTzJhSv dfk9YiTnpoLwV0GC0EI8yYHt6k1DEdiIGbUMuQpw9pMUxT3n6kfQgioivyYqDGyBmFgb bFxE4DN9+4f1COKkXz10XzrYFExxbNfvmMaHHsd3g/e9cw0uz6xHGJsWHkgwgbHj4OJh oBu4o69KWSK3z6vHUTyKTrJXJueuArgzNd2sxLrPU42+damakjAQIiCKaPqLtMXFMvUU FPK1vEjJeqJIs4tChFV24QLdOR/E1IuNU+8HeBjqknLUDws6+1fvOkJAk5rjDqe7cO8j lMyg== 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=pqYaDFb+KbWCHBoKpmHYJ5ZyO7tVZWLxMxAMGrIPsfORAMKqYkRmbwgWlLm8E4ZLdy 0YfGIk2mT8w3EY5IHBvUG3uOJBMJGija8rPgRIMxjsbM3e+2do2gJLfrv7vGX7MmsdD2 ghAlnthD979kpWJUMJ3u14OCFKOxBt716mnmcxMqmbgZiDH0n6zuLqlixKHsEdIe7Vwe IjODyxtDu5YhP2tM8VGgWSXcLoiRbUSy7AqnzvE8V5EAn5ztX168bFC425f3ifi8NWT6 B47IcOLxvD12n5tuUcKn+bj2/UCbxVdJsNPEPNpYteS/tOeW8+vwwVAYTRzSEJzXako7 sg/A== 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 l20si4423958edw.0.2020.12.10.22.12.27; Thu, 10 Dec 2020 22:13:03 -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 S2391134AbgLJOiI (ORCPT + 99 others); Thu, 10 Dec 2020 09:38:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:42534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389312AbgLJOee (ORCPT ); Thu, 10 Dec 2020 09:34:34 -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.19 31/39] spi: bcm2835: Fix use-after-free on unbind Date: Thu, 10 Dec 2020 15:27:10 +0100 Message-Id: <20201210142603.814877076@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142602.272595094@linuxfoundation.org> References: <20201210142602.272595094@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; }