Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9281573pxu; Mon, 28 Dec 2020 11:17:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJx66Yu5vyy/0WodaBvRA/Eqrq42dRHN5KoMbhIVMHdi4I7BL8NeE70yrGDEw/wFxhvfp+Ib X-Received: by 2002:a17:906:3099:: with SMTP id 25mr42930845ejv.321.1609183029335; Mon, 28 Dec 2020 11:17:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609183029; cv=none; d=google.com; s=arc-20160816; b=k4wInwVBwqI7MKotStXGkpNwLMPMp9ZxGq7Skd2VH6IXWbtVCrwh0E3J5hbIBbwr4+ RgiPpjXy0lKbfMivuqjaMT213oNiwJo2mwg0sWr47hX7g1eMeywDmukp5NQDgsZKjmP4 U+rqPzfcnrc0Ow8gVaqYwTAx2EGBEPoHs/lDjOoSlOOwFu3mOBhO6Wkdm/VwFzUOWPf6 +2k7DhBQjJhtYXiJtFDgAU74tNNeXFnHLKPEo6PU2gxFSnhTeTF+5TPwpX6moSK9Pd0T i1YSOPiiqtRo3rkvzBoTEfxiARKwSjYPp1aBW8JKFeWkm5SXTSG3ppgfKvD1Xkrl71c8 aFug== 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=dn9RB53TtZLUX962eW74cUue58Vxv4znMUmIFXQ/Xt0=; b=bZqIWY2b/8dxU4oHZQ7Mpm11FrMnFif2B1lwTsFmTZUNMwhKuO1V+8U6JL5C4uKwly o14FXKVNL1WAsWRRdmyGafMcc7862AQrg8urKUY00O/2FKn1dlGxlrGqCQ/tjJWbdCJb dlkVtuKZeYdmF7xt2KGFo7mPCvWAexnOSkHXm7y/JU9729uZSkZdhI0O4EskEcwH7VSn CHi6D+D6E/H3dX6Bxa9nUUcVCLag/uxmGLZtneaxVyRd+zQ2E2h2OnNMK48xIXuwn+s+ l7Mcg4J3C6D+gQ0mMOiPJG3P9M2Vz7nfjY3vTbb0axTy3OUdGaX6VDL71xte80n8ILFW bFCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tSY0Vc+K; 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 i6si21024941ejs.659.2020.12.28.11.16.47; Mon, 28 Dec 2020 11:17:09 -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=tSY0Vc+K; 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 S2406672AbgL1N52 (ORCPT + 99 others); Mon, 28 Dec 2020 08:57:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:58862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406446AbgL1N5S (ORCPT ); Mon, 28 Dec 2020 08:57:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D32252064B; Mon, 28 Dec 2020 13:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609163797; bh=a04PwuCJ/PHNtK7lpuYCemqdvR0ftNrLij5H8a2Eorc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tSY0Vc+KormIk/AfD6LFWWhisgdY4gNFn7gAnjbzAoStt0KSPuwTwK2Al8xmK7PZI 0rP4rdF/rEI4bgydJwxvRONckeGdJiZL0hLe0cer0UjVkMvLeP9eRhtft5MPs2iIVy rxdl/JgyFdXk/r7qJoIlM3KF86IXwQX8O49OsuZA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Piotr Bugalski , Mark Brown Subject: [PATCH 5.4 403/453] spi: atmel-quadspi: Fix use-after-free on unbind Date: Mon, 28 Dec 2020 13:50:39 +0100 Message-Id: <20201228124956.601937660@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124937.240114599@linuxfoundation.org> References: <20201228124937.240114599@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 c7b884561cb5b641f3dbba950094110794119a6d upstream. atmel_qspi_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: 2d30ac5ed633 ("mtd: spi-nor: atmel-quadspi: Use spi-mem interface for atmel-quadspi driver") Signed-off-by: Lukas Wunner Cc: # v5.0+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v5.0+ Cc: Piotr Bugalski Link: https://lore.kernel.org/r/4b05c65cf6f1ea3251484fe9a00b4c65478a1ae3.1607286887.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/atmel-quadspi.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) --- a/drivers/spi/atmel-quadspi.c +++ b/drivers/spi/atmel-quadspi.c @@ -454,7 +454,7 @@ static int atmel_qspi_probe(struct platf struct resource *res; int irq, err = 0; - ctrl = spi_alloc_master(&pdev->dev, sizeof(*aq)); + ctrl = devm_spi_alloc_master(&pdev->dev, sizeof(*aq)); if (!ctrl) return -ENOMEM; @@ -476,8 +476,7 @@ static int atmel_qspi_probe(struct platf aq->regs = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(aq->regs)) { dev_err(&pdev->dev, "missing registers\n"); - err = PTR_ERR(aq->regs); - goto exit; + return PTR_ERR(aq->regs); } /* Map the AHB memory */ @@ -485,8 +484,7 @@ static int atmel_qspi_probe(struct platf aq->mem = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(aq->mem)) { dev_err(&pdev->dev, "missing AHB memory\n"); - err = PTR_ERR(aq->mem); - goto exit; + return PTR_ERR(aq->mem); } aq->mmap_size = resource_size(res); @@ -498,15 +496,14 @@ static int atmel_qspi_probe(struct platf if (IS_ERR(aq->pclk)) { dev_err(&pdev->dev, "missing peripheral clock\n"); - err = PTR_ERR(aq->pclk); - goto exit; + return PTR_ERR(aq->pclk); } /* Enable the peripheral clock */ err = clk_prepare_enable(aq->pclk); if (err) { dev_err(&pdev->dev, "failed to enable the peripheral clock\n"); - goto exit; + return err; } aq->caps = of_device_get_match_data(&pdev->dev); @@ -557,8 +554,6 @@ disable_qspick: clk_disable_unprepare(aq->qspick); disable_pclk: clk_disable_unprepare(aq->pclk); -exit: - spi_controller_put(ctrl); return err; }