All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: Alain Volmat <alain.volmat@foss.st.com>
Cc: broonie@kernel.org, amelie.delaunay@foss.st.com,
	mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com,
	linux-spi@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, fabrice.gasnier@foss.st.com,
	antonio.borneo@foss.st.com
Subject: Re: [PATCH] spi: stm32: drop devres version of spi_register_master
Date: Tue, 16 Mar 2021 22:17:44 +0100	[thread overview]
Message-ID: <20210316211744.GA25311@wunner.de> (raw)
In-Reply-To: <1615545286-5395-1-git-send-email-alain.volmat@foss.st.com>

On Fri, Mar 12, 2021 at 11:34:46AM +0100, Alain Volmat wrote:
> --- a/drivers/spi/spi-stm32.c
> +++ b/drivers/spi/spi-stm32.c
> @@ -1960,6 +1960,7 @@ static int stm32_spi_remove(struct platform_device *pdev)
>  	struct spi_master *master = platform_get_drvdata(pdev);
>  	struct stm32_spi *spi = spi_master_get_devdata(master);
>  
> +	spi_unregister_master(master);
>  	spi->cfg->disable(spi);
>  
>  	if (master->dma_tx)

This introduces a use-after-free because spi_unregister_master()
drops the last reference on the spi_master allocation (which includes
the struct stm32_spi), causing it to be freed, yet the stm32_spi
struct is accessed afterwards.

You need to convert the driver to devm_spi_alloc_master() to
fix the use-after-free.  See commit 6cfd39e212de for an example.

Thanks,

Lukas

  parent reply	other threads:[~2021-03-16 21:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 10:34 [PATCH] spi: stm32: drop devres version of spi_register_master Alain Volmat
2021-03-12 10:34 ` Alain Volmat
2021-03-12 20:25 ` Mark Brown
2021-03-12 20:25   ` Mark Brown
2021-03-16 21:17 ` Lukas Wunner [this message]
2021-03-18  7:22   ` Alain Volmat
2021-03-18  7:22     ` Alain Volmat

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=20210316211744.GA25311@wunner.de \
    --to=lukas@wunner.de \
    --cc=alain.volmat@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=amelie.delaunay@foss.st.com \
    --cc=antonio.borneo@foss.st.com \
    --cc=broonie@kernel.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.