Skip to content

Commit f8bcaf7

Browse files
Hans Verkuilmchehab
authored andcommitted
media: vivid: s_fbuf: add more sanity checks
VIDIOC_S_FBUF is by definition a scary ioctl, which is why only root can use it. But at least check if the framebuffer parameters match that of one of the framebuffer created by vivid, and reject anything else. Signed-off-by: Hans Verkuil <[email protected]> Fixes: ef834f7 ([media] vivid: add the video capture and output parts) Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 247f34f commit f8bcaf7

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

drivers/media/test-drivers/vivid/vivid-core.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,28 @@ static int vidioc_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *a
339339
return vivid_vid_out_g_fbuf(file, fh, a);
340340
}
341341

342+
/*
343+
* Only support the framebuffer of one of the vivid instances.
344+
* Anything else is rejected.
345+
*/
346+
bool vivid_validate_fb(const struct v4l2_framebuffer *a)
347+
{
348+
struct vivid_dev *dev;
349+
int i;
350+
351+
for (i = 0; i < n_devs; i++) {
352+
dev = vivid_devs[i];
353+
if (!dev || !dev->video_pbase)
354+
continue;
355+
if ((unsigned long)a->base == dev->video_pbase &&
356+
a->fmt.width <= dev->display_width &&
357+
a->fmt.height <= dev->display_height &&
358+
a->fmt.bytesperline <= dev->display_byte_stride)
359+
return true;
360+
}
361+
return false;
362+
}
363+
342364
static int vidioc_s_fbuf(struct file *file, void *fh, const struct v4l2_framebuffer *a)
343365
{
344366
struct video_device *vdev = video_devdata(file);

drivers/media/test-drivers/vivid/vivid-core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,6 @@ static inline bool vivid_is_hdmi_out(const struct vivid_dev *dev)
613613
return dev->output_type[dev->output] == HDMI;
614614
}
615615

616+
bool vivid_validate_fb(const struct v4l2_framebuffer *a);
617+
616618
#endif

drivers/media/test-drivers/vivid/vivid-vid-cap.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,14 @@ int vivid_vid_cap_s_fbuf(struct file *file, void *fh,
12761276
return -EINVAL;
12771277
if (a->fmt.bytesperline < (a->fmt.width * fmt->bit_depth[0]) / 8)
12781278
return -EINVAL;
1279-
if (a->fmt.height * a->fmt.bytesperline < a->fmt.sizeimage)
1279+
if (a->fmt.bytesperline > a->fmt.sizeimage / a->fmt.height)
1280+
return -EINVAL;
1281+
1282+
/*
1283+
* Only support the framebuffer of one of the vivid instances.
1284+
* Anything else is rejected.
1285+
*/
1286+
if (!vivid_validate_fb(a))
12801287
return -EINVAL;
12811288

12821289
dev->fb_vbase_cap = phys_to_virt((unsigned long)a->base);

0 commit comments

Comments
 (0)