brcm2708: update linux 4.4 patches to latest version
[openwrt/staging/lynxis/omap.git] / target / linux / brcm2708 / patches-4.4 / 0317-videobuf2-v4l2-Verify-planes-array-in-buffer-dequeue.patch
1 From b9e91e565c8c05abec932a3d1bcb9bab81570ad6 Mon Sep 17 00:00:00 2001
2 From: Sakari Ailus <sakari.ailus@linux.intel.com>
3 Date: Sun, 3 Apr 2016 16:31:03 -0300
4 Subject: [PATCH 317/423] videobuf2-v4l2: Verify planes array in buffer
5 dequeueing
6
7 commit 2c1f6951a8a82e6de0d82b1158b5e493fc6c54ab upstream.
8
9 When a buffer is being dequeued using VIDIOC_DQBUF IOCTL, the exact buffer
10 which will be dequeued is not known until the buffer has been removed from
11 the queue. The number of planes is specific to a buffer, not to the queue.
12
13 This does lead to the situation where multi-plane buffers may be requested
14 and queued with n planes, but VIDIOC_DQBUF IOCTL may be passed an argument
15 struct with fewer planes.
16
17 __fill_v4l2_buffer() however uses the number of planes from the dequeued
18 videobuf2 buffer, overwriting kernel memory (the m.planes array allocated
19 in video_usercopy() in v4l2-ioctl.c) if the user provided fewer
20 planes than the dequeued buffer had. Oops!
21
22 Fixes: b0e0e1f83de3 ("[media] media: videobuf2: Prepare to divide videobuf2")
23
24 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
25 Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
26 Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 ---
29 drivers/media/v4l2-core/videobuf2-v4l2.c | 6 ++++++
30 1 file changed, 6 insertions(+)
31
32 --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
33 +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
34 @@ -67,6 +67,11 @@ static int __verify_planes_array(struct
35 return 0;
36 }
37
38 +static int __verify_planes_array_core(struct vb2_buffer *vb, const void *pb)
39 +{
40 + return __verify_planes_array(vb, pb);
41 +}
42 +
43 /**
44 * __verify_length() - Verify that the bytesused value for each plane fits in
45 * the plane length and that the data offset doesn't exceed the bytesused value.
46 @@ -432,6 +437,7 @@ static int __fill_vb2_buffer(struct vb2_
47 }
48
49 static const struct vb2_buf_ops v4l2_buf_ops = {
50 + .verify_planes_array = __verify_planes_array_core,
51 .fill_user_buffer = __fill_v4l2_buffer,
52 .fill_vb2_buffer = __fill_vb2_buffer,
53 .set_timestamp = __set_timestamp,