Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp151078pxu; Thu, 10 Dec 2020 21:47:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGSbkXyCcaJC7reNK1Kre4R9RC7cwRYkMfyGelebISd1k5dRM6+C6D7lH3o+lxOvikFEuJ X-Received: by 2002:a17:906:ae14:: with SMTP id le20mr9706940ejb.451.1607665650776; Thu, 10 Dec 2020 21:47:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607665650; cv=none; d=google.com; s=arc-20160816; b=qOiO/LRkJYWqEE6zpeEsqc7hhBoU405MI1q2Lx7D1w/ndpsfmqVyDk1gigUoL0BJmW oI1Kht7KiXRUtKEQ3FX+nM5tO8BJD9vZFjjXIsDPzlc0c5ODGyBOwYtqF2BFlrvOdQKA PDvyk7KggWgxJZFI/5sePsjMMtB6xKB4CYGgblQJOl0zwaIhJWJo9Fqol5sM5cHkfahD oFP/3SNTqHUzQBGN9QIuqsSMSyi2bb/XNKzne++zbIq+VmwS6ib4g1P6z64tEcZCXUZs +bOLzaFZYinQdpqd3dAwRk+rj8D7GrmDf/RcE/L2Xe+NVUi7NL7/g/ZNn9p2hIsCv+la UfsQ== 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=U/S97deDvktT/Ut0dWA+9AHMlvW3NEHDf8LzBtS1X0OfD1SYBsIR6VIQTmam7aD4Ex 2PsGbpUwbEd++h65/bUC+h0IgKPEzkhjCITQPt5LQq3PnTBZ9zvjqDQaftU5cNydtTo1 WW/x2liWVz19iFiAfkKhbIrIcp78f3iZ9RhGFX0APYagvx/2s8mc54RKXoTZUlOcq8xY h1JWxUE+Zjxl9M4eO+IUfohQ0EKhIox2//5el+/h1UMJ+EUOUWDoVabq+tZfCGw6J7Bg tBIHS860AVvLI8QetxVr1yUEWIeTs8F2ogTx8J3tFYMK75fg8nbV0ZTMmHjKICZ/RvKs 7qlQ== 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 x13si3818037ejo.619.2020.12.10.21.46.29; Thu, 10 Dec 2020 21:47:30 -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 S2390529AbgLJOb7 (ORCPT + 99 others); Thu, 10 Dec 2020 09:31:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:38582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390291AbgLJOag (ORCPT ); Thu, 10 Dec 2020 09:30:36 -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.9 39/45] spi: bcm2835: Fix use-after-free on unbind Date: Thu, 10 Dec 2020 15:26:53 +0100 Message-Id: <20201210142604.275692434@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142602.361598591@linuxfoundation.org> References: <20201210142602.361598591@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; }