751470
From 7881d29f2c729e4a8a5af21a0abcf3db18e22918 Mon Sep 17 00:00:00 2001
751470
From: Dave Airlie <airlied@redhat.com>
751470
Date: Fri, 14 Feb 2020 15:00:13 +1000
751470
Subject: [PATCH 1/2] dri: add another get shm variant.
751470
751470
When Brian in 02c3dad0f3b4d26e0faa5cc51d06bc50d693dcdc restricted
751470
the shm permissions it means we hit the fallback paths in some
751470
scenarios we hadn't before.
751470
751470
When you use Xephyr to xdmcp from one user to another the new perms
751470
stop the X server (running as user a) attaching to the SHM segments
751470
from gnome-shell (running as user b).
751470
751470
In this case however only the GLX side of the code had insight into this,
751470
and the dri could was meant of fall back, and it worked for put image
751470
fine but the get image path was broken, since there was no indication
751470
in the broken case of the need to fallback.
751470
751470
This adds a return type to a new interface member that lets the
751470
caller know it has to fallback.
751470
751470
Fixes: 02c3dad0f3b4 ("Call shmget() with permission 0600 instead of 0777")
751470
---
751470
 include/GL/internal/dri_interface.h    | 15 ++++++++++++++-
751470
 src/gallium/state_trackers/dri/drisw.c |  3 +++
751470
 2 files changed, 17 insertions(+), 1 deletion(-)
751470
751470
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
751470
index 09782c8baeb..e40106575c0 100644
751470
--- a/include/GL/internal/dri_interface.h
751470
+++ b/include/GL/internal/dri_interface.h
751470
@@ -634,7 +634,7 @@ struct __DRIdamageExtensionRec {
751470
  * SWRast Loader extension.
751470
  */
751470
 #define __DRI_SWRAST_LOADER "DRI_SWRastLoader"
751470
-#define __DRI_SWRAST_LOADER_VERSION 5
751470
+#define __DRI_SWRAST_LOADER_VERSION 6
751470
 struct __DRIswrastLoaderExtensionRec {
751470
     __DRIextension base;
751470
 
751470
@@ -711,6 +711,19 @@ struct __DRIswrastLoaderExtensionRec {
751470
                          int width, int height, int stride,
751470
                          int shmid, char *shmaddr, unsigned offset,
751470
                          void *loaderPrivate);
751470
+
751470
+    /**
751470
+     * get shm image to drawable (v2)
751470
+     *
751470
+     * There are some cases where GLX can't use SHM, but DRI
751470
+     * still tries, we need to get a return type for when to
751470
+     * fallback to the non-shm path.
751470
+     *
751470
+     * \since 6
751470
+     */
751470
+    GLboolean (*getImageShm2)(__DRIdrawable *readable,
751470
+                              int x, int y, int width, int height,
751470
+                              int shmid, void *loaderPrivate);
751470
 };
751470
 
751470
 /**
751470
diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c
751470
index e3fb3f1b925..df364c47391 100644
751470
--- a/src/gallium/state_trackers/dri/drisw.c
751470
+++ b/src/gallium/state_trackers/dri/drisw.c
751470
@@ -138,6 +138,9 @@ get_image_shm(__DRIdrawable *dPriv, int x, int y, int width, int height,
751470
    if (!res->screen->resource_get_handle(res->screen, NULL, res, &whandle, PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE))
751470
       return FALSE;
751470
 
751470
+   if (loader->base.version > 5 && loader->getImageShm2)
751470
+      return loader->getImageShm2(dPriv, x, y, width, height, whandle.handle, dPriv->loaderPrivate);
751470
+
751470
    loader->getImageShm(dPriv, x, y, width, height, whandle.handle, dPriv->loaderPrivate);
751470
    return TRUE;
751470
 }
751470
-- 
751470
2.21.1
751470