From a0834009cfb10b8982a1f2b47b8ed00de254c2c3 Mon Sep 17 00:00:00 2001 From: Doug Brown Date: Mon, 15 Jul 2024 19:44:23 -0700 Subject: [PATCH] dri2: Protect against dri2ClientPrivate assertion failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If DRI2ScreenInit hasn't been called yet, DRI2Authenticate and DRI2CreateDrawable2 cause the X server to crash. This has been observed to happen on multiple modern Linux distros in various conditions, including QEMU and VMware VMs. Make these functions more robust in order to prevent the crash. This patch was originally provided by Bernhard Übelacker and expanded upon by Mark Wagner. Signed-off-by: Doug Brown Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1053 Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1534 Part-of: --- hw/xfree86/dri2/dri2.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c index f4fa19edb..4ac0e144e 100644 --- a/hw/xfree86/dri2/dri2.c +++ b/hw/xfree86/dri2/dri2.c @@ -359,10 +359,15 @@ DRI2CreateDrawable2(ClientPtr client, DrawablePtr pDraw, XID id, XID *dri2_id_out) { DRI2DrawablePtr pPriv; - DRI2ClientPtr dri2_client = dri2ClientPrivate(client); + DRI2ClientPtr dri2_client; XID dri2_id; int rc; + if (!dixPrivateKeyRegistered(dri2ScreenPrivateKey)) + return BadValue; + + dri2_client = dri2ClientPrivate(client); + pPriv = DRI2GetDrawable(pDraw); if (pPriv == NULL) pPriv = DRI2AllocateDrawable(pDraw); @@ -1365,9 +1370,14 @@ Bool DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic) { DRI2ScreenPtr ds; - DRI2ClientPtr dri2_client = dri2ClientPrivate(client); + DRI2ClientPtr dri2_client; ScreenPtr primescreen; + if (!dixPrivateKeyRegistered(dri2ScreenPrivateKey)) + return FALSE; + + dri2_client = dri2ClientPrivate(client); + ds = DRI2GetScreenPrime(pScreen, dri2_client->prime_id); if (ds == NULL) return FALSE;