Blame SOURCES/CVE-2022-22942.patch

c6ac4c
From 05639043d88c1ed4c13670721d222b8621d2fbca Mon Sep 17 00:00:00 2001
c6ac4c
From: Joe Lawrence <joe.lawrence@redhat.com>
c6ac4c
Date: Wed, 9 Feb 2022 13:27:43 -0500
c6ac4c
Subject: [KPATCH CVE-2022-22942] drm/vmwgfx: kpatch fixes for CVE-2022-22942
c6ac4c
c6ac4c
Kernels:
c6ac4c
3.10.0-1160.21.1.el7
c6ac4c
3.10.0-1160.24.1.el7
c6ac4c
3.10.0-1160.25.1.el7
c6ac4c
3.10.0-1160.31.1.el7
c6ac4c
3.10.0-1160.36.2.el7
c6ac4c
3.10.0-1160.41.1.el7
c6ac4c
3.10.0-1160.42.2.el7
c6ac4c
3.10.0-1160.45.1.el7
c6ac4c
3.10.0-1160.49.1.el7
c6ac4c
3.10.0-1160.53.1.el7
c6ac4c
c6ac4c
Changes since last build:
c6ac4c
arches: x86_64
c6ac4c
vmwgfx_execbuf.o: changed function: vmw_execbuf_copy_fence_user
c6ac4c
vmwgfx_execbuf.o: changed function: vmw_execbuf_process
c6ac4c
vmwgfx_fence.o: changed function: vmw_fence_event_ioctl
c6ac4c
vmwgfx_kms.o: changed function: vmw_kms_helper_validation_finish
c6ac4c
---------------------------
c6ac4c
c6ac4c
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-7/-/merge_requests/23
c6ac4c
Approved-by: Yannick Cote (@ycote1)
c6ac4c
Approved-by: Artem Savkov (@artem.savkov)
c6ac4c
Kernels:
c6ac4c
3.10.0-1160.21.1.el7
c6ac4c
3.10.0-1160.24.1.el7
c6ac4c
3.10.0-1160.25.1.el7
c6ac4c
3.10.0-1160.31.1.el7
c6ac4c
3.10.0-1160.36.2.el7
c6ac4c
3.10.0-1160.41.1.el7
c6ac4c
3.10.0-1160.42.2.el7
c6ac4c
3.10.0-1160.45.1.el7
c6ac4c
3.10.0-1160.49.1.el7
c6ac4c
3.10.0-1160.53.1.el7
c6ac4c
c6ac4c
Modifications: none
c6ac4c
c6ac4c
commit 26695bc7aeaf0bae32d7ab7fcf8950143acb5020
c6ac4c
Author: Dave Airlie <airlied@redhat.com>
c6ac4c
Date:   Sat Jan 29 02:36:46 2022 -0500
c6ac4c
c6ac4c
    drm/vmwgfx: Fix stale file descriptors on failed usercopy
c6ac4c
c6ac4c
    Bugzilla: http://bugzilla.redhat.com/2047597
c6ac4c
    CVE: CVE-2022-22942
c6ac4c
c6ac4c
    commit a0f90c8815706981c483a652a6aefca51a5e191c
c6ac4c
    Author: Mathias Krause <minipli@grsecurity.net>
c6ac4c
    Date:   Thu Jan 27 18:34:19 2022 +1000
c6ac4c
c6ac4c
        drm/vmwgfx: Fix stale file descriptors on failed usercopy
c6ac4c
c6ac4c
        A failing usercopy of the fence_rep object will lead to a stale entry in
c6ac4c
        the file descriptor table as put_unused_fd() won't release it. This
c6ac4c
        enables userland to refer to a dangling 'file' object through that still
c6ac4c
        valid file descriptor, leading to all kinds of use-after-free
c6ac4c
        exploitation scenarios.
c6ac4c
c6ac4c
        Fix this by deferring the call to fd_install() until after the usercopy
c6ac4c
        has succeeded.
c6ac4c
c6ac4c
        Fixes: c906965dee22 ("drm/vmwgfx: Add export fence to file descriptor support")
c6ac4c
        Signed-off-by: Mathias Krause <minipli@grsecurity.net>
c6ac4c
        Signed-off-by: Zack Rusin <zackr@vmware.com>
c6ac4c
        Signed-off-by: Dave Airlie <airlied@redhat.com>
c6ac4c
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
c6ac4c
c6ac4c
    Signed-off-by: Dave Airlie <airlied@redhat.com>
c6ac4c
c6ac4c
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
c6ac4c
---
c6ac4c
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h     |  5 ++--
c6ac4c
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 34 ++++++++++++-------------
c6ac4c
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.c   |  2 +-
c6ac4c
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c     |  2 +-
c6ac4c
 4 files changed, 21 insertions(+), 22 deletions(-)
c6ac4c
c6ac4c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
c6ac4c
index cd607ba9c2fe..efd540f02227 100644
c6ac4c
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
c6ac4c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
c6ac4c
@@ -924,15 +924,14 @@ extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
c6ac4c
 				      struct vmw_private *dev_priv,
c6ac4c
 				      struct vmw_fence_obj **p_fence,
c6ac4c
 				      uint32_t *p_handle);
c6ac4c
-extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
c6ac4c
+extern int vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
c6ac4c
 					struct vmw_fpriv *vmw_fp,
c6ac4c
 					int ret,
c6ac4c
 					struct drm_vmw_fence_rep __user
c6ac4c
 					*user_fence_rep,
c6ac4c
 					struct vmw_fence_obj *fence,
c6ac4c
 					uint32_t fence_handle,
c6ac4c
-					int32_t out_fence_fd,
c6ac4c
-					struct sync_file *sync_file);
c6ac4c
+					int32_t out_fence_fd);
c6ac4c
 bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
c6ac4c
 
c6ac4c
 /**
c6ac4c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
c6ac4c
index 88b8178d4687..4f792fb89bb8 100644
c6ac4c
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
c6ac4c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
c6ac4c
@@ -3595,20 +3595,19 @@ int vmw_execbuf_fence_commands(struct drm_file *file_priv,
c6ac4c
  * object so we wait for it immediately, and then unreference the
c6ac4c
  * user-space reference.
c6ac4c
  */
c6ac4c
-void
c6ac4c
+int
c6ac4c
 vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
c6ac4c
 			    struct vmw_fpriv *vmw_fp,
c6ac4c
 			    int ret,
c6ac4c
 			    struct drm_vmw_fence_rep __user *user_fence_rep,
c6ac4c
 			    struct vmw_fence_obj *fence,
c6ac4c
 			    uint32_t fence_handle,
c6ac4c
-			    int32_t out_fence_fd,
c6ac4c
-			    struct sync_file *sync_file)
c6ac4c
+			    int32_t out_fence_fd)
c6ac4c
 {
c6ac4c
 	struct drm_vmw_fence_rep fence_rep;
c6ac4c
 
c6ac4c
 	if (user_fence_rep == NULL)
c6ac4c
-		return;
c6ac4c
+		return 0;
c6ac4c
 
c6ac4c
 	memset(&fence_rep, 0, sizeof(fence_rep));
c6ac4c
 
c6ac4c
@@ -3636,20 +3635,14 @@ vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
c6ac4c
 	 * and unreference the handle.
c6ac4c
 	 */
c6ac4c
 	if (unlikely(ret != 0) && (fence_rep.error == 0)) {
c6ac4c
-		if (sync_file)
c6ac4c
-			fput(sync_file->file);
c6ac4c
-
c6ac4c
-		if (fence_rep.fd != -1) {
c6ac4c
-			put_unused_fd(fence_rep.fd);
c6ac4c
-			fence_rep.fd = -1;
c6ac4c
-		}
c6ac4c
-
c6ac4c
 		ttm_ref_object_base_unref(vmw_fp->tfile,
c6ac4c
 					  fence_handle, TTM_REF_USAGE);
c6ac4c
 		DRM_ERROR("Fence copy error. Syncing.\n");
c6ac4c
 		(void) vmw_fence_obj_wait(fence, false, false,
c6ac4c
 					  VMW_FENCE_WAIT_TIMEOUT);
c6ac4c
 	}
c6ac4c
+
c6ac4c
+	return ret ? -EFAULT : 0;
c6ac4c
 }
c6ac4c
 
c6ac4c
 /**
c6ac4c
@@ -3997,16 +3990,23 @@ int vmw_execbuf_process(struct drm_file *file_priv,
c6ac4c
 
c6ac4c
 			(void) vmw_fence_obj_wait(fence, false, false,
c6ac4c
 						  VMW_FENCE_WAIT_TIMEOUT);
c6ac4c
+		}
c6ac4c
+	}
c6ac4c
+
c6ac4c
+	ret = vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), ret,
c6ac4c
+				    user_fence_rep, fence, handle, out_fence_fd);
c6ac4c
+
c6ac4c
+	if (sync_file) {
c6ac4c
+		if (ret) {
c6ac4c
+			/* usercopy of fence failed, put the file object */
c6ac4c
+			fput(sync_file->file);
c6ac4c
+			put_unused_fd(out_fence_fd);
c6ac4c
 		} else {
c6ac4c
 			/* Link the fence with the FD created earlier */
c6ac4c
 			fd_install(out_fence_fd, sync_file->file);
c6ac4c
 		}
c6ac4c
 	}
c6ac4c
 
c6ac4c
-	vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), ret,
c6ac4c
-				    user_fence_rep, fence, handle,
c6ac4c
-				    out_fence_fd, sync_file);
c6ac4c
-
c6ac4c
 	/* Don't unreference when handing fence out */
c6ac4c
 	if (unlikely(out_fence != NULL)) {
c6ac4c
 		*out_fence = fence;
c6ac4c
@@ -4024,7 +4024,7 @@ int vmw_execbuf_process(struct drm_file *file_priv,
c6ac4c
 	 */
c6ac4c
 	vmw_validation_unref_lists(&val_ctx);
c6ac4c
 
c6ac4c
-	return 0;
c6ac4c
+	return ret;
c6ac4c
 
c6ac4c
 out_unlock_binding:
c6ac4c
 	mutex_unlock(&dev_priv->binding_mutex);
c6ac4c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
c6ac4c
index 301260e23e52..624754cc4fc1 100644
c6ac4c
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
c6ac4c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
c6ac4c
@@ -1167,7 +1167,7 @@ int vmw_fence_event_ioctl(struct drm_device *dev, void *data,
c6ac4c
 	}
c6ac4c
 
c6ac4c
 	vmw_execbuf_copy_fence_user(dev_priv, vmw_fp, 0, user_fence_rep, fence,
c6ac4c
-				    handle, -1, NULL);
c6ac4c
+				    handle, -1);
c6ac4c
 	vmw_fence_obj_unreference(&fence);
c6ac4c
 	return 0;
c6ac4c
 out_no_create:
c6ac4c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
c6ac4c
index ed2f67822f45..fdf58090aa4a 100644
c6ac4c
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
c6ac4c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
c6ac4c
@@ -2565,7 +2565,7 @@ void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv,
c6ac4c
 	if (file_priv)
c6ac4c
 		vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv),
c6ac4c
 					    ret, user_fence_rep, fence,
c6ac4c
-					    handle, -1, NULL);
c6ac4c
+					    handle, -1);
c6ac4c
 	if (out_fence)
c6ac4c
 		*out_fence = fence;
c6ac4c
 	else
c6ac4c
-- 
c6ac4c
2.26.3
c6ac4c
c6ac4c