Blame SOURCES/CVE-2022-22942.patch

23221e
From 73c1db23af5c7364af380d21739a6e1220a2490d Mon Sep 17 00:00:00 2001
23221e
From: Joe Lawrence <joe.lawrence@redhat.com>
23221e
Date: Tue, 1 Mar 2022 15:34:07 -0500
23221e
Subject: [KPATCH CVE-2022-22942] drm/vmwgfx: kpatch fixes for CVE-2022-22942
23221e
23221e
Kernels:
23221e
4.18.0-348.el8
23221e
4.18.0-348.2.1.el8_5
23221e
4.18.0-348.7.1.el8_5
23221e
4.18.0-348.12.2.el8_5
23221e
23221e
Changes since last build:
23221e
arches: x86_64
23221e
vmwgfx_execbuf.o: changed function: vmw_execbuf_copy_fence_user
23221e
vmwgfx_execbuf.o: changed function: vmw_execbuf_process
23221e
vmwgfx_fence.o: changed function: vmw_fence_event_ioctl
23221e
vmwgfx_kms.o: changed function: vmw_kms_helper_validation_finish
23221e
---------------------------
23221e
23221e
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-8/-/merge_requests/32
23221e
Approved-by: Yannick Cote (@ycote1)
23221e
Kernels:
23221e
4.18.0-348.el8
23221e
4.18.0-348.2.1.el8_5
23221e
4.18.0-348.7.1.el8_5
23221e
4.18.0-348.12.2.el8_5
23221e
23221e
Modifications: none
23221e
23221e
commit 1b221c65601c93cb4ad2b24487c0015d6bae7c7f
23221e
Author: Dave Airlie <airlied@redhat.com>
23221e
Date:   Fri Jan 28 16:36:48 2022 -0500
23221e
23221e
    drm/vmwgfx: Fix stale file descriptors on failed usercopy
23221e
23221e
    Bugzilla: https://bugzilla.redhat.com/2047601
23221e
    CVE: CVE-2022-22942
23221e
    Y-Commit: b6793b842fba127aa491384431e84b79c7619afd
23221e
23221e
    O-Bugzilla: http://bugzilla.redhat.com/2047602
23221e
    O-CVE: CVE-2022-22942
23221e
23221e
    commit a0f90c8815706981c483a652a6aefca51a5e191c
23221e
    Author: Mathias Krause <minipli@grsecurity.net>
23221e
    Date:   Thu Jan 27 18:34:19 2022 +1000
23221e
23221e
        drm/vmwgfx: Fix stale file descriptors on failed usercopy
23221e
23221e
        A failing usercopy of the fence_rep object will lead to a stale entry in
23221e
        the file descriptor table as put_unused_fd() won't release it. This
23221e
        enables userland to refer to a dangling 'file' object through that still
23221e
        valid file descriptor, leading to all kinds of use-after-free
23221e
        exploitation scenarios.
23221e
23221e
        Fix this by deferring the call to fd_install() until after the usercopy
23221e
        has succeeded.
23221e
23221e
        Fixes: c906965dee22 ("drm/vmwgfx: Add export fence to file descriptor support")
23221e
        Signed-off-by: Mathias Krause <minipli@grsecurity.net>
23221e
        Signed-off-by: Zack Rusin <zackr@vmware.com>
23221e
        Signed-off-by: Dave Airlie <airlied@redhat.com>
23221e
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
23221e
23221e
    Signed-off-by: Dave Airlie <airlied@redhat.com>
23221e
    Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
23221e
23221e
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
23221e
---
23221e
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h     |  5 ++--
23221e
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 33 +++++++++++++------------
23221e
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.c   |  2 +-
23221e
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c     |  2 +-
23221e
 4 files changed, 21 insertions(+), 21 deletions(-)
23221e
23221e
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
23221e
index eb76a6b9ebca..2f4f39446240 100644
23221e
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
23221e
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
23221e
@@ -1069,15 +1069,14 @@ extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
23221e
 				      struct vmw_private *dev_priv,
23221e
 				      struct vmw_fence_obj **p_fence,
23221e
 				      uint32_t *p_handle);
23221e
-extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
23221e
+extern int vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
23221e
 					struct vmw_fpriv *vmw_fp,
23221e
 					int ret,
23221e
 					struct drm_vmw_fence_rep __user
23221e
 					*user_fence_rep,
23221e
 					struct vmw_fence_obj *fence,
23221e
 					uint32_t fence_handle,
23221e
-					int32_t out_fence_fd,
23221e
-					struct sync_file *sync_file);
23221e
+					int32_t out_fence_fd);
23221e
 bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
23221e
 
23221e
 /**
23221e
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
23221e
index 462f17320708..399cb4cce292 100644
23221e
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
23221e
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
23221e
@@ -3804,17 +3804,17 @@ int vmw_execbuf_fence_commands(struct drm_file *file_priv,
23221e
  * Also if copying fails, user-space will be unable to signal the fence object
23221e
  * so we wait for it immediately, and then unreference the user-space reference.
23221e
  */
23221e
-void
23221e
+int
23221e
 vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
23221e
 			    struct vmw_fpriv *vmw_fp, int ret,
23221e
 			    struct drm_vmw_fence_rep __user *user_fence_rep,
23221e
 			    struct vmw_fence_obj *fence, uint32_t fence_handle,
23221e
-			    int32_t out_fence_fd, struct sync_file *sync_file)
23221e
+			    int32_t out_fence_fd)
23221e
 {
23221e
 	struct drm_vmw_fence_rep fence_rep;
23221e
 
23221e
 	if (user_fence_rep == NULL)
23221e
-		return;
23221e
+		return 0;
23221e
 
23221e
 	memset(&fence_rep, 0, sizeof(fence_rep));
23221e
 
23221e
@@ -3842,20 +3842,14 @@ vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
23221e
 	 * handle.
23221e
 	 */
23221e
 	if (unlikely(ret != 0) && (fence_rep.error == 0)) {
23221e
-		if (sync_file)
23221e
-			fput(sync_file->file);
23221e
-
23221e
-		if (fence_rep.fd != -1) {
23221e
-			put_unused_fd(fence_rep.fd);
23221e
-			fence_rep.fd = -1;
23221e
-		}
23221e
-
23221e
 		ttm_ref_object_base_unref(vmw_fp->tfile, fence_handle,
23221e
 					  TTM_REF_USAGE);
23221e
 		VMW_DEBUG_USER("Fence copy error. Syncing.\n");
23221e
 		(void) vmw_fence_obj_wait(fence, false, false,
23221e
 					  VMW_FENCE_WAIT_TIMEOUT);
23221e
 	}
23221e
+
23221e
+	return ret ? -EFAULT : 0;
23221e
 }
23221e
 
23221e
 /**
23221e
@@ -4193,16 +4187,23 @@ int vmw_execbuf_process(struct drm_file *file_priv,
23221e
 
23221e
 			(void) vmw_fence_obj_wait(fence, false, false,
23221e
 						  VMW_FENCE_WAIT_TIMEOUT);
23221e
+		}
23221e
+	}
23221e
+
23221e
+	ret = vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), ret,
23221e
+				    user_fence_rep, fence, handle, out_fence_fd);
23221e
+
23221e
+	if (sync_file) {
23221e
+		if (ret) {
23221e
+			/* usercopy of fence failed, put the file object */
23221e
+			fput(sync_file->file);
23221e
+			put_unused_fd(out_fence_fd);
23221e
 		} else {
23221e
 			/* Link the fence with the FD created earlier */
23221e
 			fd_install(out_fence_fd, sync_file->file);
23221e
 		}
23221e
 	}
23221e
 
23221e
-	vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), ret,
23221e
-				    user_fence_rep, fence, handle, out_fence_fd,
23221e
-				    sync_file);
23221e
-
23221e
 	/* Don't unreference when handing fence out */
23221e
 	if (unlikely(out_fence != NULL)) {
23221e
 		*out_fence = fence;
23221e
@@ -4220,7 +4221,7 @@ int vmw_execbuf_process(struct drm_file *file_priv,
23221e
 	 */
23221e
 	vmw_validation_unref_lists(&val_ctx);
23221e
 
23221e
-	return 0;
23221e
+	return ret;
23221e
 
23221e
 out_unlock_binding:
23221e
 	mutex_unlock(&dev_priv->binding_mutex);
23221e
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
23221e
index 378ec7600154..23cf8a264f3d 100644
23221e
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
23221e
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
23221e
@@ -1167,7 +1167,7 @@ int vmw_fence_event_ioctl(struct drm_device *dev, void *data,
23221e
 	}
23221e
 
23221e
 	vmw_execbuf_copy_fence_user(dev_priv, vmw_fp, 0, user_fence_rep, fence,
23221e
-				    handle, -1, NULL);
23221e
+				    handle, -1);
23221e
 	vmw_fence_obj_unreference(&fence);
23221e
 	return 0;
23221e
 out_no_create:
23221e
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
23221e
index 9a89f658e501..bb0448044ced 100644
23221e
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
23221e
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
23221e
@@ -2477,7 +2477,7 @@ void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv,
23221e
 	if (file_priv)
23221e
 		vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv),
23221e
 					    ret, user_fence_rep, fence,
23221e
-					    handle, -1, NULL);
23221e
+					    handle, -1);
23221e
 	if (out_fence)
23221e
 		*out_fence = fence;
23221e
 	else
23221e
-- 
23221e
2.34.1
23221e
23221e