From: Richard Leitner <richard.leitner@linux.dev>
To: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
Cc: Lee Jones <lee@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>, Peng Fan <peng.fan@nxp.com>,
Oleksij Rempel <o.rempel@pengutronix.de>,
linux-remoteproc@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 05/10] remoteproc: imx_rproc: Avoid stale mailbox pointers on request failure
Date: Wed, 25 Nov 2026 07:27:18 +0100 [thread overview]
Message-ID: <awZ_HjrhS3Uiyssd@bombadil> (raw)
In-Reply-To: <awZ-XC1efo5QQvNI@bombadil>
On Wed, Nov 25, 2026 at 07:23:37AM +0100, Richard Leitner wrote:
> Hi Lee, Hi Peng,
>
> On Tue, Nov 24, 2026 at 11:23:41AM +0800, Peng Fan (OSS) wrote:
> > Hi Lee,
> > On Mon, 23 Nov 2026 17:20:49 +0000 Lee Jones <lee@kernel.org> wrote:
> >
> > > imx_rproc_xtr_mbox_init() stores the result of
> > > mbox_request_channel_byname() directly into priv->tx_ch and priv->rx_ch.
> > > Because mailbox channels are freed on stop() and detach() and
> > > re-requested on start(), attach(), and system shutdown, a failure while
> > > requesting "tx" leaves an ERR_PTR in priv->tx_ch, which is later
> > > dereferenced by imx_rproc_kick() and imx_rproc_free_mbox(). If "rx"
> > > fails after "tx" succeeds, priv->tx_ch is freed without being cleared
> > > while priv->rx_ch retains an ERR_PTR, causing subsequent calls to see
> > > both pointers as non-NULL and skip initialisation, leading to a
> > > use-after-free on priv->tx_ch and an ERR_PTR dereference on priv->rx_ch.
> > >
> > > Request both channels into local variables and assign priv->tx_ch and
> > > priv->rx_ch only after both requests succeed.
> >
> > I think Richard Leitner <richard.leitner@linux.dev> is working on this.
> >
> > https://lore.kernel.org/linux-remoteproc/CANLsYkx=M_TXN10qAcQC0be065TYnzfOae6E8ss-9DTj9MzogA@mail.gmail.com/T/#ma2f8e4c332d47e5bdd1787f82f4dd2feeafc67d6
>
> AFAICT my series fixes a similar, but other problem. Mine is about the
> free'ing order and a possible race when a kick occurs during
> cleanup/close. This one is targeted towards the setup/initialisation.
> Therefore IMHO this is a valid, fix for a different problem than mine.
>
> What's your opinion on this Lee?
Sorry, was too quick with answering and messed up things, as this fixes the
sashiko finding, not the "my" initial bug. So for me it's fine if we keep
this one, as I have not sended mine yet. ;-)
Therefore please feel free to add:
Reviewed-by: Richard Leitner <richard.leitner@linux.dev>
>
> reagards;rl
>
> >
> > Regards
> > Peng
> >
> > >
> > > Fixes: 99b142cf7191 ("remoteproc: imx_rproc: Request mbox channel later")
> > > Closes: https://sashiko.dev/#/bug/linux-ac0f248a-bdfd-41da-95f8-44b8f1f7091d
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Lee Jones <lee@kernel.org>
> > > ---
> > > drivers/remoteproc/imx_rproc.c | 18 +++++++++++-------
> > > 1 file changed, 11 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> > > index 581bb07f5893..a77a3342e1ed 100644
> > > --- a/drivers/remoteproc/imx_rproc.c
> > > +++ b/drivers/remoteproc/imx_rproc.c
> > > @@ -875,6 +875,7 @@ static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)
> > > static int imx_rproc_xtr_mbox_init(struct rproc *rproc, bool tx_block)
> > > {
> > > struct imx_rproc *priv = rproc->priv;
> > > + struct mbox_chan *tx_ch, *rx_ch;
> > > struct device *dev = priv->dev;
> > > struct mbox_client *cl;
> > >
> > > @@ -900,18 +901,21 @@ static int imx_rproc_xtr_mbox_init(struct rproc *rproc, bool tx_block)
> > > cl->knows_txdone = false;
> > > cl->rx_callback = imx_rproc_rx_callback;
> > >
> > > - priv->tx_ch = mbox_request_channel_byname(cl, "tx");
> > > - if (IS_ERR(priv->tx_ch))
> > > - return dev_err_probe(cl->dev, PTR_ERR(priv->tx_ch),
> > > + tx_ch = mbox_request_channel_byname(cl, "tx");
> > > + if (IS_ERR(tx_ch))
> > > + return dev_err_probe(cl->dev, PTR_ERR(tx_ch),
> > > "failed to request tx mailbox channel\n");
> > >
> > > - priv->rx_ch = mbox_request_channel_byname(cl, "rx");
> > > - if (IS_ERR(priv->rx_ch)) {
> > > - mbox_free_channel(priv->tx_ch);
> > > - return dev_err_probe(cl->dev, PTR_ERR(priv->rx_ch),
> > > + rx_ch = mbox_request_channel_byname(cl, "rx");
> > > + if (IS_ERR(rx_ch)) {
> > > + mbox_free_channel(tx_ch);
> > > + return dev_err_probe(cl->dev, PTR_ERR(rx_ch),
> > > "failed to request rx mailbox channel\n");
> > > }
> > >
> > > + priv->tx_ch = tx_ch;
> > > + priv->rx_ch = rx_ch;
> > > +
> > > return 0;
> > > }
> > >
> > > --
> > > 2.56.1.750.gf70dc682cf-goog
> >
> > Sent using hkml (https://github.com/sjp38/hackermail)
next prev parent reply other threads:[~2026-11-25 6:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261123172140.3547896-1-lee@kernel.org>
2026-11-23 17:20 ` [PATCH 01/10] remoteproc: core: Fix integer overflow in rproc_check_carveout_da() Lee Jones
2026-11-23 17:20 ` [PATCH 02/10] remoteproc: k3: Fix integer overflow in k3_rproc_da_to_va() Lee Jones
2026-11-23 17:20 ` [PATCH 03/10] remoteproc: omap: Fix integer overflow in omap_rproc_da_to_va() Lee Jones
2026-11-23 17:20 ` [PATCH 04/10] remoteproc: elf_loader: Fix overflow in rproc_elf_load_segments() Lee Jones
2026-11-23 17:20 ` [PATCH 05/10] remoteproc: imx_rproc: Avoid stale mailbox pointers on request failure Lee Jones
2026-11-24 3:23 ` Peng Fan (OSS)
2026-11-25 6:23 ` Richard Leitner
2026-11-25 6:27 ` Richard Leitner [this message]
2026-11-23 17:20 ` [PATCH 06/10] remoteproc: imx_rproc: Register SCU cleanup after resource acquisition Lee Jones
2026-11-24 3:25 ` Peng Fan (OSS)
2026-11-23 17:20 ` [PATCH 07/10] remoteproc: qcom: Clear glink->node on allocation failure Lee Jones
2026-11-23 17:20 ` [PATCH 08/10] remoteproc: qcom: Skip unregistering uninitialised SSR subdevice Lee Jones
2026-11-23 22:25 ` Alex Elder
2026-11-23 17:20 ` [PATCH 09/10] remoteproc: imx_dsp_rproc: Fix pointer stride in imx_dsp_rproc_memset() Lee Jones
2026-11-24 3:25 ` Peng Fan (OSS)
2026-11-23 17:20 ` [PATCH 10/10] remoteproc: imx_dsp_rproc: Fix off-by-one bitmask for trailing bytes Lee Jones
2026-11-24 3:26 ` Peng Fan (OSS)
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=awZ_HjrhS3Uiyssd@bombadil \
--to=richard.leitner@linux.dev \
--cc=Frank.Li@nxp.com \
--cc=andersson@kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=o.rempel@pengutronix.de \
--cc=peng.fan@nxp.com \
--cc=peng.fan@oss.nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=stable@vger.kernel.org \
/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