Skip to contentSkip to conversation

media: qcom: venus: Fix a possible null-pointer dereference in vdec_g_fmt()

PATCH In review Jia-Ju Bai 2 participants 2 messages Jul 27, 2019 – Mar 13, 2020

Subsystems (4)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 media: qcom: venus: Fix a possible null-pointer dereference in vdec_g_fmt()

In vdec_g_fmt(), fmt is firstly assigned NULL, and it could be never assigned before being used on line 223:

    pixmp->pixelformat = fmt->pixfmt;

Thus, a possible null-pointer dereference may occur.

To fix this bug, fmt is checked before being used here.

This bug is found by a static analysis tool STCheck written by us.

---
 drivers/media/platform/qcom/venus/vdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/venus/vdec.c +2 -1
index e1f998656c07..12c31551f191 100644
@@ -211,7 +211,8 @@ static int vdec_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
 		inst->height = format.fmt.pix_mp.height;
 	}
 
-	pixmp->pixelformat = fmt->pixfmt;
+	if (fmt)
+		pixmp->pixelformat = fmt->pixfmt;
 
 	if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
 		pixmp->width = inst->width;
Signature · 1 line
2.17.0
#1 lore raw

This patch fell between the cracks, but while cleaning up patchwork it popped up again :-)

Quoted 7 lines · Jia-Ju Bai

In vdec_g_fmt(), fmt is firstly assigned NULL, and it could be never assigned before being used on line 223:

    pixmp->pixelformat = fmt->pixfmt;

Thus, a possible null-pointer dereference may occur.

To fix this bug, fmt is checked before being used here.

Actually, this function can only be called for f->type values V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE or V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE.

The easiest way to fix this is to replace this:

        if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
                fmt = inst->fmt_cap;
        else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
                fmt = inst->fmt_out;

by:

        if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
                fmt = inst->fmt_cap;
        else
                fmt = inst->fmt_out;

And the same in a bit lower down in this function.

Regards,

Hans

Quoted 23 lines

This bug is found by a static analysis tool STCheck written by us.

---
 drivers/media/platform/qcom/venus/vdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/venus/vdec.c +2 -1
index e1f998656c07..12c31551f191 100644
@@ -211,7 +211,8 @@ static int vdec_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
 		inst->height = format.fmt.pix_mp.height;
 	}
 
-	pixmp->pixelformat = fmt->pixfmt;
+	if (fmt)
+		pixmp->pixelformat = fmt->pixfmt;
 
 	if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
 		pixmp->width = inst->width;