Blame SOURCES/CVE-2022-22942.patch

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