]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
media: iris: fix use-after-free of fmt_src during MBPF check
authorVishnu Reddy <busanna.reddy@oss.qualcomm.com>
Thu, 5 Mar 2026 13:28:31 +0000 (18:58 +0530)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Mon, 27 Apr 2026 06:41:21 +0000 (08:41 +0200)
During concurrency testing, multiple instances can run in parallel, and
each instance uses its own inst->lock while the core->lock protects the
list of active instances. The race happens because these locks cover
different scopes, inst->lock protects only the internals of a single
instance, while the Macro Blocks Per Frame (MBPF) checker walks the
core list under core->lock and reads fields like fmt_src->width and
fmt_src->height. At the same time, iris_close() may free fmt_src and
fmt_dst under inst->lock while the instance is still present in the core
list. This allows a situation where the MBPF checker, still iterating
through the core list, reaches an instance whose fmt_src was already
freed by another thread and ends up dereferencing a dangling pointer,
resulting in a use-after-free. This happens because the MBPF checker
assumes that any instance in the core list is fully valid, but the
freeing of fmt_src and fmt_dst without removing the instance from the
core list is not correct.

The correct ordering is to defer freeing fmt_src and fmt_dst until after
the instance has been removed from the core list and all teardown under
the core lock has completed, ensuring that no dangling pointers are ever
exposed during MBPF checks.

Reviewed-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
Reviewed-by: Dikshita Agarwal <dikshita.agarwal@oss.qualcomm.com>
Fixes: 5ad964ad5656 ("media: iris: Initialize and deinitialize encoder instance structure")
Cc: stable@vger.kernel.org
Signed-off-by: Bryan O'Donoghue <bod@kernel.org>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/platform/qcom/iris/iris_vdec.c
drivers/media/platform/qcom/iris/iris_vdec.h
drivers/media/platform/qcom/iris/iris_venc.c
drivers/media/platform/qcom/iris/iris_venc.h
drivers/media/platform/qcom/iris/iris_vidc.c

index 719217399a304e56608cb2acd8ece430b2ecaacf..99d544e2af4f98f6d3ffd97c2fadeec49fe4aca5 100644 (file)
@@ -61,12 +61,6 @@ int iris_vdec_inst_init(struct iris_inst *inst)
        return iris_ctrls_init(inst);
 }
 
-void iris_vdec_inst_deinit(struct iris_inst *inst)
-{
-       kfree(inst->fmt_dst);
-       kfree(inst->fmt_src);
-}
-
 static const struct iris_fmt iris_vdec_formats_cap[] = {
        [IRIS_FMT_NV12] = {
                .pixfmt = V4L2_PIX_FMT_NV12,
index ec1ce55d1375fd6518983baae2acf0fc43b6cabd..5123d2a340e15f1642ceb943f5cadbe021e647fa 100644 (file)
@@ -9,7 +9,6 @@
 struct iris_inst;
 
 int iris_vdec_inst_init(struct iris_inst *inst);
-void iris_vdec_inst_deinit(struct iris_inst *inst);
 int iris_vdec_enum_fmt(struct iris_inst *inst, struct v4l2_fmtdesc *f);
 int iris_vdec_try_fmt(struct iris_inst *inst, struct v4l2_format *f);
 int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f);
index aa27b22704eb9e6178efc95d5648ec9b18a6f2d6..4d886769d958b95e024e92078231d0dfc38fc2e0 100644 (file)
@@ -79,12 +79,6 @@ int iris_venc_inst_init(struct iris_inst *inst)
        return iris_ctrls_init(inst);
 }
 
-void iris_venc_inst_deinit(struct iris_inst *inst)
-{
-       kfree(inst->fmt_dst);
-       kfree(inst->fmt_src);
-}
-
 static const struct iris_fmt iris_venc_formats_cap[] = {
        [IRIS_FMT_H264] = {
                .pixfmt = V4L2_PIX_FMT_H264,
index c4db7433da537578e05d566d53d89a22e1901678..00c1716b2747c7e840c2a3317800d83663744bf0 100644 (file)
@@ -9,7 +9,6 @@
 struct iris_inst;
 
 int iris_venc_inst_init(struct iris_inst *inst);
-void iris_venc_inst_deinit(struct iris_inst *inst);
 int iris_venc_enum_fmt(struct iris_inst *inst, struct v4l2_fmtdesc *f);
 int iris_venc_try_fmt(struct iris_inst *inst, struct v4l2_format *f);
 int iris_venc_s_fmt(struct iris_inst *inst, struct v4l2_format *f);
index bd38d84c9cc79d15585ed5dd5f905a37521cb6dc..5eb1786b07371d157dfc66018cd1010418831aab 100644 (file)
@@ -289,10 +289,6 @@ int iris_close(struct file *filp)
        v4l2_m2m_ctx_release(inst->m2m_ctx);
        v4l2_m2m_release(inst->m2m_dev);
        mutex_lock(&inst->lock);
-       if (inst->domain == DECODER)
-               iris_vdec_inst_deinit(inst);
-       else if (inst->domain == ENCODER)
-               iris_venc_inst_deinit(inst);
        iris_session_close(inst);
        iris_inst_change_state(inst, IRIS_INST_DEINIT);
        iris_v4l2_fh_deinit(inst, filp);
@@ -304,6 +300,8 @@ int iris_close(struct file *filp)
        mutex_unlock(&inst->lock);
        mutex_destroy(&inst->ctx_q_lock);
        mutex_destroy(&inst->lock);
+       kfree(inst->fmt_src);
+       kfree(inst->fmt_dst);
        kfree(inst);
 
        return 0;