]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drm/amdgpu: validate user pitch alignment
authorYu Zhao <yuzhao@google.com>
Mon, 7 Jan 2019 22:51:14 +0000 (15:51 -0700)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 8 Jan 2019 21:26:41 +0000 (16:26 -0500)
Userspace may request pitch alignment that is not supported by GPU.
Some requests 32, but GPU ignores it and uses default 64 when cpp is
4. If GEM object is allocated based on the smaller alignment, GPU
DMA will go out of bound.

Cc: stable@vger.kernel.org # v4.2+
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Yu Zhao <yuzhao@google.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c

index b083b219b1a966e9e38c318cb30c91e478f650c7..cb72d9675ab18600197b32c30a5298f1369307ca 100644 (file)
@@ -531,6 +531,16 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev,
        struct drm_gem_object *obj;
        struct amdgpu_framebuffer *amdgpu_fb;
        int ret;
+       struct amdgpu_device *adev = dev->dev_private;
+       int cpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);
+       int pitch = mode_cmd->pitches[0] / cpp;
+
+       pitch = amdgpu_align_pitch(adev, pitch, cpp, false);
+       if (mode_cmd->pitches[0] != pitch) {
+               DRM_DEBUG_KMS("Invalid pitch: expecting %d but got %d\n",
+                             pitch, mode_cmd->pitches[0]);
+               return ERR_PTR(-EINVAL);
+       }
 
        obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[0]);
        if (obj ==  NULL) {