From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Xiaolei Wang <xiaolei.wang@windriver.com>
Cc: mchehab@kernel.org, Frank.li@nxp.com, s.hauer@pengutronix.de,
kernel@pengutronix.de, festevam@gmail.com, aisheng.dong@nxp.com,
jacopo@jmondi.org, guoniu.zhou@nxp.com, s.riedmueller@phytec.de,
linux-media@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 v2 1/4] media: imx8-isi: fix use-after-free on remove
Date: Wed, 6 May 2026 15:31:52 +0300 [thread overview]
Message-ID: <20260506123152.GN1598374@killaraus.ideasonboard.com> (raw)
In-Reply-To: <20260506031210.2769998-2-xiaolei.wang@windriver.com>
Hello Xiaolei,
Thank you for the patch.
On Wed, May 06, 2026 at 11:12:07AM +0800, Xiaolei Wang wrote:
> KASAN reports a slab-use-after-free in __media_entity_remove_link()
> during rmmod of imx8_isi:
>
> BUG: KASAN: slab-use-after-free in __media_entity_remove_link+0x608/0x650
> Read of size 2 at addr ffff0000d47cb02a by task rmmod/724
>
> Call trace:
> __media_entity_remove_link+0x608/0x650
> __media_entity_remove_links+0x78/0x144
> __media_device_unregister_entity+0x150/0x280
> media_device_unregister_entity+0x48/0x68
> v4l2_device_unregister_subdev+0x158/0x300
> v4l2_async_unbind_subdev_one+0x22c/0x358
> v4l2_async_nf_unbind_all_subdevs+0xfc/0x1c0
> v4l2_async_nf_unregister+0x5c/0x14c
> mxc_isi_remove+0x124/0x2a0 [imx8_isi]
>
> Allocated by task 249:
> __kmalloc_noprof+0x27c/0x690
> mxc_isi_crossbar_init+0x22c/0x560 [imx8_isi]
>
> Freed by task 724:
> kfree+0x1e4/0x5b0
> mxc_isi_crossbar_cleanup+0x34/0x80 [imx8_isi]
> mxc_isi_remove+0x11c/0x2a0 [imx8_isi]
>
> The problem is that mxc_isi_remove() calls mxc_isi_crossbar_cleanup()
> before mxc_isi_v4l2_cleanup(). The crossbar cleanup frees the media
> entity pads, but the subsequent v4l2 cleanup still tries to remove
> media links that reference those pads.
>
> Fix this by calling mxc_isi_v4l2_cleanup() before
> mxc_isi_crossbar_cleanup() to ensure all media entities are properly
> unregistered while the pads are still valid.
>
> Fixes: cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")
> Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> index 4bf8570e1b9e..2d639b789910 100644
> --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c
> @@ -556,8 +556,8 @@ static void mxc_isi_remove(struct platform_device *pdev)
> mxc_isi_pipe_cleanup(pipe);
> }
>
> - mxc_isi_crossbar_cleanup(&isi->crossbar);
> mxc_isi_v4l2_cleanup(isi);
> + mxc_isi_crossbar_cleanup(&isi->crossbar);
> }
>
> static const struct of_device_id mxc_isi_of_match[] = {
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2026-05-06 12:32 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 3:12 [PATCH v2 0/4] media: imx8-isi: fix resource cleanup issues Xiaolei Wang
2026-05-06 3:12 ` [PATCH v2 1/4] media: imx8-isi: fix use-after-free on remove Xiaolei Wang
2026-05-06 12:31 ` Laurent Pinchart [this message]
2026-05-06 3:12 ` [PATCH v2 2/4] media: imx8-isi: add missing v4l2_subdev_cleanup() in crossbar and pipe Xiaolei Wang
2026-05-06 12:35 ` Laurent Pinchart
2026-05-06 14:23 ` xiaolei wang
2026-05-06 3:12 ` [PATCH v2 3/4] media: imx8-isi: fix isi->pipes memory leak in probe and remove Xiaolei Wang
2026-05-06 12:41 ` Laurent Pinchart
2026-05-06 14:29 ` xiaolei wang
2026-05-06 3:12 ` [PATCH v2 4/4] media: imx8-isi: clean up already-initialized pipes on probe failure Xiaolei Wang
2026-05-06 14:19 ` Laurent Pinchart
2026-05-06 14:25 ` Frank Li
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=20260506123152.GN1598374@killaraus.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=Frank.li@nxp.com \
--cc=aisheng.dong@nxp.com \
--cc=festevam@gmail.com \
--cc=guoniu.zhou@nxp.com \
--cc=imx@lists.linux.dev \
--cc=jacopo@jmondi.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=s.riedmueller@phytec.de \
--cc=stable@vger.kernel.org \
--cc=xiaolei.wang@windriver.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox