From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA9D03AD525 for ; Wed, 15 Jul 2026 16:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784134458; cv=none; b=QKWgFjQdOi52xXp1//Lw+jt2eqk+ucb7q7ksRsyhtxvGYj4Q3EQ0LIZ55v6eHZFQS5BrQbCGlF20zpmh1DPB4VyYTiGbcu5XRSH+oLZ5wUJW5N5aIYyLnA+WHCpHCX44QByfo7XoktbXiF/PMFMdWqOPBcwX6cwyjiYLkY6AqwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784134458; c=relaxed/simple; bh=6Yf1XBh9DHlZ3jQ3M6De+M2eE1Z4qhAfs83MUZ397y0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M4es5R+wBE2iAxYewnIY/tZULodIkJgH7W3dd1xm3lq5Hvg48tSHJv2D89EI3/t/7/RvS4HpWJXEqaTPNKj7yGAqTXppPuWl8bsMELN6GKaVS+k/Wnt7eTmBU1GoO/rYrzh4SspokowfnDK2r5P0tG63pd4M9hKmo+wvOYAorD4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rlmazt7q; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Rlmazt7q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58B001F00A3D; Wed, 15 Jul 2026 16:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784134455; bh=QwfS5ci9RzmKmRVkiUwtiECAuML8l7tS6ydimhIJ/9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Rlmazt7q+dqHH7obehx7z8eZoWD3PyxJuK15JpF+a37KdpOkwVer6G1erkMB3xUsH MTjfGL9jmrbS60hfF6QPqHXLQN3escTImgAVs/vIksgRigbRtEpsT5UMoF1hZWHRcf yKLA/c6Dn3NcxJmbwEXNuhEqukIr0Kxlb1XHCpLYH52gCxUtuc+O7dPbwTYSLHeU2Q 7iTFOOCI1ouaaUX26+fCYWggIJz74cID6qNq7gZQcbzJ1b9wHbSJKOC9aY/bFI+VEF 4tmtmO+HM+HbM5VuBOquHRVhJXpM5qs8CPUn3mXO9gdwcKd7UcdAl+MJk8paFr7gJ5 euEeIblWHGpGg== From: Sasha Levin To: stable@vger.kernel.org Cc: Xiaolei Wang , Frank Li , Laurent Pinchart , Hans Verkuil , Sasha Levin Subject: [PATCH 6.6.y 3/3] media: nxp: imx8-isi: Fix use-after-free on remove Date: Wed, 15 Jul 2026 12:54:10 -0400 Message-ID: <20260715165410.963211-3-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260715165410.963211-1-sashal@kernel.org> References: <2026071345-pureness-herald-7920@gregkh> <20260715165410.963211-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Xiaolei Wang [ Upstream commit b670bf89824ede5d07d20bb9bfbafb754846081d ] 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") Cc: stable@vger.kernel.org Signed-off-by: Xiaolei Wang Reviewed-by: Frank Li Reviewed-by: Laurent Pinchart Link: https://patch.msgid.link/20260507041318.491594-2-xiaolei.wang@windriver.com Signed-off-by: Laurent Pinchart Signed-off-by: Hans Verkuil Signed-off-by: Sasha Levin --- 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 8b2f91cb47ac74..a1354d40ad8eac 100644 --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c @@ -521,8 +521,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[] = { -- 2.53.0