From: <Tudor.Ambarus@microchip.com>
To: <lukas@wunner.de>, <broonie@kernel.org>
Cc: <linux-spi@vger.kernel.org>, <bugalski.piotr@gmail.com>
Subject: Re: [PATCH 17/17] spi: atmel-quadspi: Fix use-after-free on unbind
Date: Mon, 7 Dec 2020 15:03:14 +0000 [thread overview]
Message-ID: <2e903538-d221-3f6b-cc46-3f4951ecbcdf@microchip.com> (raw)
In-Reply-To: <4b05c65cf6f1ea3251484fe9a00b4c65478a1ae3.1607286887.git.lukas@wunner.de>
On 12/7/20 10:17 AM, Lukas Wunner wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> 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 <lukas@wunner.de>
> Cc: <stable@vger.kernel.org> # v5.0+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation
> Cc: <stable@vger.kernel.org> # v5.0+
> Cc: Piotr Bugalski <bugalski.piotr@gmail.com>
Reviewed-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
> drivers/spi/atmel-quadspi.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
> index b44521d4a245..1742ccc1ad0e 100644
> --- a/drivers/spi/atmel-quadspi.c
> +++ b/drivers/spi/atmel-quadspi.c
> @@ -535,7 +535,7 @@ static int atmel_qspi_probe(struct platform_device *pdev)
> 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;
>
> @@ -557,8 +557,7 @@ static int atmel_qspi_probe(struct platform_device *pdev)
> 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 */
> @@ -566,8 +565,7 @@ static int atmel_qspi_probe(struct platform_device *pdev)
> 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);
> @@ -579,15 +577,14 @@ static int atmel_qspi_probe(struct platform_device *pdev)
>
> 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);
> @@ -638,8 +635,6 @@ static int atmel_qspi_probe(struct platform_device *pdev)
> clk_disable_unprepare(aq->qspick);
> disable_pclk:
> clk_disable_unprepare(aq->pclk);
> -exit:
> - spi_controller_put(ctrl);
>
> return err;
> }
> --
> 2.29.2
>
next prev parent reply other threads:[~2020-12-07 15:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-07 8:17 [PATCH 00/17] SPI probe/remove sanitization for 5.11 Lukas Wunner
2020-12-07 8:17 ` [PATCH 01/17] spi: davinci: Fix use-after-free on unbind Lukas Wunner
2020-12-07 8:17 ` [PATCH 02/17] spi: spi-geni-qcom: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 03/17] spi: spi-qcom-qspi: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 04/17] spi: spi-sh: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 05/17] spi: pxa2xx: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 06/17] spi: rpc-if: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 07/17] spi: mxic: Don't leak SPI master in probe error path Lukas Wunner
2020-12-07 8:17 ` [PATCH 08/17] spi: spi-mtk-nor: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 09/17] spi: gpio: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 10/17] spi: rb4xx: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 11/17] spi: sc18is602: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 12/17] media: netup_unidvb: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 13/17] spi: mt7621: Disable clock " Lukas Wunner
2020-12-07 8:17 ` [PATCH 14/17] spi: mt7621: Don't leak SPI master " Lukas Wunner
2020-12-07 8:17 ` [PATCH 15/17] spi: ar934x: " Lukas Wunner
2020-12-07 8:17 ` [PATCH 16/17] spi: npcm-fiu: Disable clock " Lukas Wunner
2020-12-07 8:17 ` [PATCH 17/17] spi: atmel-quadspi: Fix use-after-free on unbind Lukas Wunner
2020-12-07 15:03 ` Tudor.Ambarus [this message]
2020-12-07 17:22 ` [PATCH 00/17] SPI probe/remove sanitization for 5.11 Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2e903538-d221-3f6b-cc46-3f4951ecbcdf@microchip.com \
--to=tudor.ambarus@microchip.com \
--cc=broonie@kernel.org \
--cc=bugalski.piotr@gmail.com \
--cc=linux-spi@vger.kernel.org \
--cc=lukas@wunner.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox