Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp830454pxu; Mon, 23 Nov 2020 05:24:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxacRKo80Zew7AqCahLvOrFvNASCqgyTY8jZL3WZzGPczGVyI0dITxqDvHwBZKYVS9JucrD X-Received: by 2002:a50:bb26:: with SMTP id y35mr36285653ede.257.1606137851493; Mon, 23 Nov 2020 05:24:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606137851; cv=none; d=google.com; s=arc-20160816; b=nHg7GWCwKwWDccGMhj9eOjTAedMav8wcpGA6ASAV/jbH3lAtEKbUPOZcPu+dDc0ApL n+oDdBBBOn+YenYOZgPj3AP2sGpUfD3AsqHwZTmsOE9e8xcPCPSVRoQxaZ3aF3yAsIYT /H8On3yXVHGfuIurXsf7IHHgOhtE9Qq4FjGa6f3btNWLVsV1Wdru+eUjnxsSMST28xwg kgC1fNvXnvF5Ko+dsPhrAZt4PvgX3KMVPLQcI2hmQxAWxZuKndFdS4xYxe4OgOl5Ha7B eqZEGmu8xlBkoMyIHgFqiO58MMOWpkdabXd7VfiNI6dO56JKjuYG8DwkwGnlYEBFWZI5 0ikQ== 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=0OD5CtaUvGKzIa3N+rsJ1paE4g+SLUmF3IO11F7s/O4=; b=S1yHk3Ic5tWioHmbANz5y+eBHyzzQkU57C84LEVGCa6TazE/WkPAyXo/EQTaL4ktEJ YSUbI7rAnhJBabNo4bFePRwEwMmmZ/X8xE5XhKSLpkBWbROc7QF4Bj4XAtNdc18Wya1K HzfhNL7qSae1expQ2p5BtGY60We93q3kNQq7qowQhD8qWLOC6j272dBbyTJcRzl5S7zR /+XWXo4fSJ+bgw/TjyCezzxdthsYPejViTuBgh/EKU1u2bdxuh8En3VwEvFcnfyofiIf M0DZJcyTc2BGj/prULxGboDBqJuNxL7WplUt+EnTx6L70L9uwXra5wUWB9iPSq9xhoUV +MWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wlkUXbcY; 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 a9si6825001edq.466.2020.11.23.05.23.48; Mon, 23 Nov 2020 05:24:11 -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=wlkUXbcY; 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 S1732358AbgKWMjw (ORCPT + 99 others); Mon, 23 Nov 2020 07:39:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:52466 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732303AbgKWMjq (ORCPT ); Mon, 23 Nov 2020 07:39:46 -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 A26CB217A0; Mon, 23 Nov 2020 12:39:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135186; bh=bLd/IA/GBN91CmWxjZ77W/baBskahdfQejsxLh0CS6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wlkUXbcY+7bDDKmxBGoV0LSfULfp5rwmEH9TlsY1OQ9DgQDh0t+Q0vzIHCarajMXF q2uNa6zxfEYeoj9T7aF4CqUeRyL/kq0lp+jkoRZI5bJrLO6zP5s4wIWdX2kygVE+4C smxeBocH8yCI71SlOSQr/OTNbrHFH90jBc3LM+sA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Mark Brown Subject: [PATCH 5.4 136/158] spi: bcm2835aux: Fix use-after-free on unbind Date: Mon, 23 Nov 2020 13:22:44 +0100 Message-Id: <20201123121826.494943875@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@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 e13ee6cc4781edaf8c7321bee19217e3702ed481 upstream. 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+: 123456789abc: 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 | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) --- a/drivers/spi/spi-bcm2835aux.c +++ b/drivers/spi/spi-bcm2835aux.c @@ -494,7 +494,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) return -ENOMEM; @@ -524,29 +524,24 @@ static int bcm2835aux_spi_probe(struct p /* the main area */ bs->regs = devm_platform_ioremap_resource(pdev, 0); - 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 PTR_ERR(bs->clk); } bs->irq = platform_get_irq(pdev, 0); - if (bs->irq <= 0) { - err = bs->irq ? bs->irq : -ENODEV; - goto out_master_put; - } + if (bs->irq <= 0) + 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 */ @@ -581,8 +576,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; }