egl: Fix _eglPointerIsDereferencable w/o mincore()
authorAlexander van der Grinten <alexander.vandergrinten@gmail.com>
Sun, 15 Dec 2019 10:25:37 +0000 (11:25 +0100)
committerEric Engestrom <eric@engestrom.ch>
Wed, 22 Jan 2020 12:55:05 +0000 (12:55 +0000)
On platforms without mincore(), _eglPointerIsDereferencable()
currently just checks whether p != NULL. This is not sufficient:
In the Wayland platform code (i.e., in get_wl_surface_proxy()),
_eglPointerIsDereferencable() is called on the version field
of `struct wl_egl_window` which is 3 on current versions of
Wayland. This causes a segfault when trying to dereference p.

Fix this behavior by assuming that the first page of the
process is never dereferencable.

Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3103>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3103>

src/egl/main/eglglobals.c

index 0d7270333ec0bbb8600ffe9a00efb439916c6763..5760edc3d3c11719d9a14309321044884b775c74 100644 (file)
@@ -161,10 +161,10 @@ _eglGetClientExtensionString(void)
 EGLBoolean
 _eglPointerIsDereferencable(void *p)
 {
-#ifdef HAVE_MINCORE
    uintptr_t addr = (uintptr_t) p;
-   unsigned char valid = 0;
    const long page_size = getpagesize();
+#ifdef HAVE_MINCORE
+   unsigned char valid = 0;
 
    if (p == NULL)
       return EGL_FALSE;
@@ -190,6 +190,7 @@ _eglPointerIsDereferencable(void *p)
     */
    return EGL_TRUE;
 #else
-   return p != NULL;
+   // Without mincore(), we just assume that the first page is unmapped.
+   return addr >= page_size;
 #endif
 }