]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/6.8.6/media-mediatek-vcodec-fix-oops-when-hevc-init-fails.patch
Linux 6.6.27
[thirdparty/kernel/stable-queue.git] / releases / 6.8.6 / media-mediatek-vcodec-fix-oops-when-hevc-init-fails.patch
1 From 2e680d62bd7f997857d5b2d86767d1b35f7605d9 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 26 Feb 2024 16:19:52 -0500
4 Subject: media: mediatek: vcodec: Fix oops when HEVC init fails
5
6 From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
7
8 [ Upstream commit 97c75ee5de060d271d80109b0c47cb6008439e5b ]
9
10 The stateless HEVC decoder saves the instance pointer in the context
11 regardless if the initialization worked or not. This caused a use after
12 free, when the pointer is freed in case of a failure in the deinit
13 function.
14 Only store the instance pointer when the initialization was successful,
15 to solve this issue.
16
17 Hardware name: Acer Tomato (rev3 - 4) board (DT)
18 pstate: 80400009 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
19 pc : vcodec_vpu_send_msg+0x4c/0x190 [mtk_vcodec_dec]
20 lr : vcodec_send_ap_ipi+0x78/0x170 [mtk_vcodec_dec]
21 sp : ffff80008750bc20
22 x29: ffff80008750bc20 x28: ffff1299f6d70000 x27: 0000000000000000
23 x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000
24 x23: ffff80008750bc98 x22: 000000000000a003 x21: ffffd45c4cfae000
25 x20: 0000000000000010 x19: ffff1299fd668310 x18: 000000000000001a
26 x17: 000000040044ffff x16: ffffd45cb15dc648 x15: 0000000000000000
27 x14: ffff1299c08da1c0 x13: ffffd45cb1f87a10 x12: ffffd45cb2f5fe80
28 x11: 0000000000000001 x10: 0000000000001b30 x9 : ffffd45c4d12b488
29 x8 : 1fffe25339380d81 x7 : 0000000000000001 x6 : ffff1299c9c06c00
30 x5 : 0000000000000132 x4 : 0000000000000000 x3 : 0000000000000000
31 x2 : 0000000000000010 x1 : ffff80008750bc98 x0 : 0000000000000000
32 Call trace:
33 vcodec_vpu_send_msg+0x4c/0x190 [mtk_vcodec_dec]
34 vcodec_send_ap_ipi+0x78/0x170 [mtk_vcodec_dec]
35 vpu_dec_deinit+0x1c/0x30 [mtk_vcodec_dec]
36 vdec_hevc_slice_deinit+0x30/0x98 [mtk_vcodec_dec]
37 vdec_if_deinit+0x38/0x68 [mtk_vcodec_dec]
38 mtk_vcodec_dec_release+0x20/0x40 [mtk_vcodec_dec]
39 fops_vcodec_release+0x64/0x118 [mtk_vcodec_dec]
40 v4l2_release+0x7c/0x100
41 __fput+0x80/0x2d8
42 __fput_sync+0x58/0x70
43 __arm64_sys_close+0x40/0x90
44 invoke_syscall+0x50/0x128
45 el0_svc_common.constprop.0+0x48/0xf0
46 do_el0_svc+0x24/0x38
47 el0_svc+0x38/0xd8
48 el0t_64_sync_handler+0xc0/0xc8
49 el0t_64_sync+0x1a8/0x1b0
50 Code: d503201f f9401660 b900127f b900227f (f9400400)
51
52 Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
53 Fixes: 2674486aac7d ("media: mediatek: vcodec: support stateless hevc decoder")
54 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
55 Signed-off-by: Sebastian Fricke <sebastian.fricke@collabora.com>
56 Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
57 Signed-off-by: Sasha Levin <sashal@kernel.org>
58 ---
59 .../mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c | 2 +-
60 1 file changed, 1 insertion(+), 1 deletion(-)
61
62 diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c
63 index 06ed47df693bf..21836dd6ef85a 100644
64 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c
65 +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c
66 @@ -869,7 +869,6 @@ static int vdec_hevc_slice_init(struct mtk_vcodec_dec_ctx *ctx)
67 inst->vpu.codec_type = ctx->current_codec;
68 inst->vpu.capture_type = ctx->capture_fourcc;
69
70 - ctx->drv_handle = inst;
71 err = vpu_dec_init(&inst->vpu);
72 if (err) {
73 mtk_vdec_err(ctx, "vdec_hevc init err=%d", err);
74 @@ -898,6 +897,7 @@ static int vdec_hevc_slice_init(struct mtk_vcodec_dec_ctx *ctx)
75 mtk_vdec_debug(ctx, "lat hevc instance >> %p, codec_type = 0x%x",
76 inst, inst->vpu.codec_type);
77
78 + ctx->drv_handle = inst;
79 return 0;
80 error_free_inst:
81 kfree(inst);
82 --
83 2.43.0
84