dri2: Protect against dri2ClientPrivate assertion failures

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 <doug@schmorgal.com>
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1053
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1534
This commit is contained in:
Doug Brown 2024-07-15 19:44:23 -07:00 committed by Enrico Weigelt, metux IT consult
parent 9747ade9b1
commit 4898415c6b

View File

@ -356,10 +356,15 @@ DRI2CreateDrawable2(ClientPtr client, DrawablePtr pDraw, XID id,
XID *dri2_id_out) XID *dri2_id_out)
{ {
DRI2DrawablePtr pPriv; DRI2DrawablePtr pPriv;
DRI2ClientPtr dri2_client = dri2ClientPrivate(client); DRI2ClientPtr dri2_client;
XID dri2_id; XID dri2_id;
int rc; int rc;
if (!dixPrivateKeyRegistered(dri2ScreenPrivateKey))
return BadValue;
dri2_client = dri2ClientPrivate(client);
pPriv = DRI2GetDrawable(pDraw); pPriv = DRI2GetDrawable(pDraw);
if (pPriv == NULL) if (pPriv == NULL)
pPriv = DRI2AllocateDrawable(pDraw); pPriv = DRI2AllocateDrawable(pDraw);
@ -1362,9 +1367,14 @@ Bool
DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic) DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic)
{ {
DRI2ScreenPtr ds; DRI2ScreenPtr ds;
DRI2ClientPtr dri2_client = dri2ClientPrivate(client); DRI2ClientPtr dri2_client;
ScreenPtr primescreen; ScreenPtr primescreen;
if (!dixPrivateKeyRegistered(dri2ScreenPrivateKey))
return FALSE;
dri2_client = dri2ClientPrivate(client);
ds = DRI2GetScreenPrime(pScreen, dri2_client->prime_id); ds = DRI2GetScreenPrime(pScreen, dri2_client->prime_id);
if (ds == NULL) if (ds == NULL)
return FALSE; return FALSE;