4b716b2
From: Eric Anholt <eric@anholt.net>
4b716b2
To: dri-devel@lists.freedesktop.org
4b716b2
Subject: [PATCH 1/2] drm/vc4: Fix an integer overflow in temporary
4b716b2
 allocation layout.
4b716b2
Date: Wed, 18 Jan 2017 07:20:49 +1100
4b716b2
4b716b2
We copy the unvalidated ioctl arguments from the user into kernel
4b716b2
temporary memory to run the validation from, to avoid a race where the
4b716b2
user updates the unvalidate contents in between validating them and
4b716b2
copying them into the validated BO.
4b716b2
4b716b2
However, in setting up the layout of the kernel side, we failed to
4b716b2
check one of the additions (the roundup() for shader_rec_offset)
4b716b2
against integer overflow, allowing a nearly MAX_UINT value of
4b716b2
bin_cl_size to cause us to under-allocate the temporary space that we
4b716b2
then copy_from_user into.
4b716b2
4b716b2
Reported-by: Murray McAllister <murray.mcallister@insomniasec.com>
4b716b2
Signed-off-by: Eric Anholt <eric@anholt.net>
4b716b2
Fixes: d5b1a78a772f ("drm/vc4: Add support for drawing 3D frames.")
4b716b2
---
4b716b2
 drivers/gpu/drm/vc4/vc4_gem.c | 3 ++-
4b716b2
 1 file changed, 2 insertions(+), 1 deletion(-)
4b716b2
4b716b2
diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c
4b716b2
index db920771bfb5..c5fe3554858e 100644
4b716b2
--- a/drivers/gpu/drm/vc4/vc4_gem.c
4b716b2
+++ b/drivers/gpu/drm/vc4/vc4_gem.c
4b716b2
@@ -594,7 +594,8 @@ vc4_get_bcl(struct drm_device *dev, struct vc4_exec_info *exec)
4b716b2
 					  args->shader_rec_count);
4b716b2
 	struct vc4_bo *bo;
4b716b2
 
4b716b2
-	if (uniforms_offset < shader_rec_offset ||
4b716b2
+	if (shader_rec_offset < args->bin_cl_size ||
4b716b2
+	    uniforms_offset < shader_rec_offset ||
4b716b2
 	    exec_size < uniforms_offset ||
4b716b2
 	    args->shader_rec_count >= (UINT_MAX /
4b716b2
 					  sizeof(struct vc4_shader_state)) ||
4b716b2
-- 
4b716b2
2.11.0
4b716b2
4b716b2
_______________________________________________
4b716b2
dri-devel mailing list
4b716b2
dri-devel@lists.freedesktop.org
4b716b2
https://lists.freedesktop.org/mailman/listinfo/dri-devel
4b716b2
4b716b2
From: Eric Anholt <eric@anholt.net>
4b716b2
To: dri-devel@lists.freedesktop.org
4b716b2
Subject: [PATCH 2/2] drm/vc4: Return -EINVAL on the overflow checks failing.
4b716b2
Date: Wed, 18 Jan 2017 07:20:50 +1100
4b716b2
4b716b2
By failing to set the errno, we'd continue on to trying to set up the
4b716b2
RCL, and then oops on trying to dereference the tile_bo that binning
4b716b2
validation should have set up.
4b716b2
4b716b2
Reported-by: Ingo Molnar <mingo@kernel.org>
4b716b2
Signed-off-by: Eric Anholt <eric@anholt.net>
4b716b2
Fixes: d5b1a78a772f ("drm/vc4: Add support for drawing 3D frames.")
4b716b2
---
4b716b2
 drivers/gpu/drm/vc4/vc4_gem.c | 1 +
4b716b2
 1 file changed, 1 insertion(+)
4b716b2
4b716b2
diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c
4b716b2
index c5fe3554858e..ab3016982466 100644
4b716b2
--- a/drivers/gpu/drm/vc4/vc4_gem.c
4b716b2
+++ b/drivers/gpu/drm/vc4/vc4_gem.c
4b716b2
@@ -601,6 +601,7 @@ vc4_get_bcl(struct drm_device *dev, struct vc4_exec_info *exec)
4b716b2
 					  sizeof(struct vc4_shader_state)) ||
4b716b2
 	    temp_size < exec_size) {
4b716b2
 		DRM_ERROR("overflow in exec arguments\n");
4b716b2
+		ret = -EINVAL;
4b716b2
 		goto fail;
4b716b2
 	}
4b716b2
 
4b716b2
-- 
4b716b2
2.11.0
4b716b2
4b716b2
_______________________________________________
4b716b2
dri-devel mailing list
4b716b2
dri-devel@lists.freedesktop.org
4b716b2
https://lists.freedesktop.org/mailman/listinfo/dri-devel
4b716b2