media: mediatek: vcodec: Fix encoder access NULL pointer
Subsystems (3)
PATCH 1/2 media: mediatek: vcodec: Fix encoder access NULL pointer
Need to set the private data with encoder device, or will access NULL pointer in encoder handler.
--- drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +2 -1
@@ -138,7 +138,8 @@ int vpu_enc_init(struct venc_vpu_inst *vpu) vpu->ctx->vpu_inst = vpu; status =mtk_vcodec_fw_ipi_register (vpu->ctx->dev->fw_handler, vpu->id, - vpu_enc_ipi_handler,"venc" ,NULL ); + vpu_enc_ipi_handler,"venc" , + vpu->ctx->dev);if (status) {mtk_venc_err (vpu->ctx,"vpu_ipi_register fail %d" , status);
Signature · 1 line
2.25.1
PATCH 2/2 media: mediatek: vcodec: Handle encoder vsi NULL pointer case
There will be a kernel null pointer exception if 'vsi' is NULL, check 'vsi' is not NULL before assign it to encoder instance.
--- .../platform/mediatek/vcodec/encoder/venc/venc_h264_if.c | 5 +++++ .../platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c | 5 +++++ 2 files changed, 10 insertions(+)
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +5 -0
@@ -597,6 +597,11 @@ static int h264_enc_init(struct mtk_vcodec_enc_ctx *ctx) inst->hw_base =mtk_vcodec_get_reg_addr (inst->ctx->dev->reg_base,VENC_SYS ); ret =vpu_enc_init (&inst->vpu_inst); +if (!inst->vpu_inst.vsi) { +mtk_venc_err (ctx,"share buffer is NULL" ); +kfree (inst); +return -EFAULT ; + }if (MTK_ENC_IOVA_IS_34BIT (ctx)) inst->vsi_34 = (struct venc_h264_vsi_34 *)inst->vpu_inst.vsi;
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c +5 -0
@@ -326,6 +326,11 @@ static int vp8_enc_init(struct mtk_vcodec_enc_ctx *ctx) inst->hw_base =mtk_vcodec_get_reg_addr (inst->ctx->dev->reg_base,VENC_LT_SYS ); ret =vpu_enc_init (&inst->vpu_inst); +if (!inst->vpu_inst.vsi) { +mtk_venc_err (ctx,"share buffer is NULL" ); +kfree (inst); +return -EFAULT ; + } inst->vsi = (struct venc_vp8_vsi *)inst->vpu_inst.vsi;
Signature · 1 line
2.25.1
Re: [PATCH 2/2] media: mediatek: vcodec: Handle encoder vsi NULL pointer case
Quoted 4 lines · Irui Wang
There will be a kernel null pointer exception if 'vsi' is NULL, check 'vsi' is not NULL before assign it to encoder instance.
Signed-off-by Irui Wang <[email protected]>
I see no Fixes tag, is that correct?
Is this a fix that needs to go to kernel 6.6? It's not clear how urgent this is.
Regards,
Hans
Quoted 37 lines
--- .../platform/mediatek/vcodec/encoder/venc/venc_h264_if.c | 5 +++++ .../platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c | 5 +++++ 2 files changed, 10 insertions(+)drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +5
-0@@ -597,6 +597,11 @@ static int h264_enc_init(struct mtk_vcodec_enc_ctx *ctx) inst->hw_base =mtk_vcodec_get_reg_addr (inst->ctx->dev->reg_base,VENC_SYS ); ret =vpu_enc_init (&inst->vpu_inst); +if (!inst->vpu_inst.vsi) { +mtk_venc_err (ctx,"share buffer is NULL" ); +kfree (inst); +return -EFAULT ; + }if (MTK_ENC_IOVA_IS_34BIT (ctx)) inst->vsi_34 = (struct venc_h264_vsi_34 *)inst->vpu_inst.vsi;drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c +5
-0@@ -326,6 +326,11 @@ static int vp8_enc_init(struct mtk_vcodec_enc_ctx *ctx) inst->hw_base =mtk_vcodec_get_reg_addr (inst->ctx->dev->reg_base,VENC_LT_SYS ); ret =vpu_enc_init (&inst->vpu_inst); +if (!inst->vpu_inst.vsi) { +mtk_venc_err (ctx,"share buffer is NULL" ); +kfree (inst); +return -EFAULT ; + } inst->vsi = (struct venc_vp8_vsi *)inst->vpu_inst.vsi;
Re: [PATCH 2/2] media: mediatek: vcodec: Handle encoder vsi NULL pointer case
In reply to Irui WangIl 26/09/23 12:19, Irui Wang ha scritto:
Quoted 4 lines
There will be a kernel null pointer exception if 'vsi' is NULL, check 'vsi' is not NULL before assign it to encoder instance.
Signed-off-by Irui Wang <[email protected]>
AngeloGioacchino Del Regno
maintainerRe: [PATCH 2/2] media: mediatek: vcodec: Handle encoder vsi NULL pointer case
Il 02/10/23 12:48, AngeloGioacchino Del Regno ha scritto:
Quoted 8 lines
Il 26/09/23 12:19, Irui Wang ha scritto:
Quoted 4 lines
There will be a kernel null pointer exception if 'vsi' is NULL, check 'vsi' is not NULL before assign it to encoder instance.
Signed-off-by Irui Wang <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>
Sorry I just noticed that there's no Fixes tag.
This commit needs a Fixes tag, please add one and send a v2.
Re: [PATCH 2/2] media: mediatek: vcodec: Handle encoder vsi NULL pointer case
In reply to Irui WangQuoted 14 lines · Irui Wang
There will be a kernel null pointer exception if 'vsi' is NULL, check 'vsi' is not NULL before assign it to encoder instance.
Signed-off-by Irui Wang <[email protected]>--- .../platform/mediatek/vcodec/encoder/venc/venc_h264_if.c | 5 +++++ .../platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c | 5 +++++ 2 files changed, 10 insertions(+)drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +0
-0
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c static int h264_enc_init(struct mtk_vcodec_enc_ctx *ctx) · line 604
Quoted 8 lines
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +5
-0@@ -597,6 +597,11 @@ static int h264_enc_init(struct mtk_vcodec_enc_ctx *ctx) inst->hw_base =mtk_vcodec_get_reg_addr (inst->ctx->dev->reg_base,VENC_SYS ); ret =vpu_enc_init (&inst->vpu_inst); +if (!inst->vpu_inst.vsi) { +mtk_venc_err (ctx,"share buffer is NULL" ); +kfree (inst); +return -EFAULT ; + }
Shouldn't this check be done in vpu_enc_init?
It looks weird that a function can return 0, but there is still an error that needs to be checked manually afterwards.
Regards,
Hans
Quoted 19 lines
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +0
-0if (MTK_ENC_IOVA_IS_34BIT (ctx)) inst->vsi_34 = (struct venc_h264_vsi_34 *)inst->vpu_inst.vsi;drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c +5
-0@@ -326,6 +326,11 @@ static int vp8_enc_init(struct mtk_vcodec_enc_ctx *ctx) inst->hw_base =mtk_vcodec_get_reg_addr (inst->ctx->dev->reg_base,VENC_LT_SYS ); ret =vpu_enc_init (&inst->vpu_inst); +if (!inst->vpu_inst.vsi) { +mtk_venc_err (ctx,"share buffer is NULL" ); +kfree (inst); +return -EFAULT ; + } inst->vsi = (struct venc_vp8_vsi *)inst->vpu_inst.vsi;
Re: [PATCH 2/2] media: mediatek: vcodec: Handle encoder vsi NULL pointer case
Dear Angelo, Hans,
Thanks for your reviewing.
I will send patch v2 with Fix tag...
....
Quoted 40 lines · Hans Verkuil
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 1 line · Irui Wang
There will be a kernel null pointer exception if 'vsi' is NULL,
check
Quoted 5 lines
'vsi' is not NULL before assign it to encoder instance.
Signed-off-by Irui Wang <[email protected]>--- .../platform/mediatek/vcodec/encoder/venc/venc_h264_if.c | 5+++++
Quoted 1 line
.../platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c | 5+++++
Quoted 3 lines
2 files changed, 10 insertions(+)diff --git
a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.cb/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.cQuoted 2 lines
index
a68dac72c4e4..385bcc0d14f3100644
---
a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.cQuoted 1 line
+++
b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.cReview static int h264_enc_init(struct
Quoted 1 line
(quoted diff) +0
-0@@ -597,6 +597,11 @@ static int h264_enc_init(struct
mtk_vcodec_enc_ctx*ctx)Review static int h264_enc_init(struct · line 597
Quoted 1 line
(quoted diff) +0
-0inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx->dev->reg_base,
VENC_SYS);drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c static int h264_enc_init(struct mtk_vcodec_enc_ctx *ctx) · line 604
Quoted 7 lines
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +5
-0ret =vpu_enc_init (&inst->vpu_inst); +if (!inst->vpu_inst.vsi) { +mtk_venc_err (ctx,"share buffer is NULL" ); +kfree (inst); +return -EFAULT ; +}Shouldn't this check be done in
vpu_enc_init?
It looks weird that a function can return 0, but there is still an error that needs to be checked manually afterwards.
Quoted 3 lines
Regards,
Hans
Also, this check will move into vpu_enc_init.
Best Regards
Quoted 27 lines
Quoted 5 lines
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +0
-0if (MTK_ENC_IOVA_IS_34BIT (ctx)) inst->vsi_34 = (struct venc_h264_vsi_34 *)inst->vpu_inst.vsi;diff --git
a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.cb/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.cQuoted 2 lines
index
05abca91e742..23ca0d93324f100644
---
a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.cQuoted 1 line
+++
b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.cReview static int vp8_enc_init(struct
Quoted 1 line
(quoted diff) +0
-0@@ -326,6 +326,11 @@ static int vp8_enc_init(struct
mtk_vcodec_enc_ctx*ctx)Review static int vp8_enc_init(struct · line 326
Quoted 1 line
(quoted diff) +0
-0inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx->dev->reg_base,
VENC_LT_SYS);Quoted 10 lines
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c +5
-0ret =vpu_enc_init (&inst->vpu_inst); +if (!inst->vpu_inst.vsi) { +mtk_venc_err (ctx,"share buffer is NULL" ); +kfree (inst); +return -EFAULT ; +} inst->vsi = (struct venc_vp8_vsi *)inst->vpu_inst.vsi;
Quoted 15 lines · Irui Wang
Need to set the private data with encoder device, or will access NULL pointer in encoder handler.
Fixes 1972e32431ed ("media: mediatek: vcodec: Fix possible invalid memory access for encoder")Signed-off-by Irui Wang <[email protected]>--- drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +0
-0
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c int vpu_enc_init(struct venc_vpu_inst *vpu) · line 145
Quoted 9 lines
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +2
-1@@ -138,7 +138,8 @@ int vpu_enc_init(struct venc_vpu_inst *vpu) vpu->ctx->vpu_inst = vpu; status =mtk_vcodec_fw_ipi_register (vpu->ctx->dev->fw_handler, vpu->id, - vpu_enc_ipi_handler,"venc" ,NULL ); + vpu_enc_ipi_handler,"venc" , + vpu->ctx->dev);if (status) {mtk_venc_err (vpu->ctx,"vpu_ipi_register fail %d" , status);
Is this a fix that should go to 6.6?
Regards,
Hans
Ping! Is this a fix for 6.6 or not?
Regards,
Hans
Quoted 31 lines · Hans Verkuil
Quoted 15 lines · Irui Wang
Need to set the private data with encoder device, or will access NULL pointer in encoder handler.
Fixes 1972e32431ed ("media: mediatek: vcodec: Fix possible invalid memory access for encoder")Signed-off-by Irui Wang <[email protected]>--- drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +0
-0drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c int vpu_enc_init(struct venc_vpu_inst *vpu) · line 145
Quoted 9 lines
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +2
-1@@ -138,7 +138,8 @@ int vpu_enc_init(struct venc_vpu_inst *vpu) vpu->ctx->vpu_inst = vpu; status =mtk_vcodec_fw_ipi_register (vpu->ctx->dev->fw_handler, vpu->id, - vpu_enc_ipi_handler,"venc" ,NULL ); + vpu_enc_ipi_handler,"venc" , + vpu->ctx->dev);if (status) {mtk_venc_err (vpu->ctx,"vpu_ipi_register fail %d" , status);Is this a fix that should go to 6.6?
Regards,
Hans
Quoted 34 lines · Hans Verkuil
Ping! Is this a fix for 6.6 or not?
Regards,
Hans
Quoted 27 lines · Hans Verkuil
Quoted 15 lines · Irui Wang
Need to set the private data with encoder device, or will access NULL pointer in encoder handler.
Fixes 1972e32431ed ("media: mediatek: vcodec: Fix possible invalid memory access for encoder")Signed-off-by Irui Wang <[email protected]>--- drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +0
-0drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c int vpu_enc_init(struct venc_vpu_inst *vpu) · line 145
Quoted 9 lines
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +2
-1@@ -138,7 +138,8 @@ int vpu_enc_init(struct venc_vpu_inst *vpu) vpu->ctx->vpu_inst = vpu; status =mtk_vcodec_fw_ipi_register (vpu->ctx->dev->fw_handler, vpu->id, - vpu_enc_ipi_handler,"venc" ,NULL ); + vpu_enc_ipi_handler,"venc" , + vpu->ctx->dev);if (status) {mtk_venc_err (vpu->ctx,"vpu_ipi_register fail %d" , status);Is this a fix that should go to 6.6?
This looks like a real bug, so I'll queue this up for 6.6.
Regards,
Hans
Dear Hans,
Sorry for late response, we have just returned to office after vacation. Yes, it's a fix and thank you very much for accepting it.
Best Regards
Quoted 51 lines · Hans Verkuil
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 12 lines · Hans Verkuil
Ping! Is this a fix for 6.6 or not?
Regards,
Hans
Quoted 5 lines · Hans Verkuil
Quoted 4 lines · Irui Wang
Need to set the private data with encoder device, or will access NULL pointer in encoder handler.
Fixes 1972e32431ed ("media: mediatek: vcodec: Fix possibleinvalid memory access for encoder")
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Signed-off-by Irui Wang <[email protected]>--- drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c | 3++-
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
1 file changed, 2 insertions(+), 1 deletion(-)diff --git
a/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.cb/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.cQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
index
d299cc2962a5..ae6290d28f8e100644
---
a/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.cQuoted 1 line
Quoted 1 line
Quoted 1 line
+++
b/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.cQuoted 4 lines
Quoted 4 lines
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c int vpu_enc_init(struct venc_vpu_inst *vpu) · line 140
Quoted 4 lines
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +0
-0@@ -138,7 +138,8 @@ int vpu_enc_init(struct venc_vpu_inst *vpu) vpu->ctx->vpu_inst = vpu; status = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler,
vpu->id,Quoted 8 lines
Quoted 8 lines
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c int vpu_enc_init(struct venc_vpu_inst *vpu) · line 145
Quoted 6 lines
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +2
-1- vpu_enc_ipi_handler, "venc", NULL); + vpu_enc_ipi_handler,"venc" , + vpu->ctx->dev);if (status) {mtk_venc_err (vpu->ctx,"vpu_ipi_register fail %d" , status);Is this a fix that should go to 6.6?
This looks like a real bug, so I'll queue this up for 6.6.
Regards,
Hans
Il 26/09/23 12:19, Irui Wang ha scritto:
Quoted 6 lines
Need to set the private data with encoder device, or will access NULL pointer in encoder handler.
Fixes 1972e32431ed ("media: mediatek: vcodec: Fix possible invalid memory access for encoder")Signed-off-by Irui Wang <[email protected]>