Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp408582pxu; Tue, 1 Dec 2020 14:31:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDMufesTSK6b8vMzKSg7nUKkHV87A2v6efnW/kiG4yuBaZ6HEnX0doJ6syEP29L/TBCpBd X-Received: by 2002:a17:906:af83:: with SMTP id mj3mr5048223ejb.243.1606861911260; Tue, 01 Dec 2020 14:31:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861911; cv=none; d=google.com; s=arc-20160816; b=enDXfk1SiHicWE7QRq3rab4kmo5dPuztI4htRhpB/LROt3bNuzgATYpphhDlANgTk+ HUEdshWoposa3A0yM8CTlPxliQZlUbScVFuXeZURYQj8jfYm0tYlcUrQEztXZtWmy2Sp 5ZlRVz9GYDTLFvpZqU5Gj8sggDimaEJVfyZCH+m1dkylF+mj+jVuEwF5jtVBZwSHxZJQ Kfj1ynreMwYS3bHO25ljaTsDGE51PegVCBBHMl+aL0VFQJ87TSGdgj1CzTVe4eLOS9SX I6ZvwTdS5NsSPVgexNiHlcnr92rn9byOV9gU4nCAzxgP6NTsdQ4GT/sUW64slrUOm3MV nZNA== 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=v/OIlzFlDQMwmxPaKxPUAj3MragpUhJzh9PAOo6SFGI=; b=CTg0eJaUSl+gQslW+x11Kkx6MD2anrz4IlXLEOacCr3GwsVqqaPB5UPb/14kA2YBD+ tQKtLimP0dab6C1MigYyNr5imLlkHT20PIcqYI8rMHYv7F9SWH3SL4i8tZ+3KyOLO+fs gdB3bTsfv2sjehtOmSRTPDmvtrKjfAw0y0bdzvyTatKLmN0eEK8D675zP7sr4YuSb38A nBhq29ugJbCBADtyKA65HjGklvrrvDYUgPCGFLl8MakxSQJtNzMnhy8xs8FEoduzL3sF 5mIKUfrvoAbnuioI3m5a6KRtLI2/gI+yewYfmwwRoXESpsDVNlWHs+zQbtKbyqXwrtKs FSIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GOIRL6xX; 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 m7si935503edq.549.2020.12.01.14.31.29; Tue, 01 Dec 2020 14:31:51 -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=GOIRL6xX; 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 S2389566AbgLAJ0l (ORCPT + 99 others); Tue, 1 Dec 2020 04:26:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:40062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388098AbgLAJDP (ORCPT ); Tue, 1 Dec 2020 04:03:15 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2484D206C1; Tue, 1 Dec 2020 09:02:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813379; bh=loT/Ftnw+9TANSZmYMtxoJ81ooNxguCrSRrMJSr7LhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GOIRL6xXla3A/2Txra3zZkSSdqxRVABe6ogvoGcI/dDyMlRtPr5bGf4DJ9vQcZEdT nzYyXsukm66xYcCOK10GfBrm/w9UvTuKt9DHQAbrljAXp6wXxQVxhEX4YiSFOLIFhd 2ozeuyjlWZmQmXBrxOeYWgbqd2lIxJ2XpRkvLJIU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sascha Hauer , Florian Fainelli , Lukas Wunner , Vladimir Oltean , Mark Brown , Sudip Mukherjee Subject: [PATCH 5.4 02/98] spi: bcm2835: Fix use-after-free on unbind Date: Tue, 1 Dec 2020 09:52:39 +0100 Message-Id: <20201201084653.067476286@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084652.827177826@linuxfoundation.org> References: <20201201084652.827177826@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 e1483ac030fb4c57734289742f1c1d38dca61e22 upstream 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+: 123456789abc: 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 [sudip: dev_err_probe() not yet available] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-bcm2835.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -1264,7 +1264,7 @@ static int bcm2835_spi_probe(struct plat struct bcm2835_spi *bs; int err; - ctlr = spi_alloc_master(&pdev->dev, ALIGN(sizeof(*bs), + ctlr = devm_spi_alloc_master(&pdev->dev, ALIGN(sizeof(*bs), dma_get_cache_alignment())); if (!ctlr) return -ENOMEM; @@ -1284,23 +1284,19 @@ static int bcm2835_spi_probe(struct plat bs = spi_controller_get_devdata(ctlr); bs->regs = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(bs->regs)) { - err = PTR_ERR(bs->regs); - goto out_controller_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_controller_put; + return err; } bs->irq = platform_get_irq(pdev, 0); - if (bs->irq <= 0) { - err = bs->irq ? bs->irq : -ENODEV; - goto out_controller_put; - } + if (bs->irq <= 0) + return bs->irq ? bs->irq : -ENODEV; clk_prepare_enable(bs->clk); @@ -1330,8 +1326,6 @@ static int bcm2835_spi_probe(struct plat out_clk_disable: clk_disable_unprepare(bs->clk); -out_controller_put: - spi_controller_put(ctlr); return err; }