Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9186182pxu; Mon, 28 Dec 2020 08:44:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxC3Isxv3BY2y6nnr7sW4yaHw3NjHbUrCKLItqaDiJmym4nG7+pdbD/30roPu5ZAJEg0t9p X-Received: by 2002:a17:907:9705:: with SMTP id jg5mr42852228ejc.448.1609173869868; Mon, 28 Dec 2020 08:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173869; cv=none; d=google.com; s=arc-20160816; b=UR21k5neg/2U+Vsby0WH1IYBLdlKysgumA5dV56/HjTk8IXmDuLRAsIEk+4O61OWBl pCkYbMfHc3hujctZU4cxSYcn59JN7FFy/PkyOKPGmtflctCwXjc/eahrzH441ZzOhOnZ dXJ3WBM+nKffNqoqUpulxbn0421Z9v5EV3TdRoKI7dC7Wp7/Q61XyXK1f2J7dMS72fty ip1IoFSfstC2hw19J//Bu1m6g+Rv1wPNf4BRVVT9rJ9HH5aSHhN3j86MvUZQv/s3ceha R7xQpO7B/VtseAYG73G9psbqyQmDJ96/76sRnupWIHtO+1Bhvs4xm+Nl+p4B28G5BKxC VpzQ== 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=saP2xYQUKLjCzJiZkWuqwTjYJcNNvwr/hiQWCd0P9oI=; b=U5oSYngi5TwCV88V+xzaFYOJFrpixjSVc78JquiJrByGZXguejoZPaJSsTFD4u6ty7 0qjV6rAmS09KrDQvMv7R8A1Aeg2FFbheqxkJeh0fNQ1LZwz9Ig+jnwXEF5tIF4XNY15k OHoShFOwAEqCz0td/qIPtOEooaOHmAhb1l7InHbTklR6LTfRTlih3L9FvwRIb2Q17HRR S4cRjAfWcRVwfIZxZ1r3cl+Psu5aB1CTMR4Pz5iA0/jmJHvXGV2c5OTtR8P8uZwfQwdV MxZVCBtj2k44dOAbvoi/WlTu4IrvOURKf2V+UF+04SiX917ror7cwBTIM+tY9F39fDUQ q8SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DGHjnhnd; 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 rn2si18635218ejb.251.2020.12.28.08.44.06; Mon, 28 Dec 2020 08:44:29 -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=DGHjnhnd; 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 S2634369AbgL1QlO (ORCPT + 99 others); Mon, 28 Dec 2020 11:41:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:55540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729292AbgL1M7O (ORCPT ); Mon, 28 Dec 2020 07:59:14 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AA4C522582; Mon, 28 Dec 2020 12:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160313; bh=cp5yAWSsmGzTB6HvGKaK6i/WsFk3L5RGH48JWKlLltg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DGHjnhndapMQ8xlR9PA54sOAjc4Wx8Ni07Wbv8Hckp0+D6qmWZRhMxCOEfJbunWHX 5R4ZyWLIczIaVe2b/RrAjfPisU44gowmIp/s1fj6L0hG4Jw6+DjDtogkrJADA3Va7b lGStJT1IdIFgltJNzuMJjMtWKDzCKd8iv6/Vyf/c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Mark Brown Subject: [PATCH 4.9 001/175] spi: bcm2835aux: Fix use-after-free on unbind Date: Mon, 28 Dec 2020 13:47:34 +0100 Message-Id: <20201228124853.297298171@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore 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 e13ee6cc4781edaf8c7321bee19217e3702ed481 ] bcm2835aux_spi_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. Fix by switching over to the new devm_spi_alloc_master() helper which keeps the private data accessible until the driver has unbound. Fixes: b9dd3f6d4172 ("spi: bcm2835aux: Fix controller unregister order") Signed-off-by: Lukas Wunner Cc: # v4.4+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v4.4+: b9dd3f6d4172: spi: bcm2835aux: Fix controller unregister order Cc: # v4.4+ Link: https://lore.kernel.org/r/b290b06357d0c0bdee9cecc539b840a90630f101.1605121038.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-bcm2835aux.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) --- a/drivers/spi/spi-bcm2835aux.c +++ b/drivers/spi/spi-bcm2835aux.c @@ -407,7 +407,7 @@ static int bcm2835aux_spi_probe(struct p unsigned long clk_hz; 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; @@ -439,30 +439,26 @@ static int bcm2835aux_spi_probe(struct p /* the main area */ 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 ((!bs->clk) || (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 PTR_ERR(bs->clk); } 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; } /* this also enables the HW block */ err = clk_prepare_enable(bs->clk); if (err) { dev_err(&pdev->dev, "could not prepare clock: %d\n", err); - goto out_master_put; + return err; } /* just checking if the clock returns a sane value */ @@ -495,8 +491,6 @@ static int bcm2835aux_spi_probe(struct p out_clk_disable: clk_disable_unprepare(bs->clk); -out_master_put: - spi_master_put(master); return err; }