Skip to contentSkip to conversation

vb2: check for sane values from queue_setup

PATCH In review Johan Fjeldtvedt 2 participants 2 messages Sep 17, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 vb2: check for sane values from queue_setup

Warn and return error from the reqbufs ioctl when driver sets 0 number of planes or 0 as plane sizes, as these values don't make any sense. Checking this here stops obviously wrong values from propagating further and causing various problems that are hard to trace back to either of these values being 0.

---
 drivers/media/common/videobuf2/videobuf2-core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/media/common/videobuf2/videobuf2-core.c +9 -0
index f32ec7342ef0..14cedf42e907 100644
@@ -661,6 +661,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 {
 	unsigned int num_buffers, allocated_buffers, num_planes = 0;
 	unsigned plane_sizes[VB2_MAX_PLANES] = { };
+	unsigned int i;
 	int ret;
 
 	if (q->streaming) {
@@ -718,6 +719,14 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	if (ret)
 		return ret;
 
+	/* Check that driver has set sane values */
+	if (WARN_ON(!num_planes))
+		return -EINVAL;
+
+	for (i = 0; i < num_planes; i++)
+		if (WARN_ON(!plane_sizes[i]))
+			return -EINVAL;
+
 	/* Finally, allocate buffers and video memory */
 	allocated_buffers =
 		__vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 7 lines · Johan Fjeldtvedt

Warn and return error from the reqbufs ioctl when driver sets 0 number of planes or 0 as plane sizes, as these values don't make any sense. Checking this here stops obviously wrong values from propagating further and causing various problems that are hard to trace back to either of these values being 0.

FYI: next time when you post a new version of a patch don't forget to add any Acked-by's or Reviewed-by's that others added to previous versions.

I'll add Sakari's Acked-by, so no need for a v6 :-)

Regards,

Hans

Quoted 32 lines
---
 drivers/media/common/videobuf2/videobuf2-core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/media/common/videobuf2/videobuf2-core.c +9 -0
index f32ec7342ef0..14cedf42e907 100644
@@ -661,6 +661,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 {
 	unsigned int num_buffers, allocated_buffers, num_planes = 0;
 	unsigned plane_sizes[VB2_MAX_PLANES] = { };
+	unsigned int i;
 	int ret;
 
 	if (q->streaming) {
@@ -718,6 +719,14 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	if (ret)
 		return ret;
 
+	/* Check that driver has set sane values */
+	if (WARN_ON(!num_planes))
+		return -EINVAL;
+
+	for (i = 0; i < num_planes; i++)
+		if (WARN_ON(!plane_sizes[i]))
+			return -EINVAL;
+
 	/* Finally, allocate buffers and video memory */
 	allocated_buffers =
 		__vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes);