Blame SOURCES/CVE-2022-22942.patch

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