Blame SOURCES/CVE-2022-22942.patch

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