xace: typesafe hook function for XACE_RESOURCE_ACCESS

The generic XaceHook() call isn't typesafe (und unnecessarily slow).
Better add an explicit function, just like we already have for others.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1556>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-05-16 17:49:33 +02:00 committed by Marge Bot
parent 632a48a057
commit ae3c573337
18 changed files with 46 additions and 46 deletions

View File

@ -997,7 +997,7 @@ ProcPanoramiXShmCreatePixmap(ClientPtr client)
stuff->offset); stuff->offset);
if (pMap) { if (pMap) {
result = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, result = XaceHookResourceAccess(client, stuff->pid,
X11_RESTYPE_PIXMAP, pMap, X11_RESTYPE_NONE, NULL, DixCreateAccess); X11_RESTYPE_PIXMAP, pMap, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (result != Success) { if (result != Success) {
pDraw->pScreen->DestroyPixmap(pMap); pDraw->pScreen->DestroyPixmap(pMap);
@ -1112,7 +1112,7 @@ ProcShmCreatePixmap(ClientPtr client)
shmdesc->addr + shmdesc->addr +
stuff->offset); stuff->offset);
if (pMap) { if (pMap) {
rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, X11_RESTYPE_PIXMAP, rc = XaceHookResourceAccess(client, stuff->pid, X11_RESTYPE_PIXMAP,
pMap, X11_RESTYPE_NONE, NULL, DixCreateAccess); pMap, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (rc != Success) { if (rc != Success) {
pDraw->pScreen->DestroyPixmap(pMap); pDraw->pScreen->DestroyPixmap(pMap);

View File

@ -62,13 +62,21 @@ XaceHookSelectionAccess(ClientPtr client, Selection ** ppSel, Mask access_mode)
return rec.status; return rec.status;
} }
int XaceHookResourceAccess(ClientPtr client, XID id, RESTYPE rtype, void *res,
RESTYPE ptype, void *parent, Mask access_mode)
{
XaceResourceAccessRec rec = { client, id, rtype, res, ptype, parent,
access_mode, Success };
CallCallbacks(&XaceHooks[XACE_RESOURCE_ACCESS], &rec);
return rec.status;
}
/* Entry point for hook functions. Called by Xserver. /* Entry point for hook functions. Called by Xserver.
*/ */
int int
XaceHook(int hook, ...) XaceHook(int hook, ...)
{ {
union { union {
XaceResourceAccessRec res;
XaceDeviceAccessRec dev; XaceDeviceAccessRec dev;
XaceSendAccessRec send; XaceSendAccessRec send;
XaceReceiveAccessRec recv; XaceReceiveAccessRec recv;
@ -93,18 +101,6 @@ XaceHook(int hook, ...)
* sets calldata directly to a single argument (with no return result) * sets calldata directly to a single argument (with no return result)
*/ */
switch (hook) { switch (hook) {
case XACE_RESOURCE_ACCESS:
u.res.client = va_arg(ap, ClientPtr);
u.res.id = va_arg(ap, XID);
u.res.rtype = va_arg(ap, RESTYPE);
u.res.res = va_arg(ap, void *);
u.res.ptype = va_arg(ap, RESTYPE);
u.res.parent = va_arg(ap, void *);
u.res.access_mode = va_arg(ap, Mask);
u.res.status = Success; /* default allow */
prv = &u.res.status;
break;
case XACE_DEVICE_ACCESS: case XACE_DEVICE_ACCESS:
u.dev.client = va_arg(ap, ClientPtr); u.dev.client = va_arg(ap, ClientPtr);
u.dev.dev = va_arg(ap, DeviceIntPtr); u.dev.dev = va_arg(ap, DeviceIntPtr);

View File

@ -78,6 +78,10 @@ int XaceHookPropertyAccess(ClientPtr ptr, WindowPtr pWin, PropertyPtr *ppProp,
Mask access_mode); Mask access_mode);
int XaceHookSelectionAccess(ClientPtr ptr, Selection ** ppSel, Mask access_mode); int XaceHookSelectionAccess(ClientPtr ptr, Selection ** ppSel, Mask access_mode);
/* needs to be exported for in-tree modsetting, but not part of public API */
_X_EXPORT int XaceHookResourceAccess(ClientPtr client, XID id, RESTYPE rtype, void *res,
RESTYPE ptype, void *parent, Mask access_mode);
/* Register a callback for a given hook. /* Register a callback for a given hook.
*/ */
#define XaceRegisterCallback(hook,callback,data) \ #define XaceRegisterCallback(hook,callback,data) \

View File

@ -252,7 +252,7 @@ ProcCompositeNameWindowPixmap(ClientPtr client)
return BadMatch; return BadMatch;
/* security creation/labeling check */ /* security creation/labeling check */
rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pixmap, X11_RESTYPE_PIXMAP, rc = XaceHookResourceAccess(client, stuff->pixmap, X11_RESTYPE_PIXMAP,
pPixmap, X11_RESTYPE_WINDOW, pWin, DixCreateAccess); pPixmap, X11_RESTYPE_WINDOW, pWin, DixCreateAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -306,7 +306,7 @@ ProcCompositeGetOverlayWindow(ClientPtr client)
return BadAlloc; return BadAlloc;
} }
rc = XaceHook(XACE_RESOURCE_ACCESS, client, cs->pOverlayWin->drawable.id, rc = XaceHookResourceAccess(client, cs->pOverlayWin->drawable.id,
X11_RESTYPE_WINDOW, cs->pOverlayWin, X11_RESTYPE_NONE, X11_RESTYPE_WINDOW, cs->pOverlayWin, X11_RESTYPE_NONE,
NULL, DixGetAttrAccess); NULL, DixGetAttrAccess);
if (rc != Success) { if (rc != Success) {
@ -828,7 +828,7 @@ PanoramiXCompositeGetOverlayWindow(ClientPtr client)
return BadAlloc; return BadAlloc;
} }
rc = XaceHook(XACE_RESOURCE_ACCESS, client, rc = XaceHookResourceAccess(client,
cs->pOverlayWin->drawable.id, cs->pOverlayWin->drawable.id,
X11_RESTYPE_WINDOW, cs->pOverlayWin, X11_RESTYPE_NONE, NULL, X11_RESTYPE_WINDOW, cs->pOverlayWin, X11_RESTYPE_NONE, NULL,
DixGetAttrAccess); DixGetAttrAccess);

View File

@ -169,9 +169,9 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction)
} }
/* Security creation/labeling check. */ /* Security creation/labeling check. */
rc = XaceHook(XACE_RESOURCE_ACCESS, serverClient, bufId, rc = XaceHookResourceAccess(serverClient, bufId, dbeDrawableResType,
dbeDrawableResType, pDbeWindowPriv->pBackBuffer, pDbeWindowPriv->pBackBuffer, X11_RESTYPE_WINDOW,
X11_RESTYPE_WINDOW, pWin, DixCreateAccess); pWin, DixCreateAccess);
/* Make the back pixmap a DBE drawable resource. */ /* Make the back pixmap a DBE drawable resource. */
if (rc != Success || !AddResource(bufId, dbeDrawableResType, if (rc != Success || !AddResource(bufId, dbeDrawableResType,

View File

@ -379,7 +379,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
/* /*
* Security creation/labeling check * Security creation/labeling check
*/ */
i = XaceHook(XACE_RESOURCE_ACCESS, clients[client], mid, X11_RESTYPE_COLORMAP, i = XaceHookResourceAccess(clients[client], mid, X11_RESTYPE_COLORMAP,
pmap, X11_RESTYPE_NONE, NULL, DixCreateAccess); pmap, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (i != Success) { if (i != Success) {
FreeResource(mid, X11_RESTYPE_NONE); FreeResource(mid, X11_RESTYPE_NONE);

View File

@ -279,7 +279,7 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
pCurs->id = cid; pCurs->id = cid;
/* security creation/labeling check */ /* security creation/labeling check */
rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, X11_RESTYPE_CURSOR, rc = XaceHookResourceAccess(client, cid, X11_RESTYPE_CURSOR,
pCurs, X11_RESTYPE_NONE, NULL, DixCreateAccess); pCurs, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (rc != Success) if (rc != Success)
goto error; goto error;
@ -459,7 +459,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
pCurs->id = cid; pCurs->id = cid;
/* security creation/labeling check */ /* security creation/labeling check */
rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, X11_RESTYPE_CURSOR, rc = XaceHookResourceAccess(client, cid, X11_RESTYPE_CURSOR,
pCurs, X11_RESTYPE_NONE, NULL, DixCreateAccess); pCurs, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (rc != Success) if (rc != Success)
goto error; goto error;

View File

@ -1518,7 +1518,7 @@ ProcCreatePixmap(ClientPtr client)
pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
pMap->drawable.id = stuff->pid; pMap->drawable.id = stuff->pid;
/* security creation/labeling check */ /* security creation/labeling check */
rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, X11_RESTYPE_PIXMAP, rc = XaceHookResourceAccess(client, stuff->pid, X11_RESTYPE_PIXMAP,
pMap, X11_RESTYPE_NONE, NULL, DixCreateAccess); pMap, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (rc != Success) { if (rc != Success) {
(*pDraw->pScreen->DestroyPixmap) (pMap); (*pDraw->pScreen->DestroyPixmap) (pMap);

View File

@ -4531,7 +4531,7 @@ EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask)
} }
check = (mask & ManagerMask); check = (mask & ManagerMask);
if (check) { if (check) {
rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, rc = XaceHookResourceAccess(client, pWin->drawable.id,
X11_RESTYPE_WINDOW, pWin, X11_RESTYPE_NONE, NULL, DixManageAccess); X11_RESTYPE_WINDOW, pWin, X11_RESTYPE_NONE, NULL, DixManageAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;

View File

@ -549,7 +549,7 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
} }
/* security creation/labeling check */ /* security creation/labeling check */
*pStatus = XaceHook(XACE_RESOURCE_ACCESS, client, gcid, X11_RESTYPE_GC, pGC, *pStatus = XaceHookResourceAccess(client, gcid, X11_RESTYPE_GC, pGC,
X11_RESTYPE_NONE, NULL, DixCreateAccess | DixSetAttrAccess); X11_RESTYPE_NONE, NULL, DixCreateAccess | DixSetAttrAccess);
if (*pStatus != Success) if (*pStatus != Success)
goto out; goto out;

View File

@ -1223,7 +1223,7 @@ dixLookupResourceByType(void **result, XID id, RESTYPE rtype,
return resourceTypes[rtype & TypeMask].errorValue; return resourceTypes[rtype & TypeMask].errorValue;
if (client) { if (client) {
cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, cid = XaceHookResourceAccess(client, id, res->type,
res->value, X11_RESTYPE_NONE, NULL, mode); res->value, X11_RESTYPE_NONE, NULL, mode);
if (cid == BadValue) if (cid == BadValue)
return resourceTypes[rtype & TypeMask].errorValue; return resourceTypes[rtype & TypeMask].errorValue;
@ -1258,7 +1258,7 @@ dixLookupResourceByClass(void **result, XID id, RESTYPE rclass,
return BadValue; return BadValue;
if (client) { if (client) {
cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, cid = XaceHookResourceAccess(client, id, res->type,
res->value, X11_RESTYPE_NONE, NULL, mode); res->value, X11_RESTYPE_NONE, NULL, mode);
if (cid != Success) if (cid != Success)
return cid; return cid;

View File

@ -638,7 +638,7 @@ CreateRootWindow(ScreenPtr pScreen)
/* security creation/labeling check /* security creation/labeling check
*/ */
if (XaceHook(XACE_RESOURCE_ACCESS, serverClient, pWin->drawable.id, if (XaceHookResourceAccess(serverClient, pWin->drawable.id,
X11_RESTYPE_WINDOW, pWin, X11_RESTYPE_NONE, NULL, DixCreateAccess)) X11_RESTYPE_WINDOW, pWin, X11_RESTYPE_NONE, NULL, DixCreateAccess))
return FALSE; return FALSE;
@ -867,7 +867,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
/* security creation/labeling check /* security creation/labeling check
*/ */
*error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, X11_RESTYPE_WINDOW, pWin, *error = XaceHookResourceAccess(client, wid, X11_RESTYPE_WINDOW, pWin,
X11_RESTYPE_WINDOW, pWin->parent, X11_RESTYPE_WINDOW, pWin->parent,
DixCreateAccess | DixSetAttrAccess); DixCreateAccess | DixSetAttrAccess);
if (*error != Success) { if (*error != Success) {
@ -1115,7 +1115,7 @@ DestroySubwindows(WindowPtr pWin, ClientPtr client)
*/ */
UnmapSubwindows(pWin); UnmapSubwindows(pWin);
while (pWin->lastChild) { while (pWin->lastChild) {
int rc = XaceHook(XACE_RESOURCE_ACCESS, client, int rc = XaceHookResourceAccess(client,
pWin->lastChild->drawable.id, X11_RESTYPE_WINDOW, pWin->lastChild->drawable.id, X11_RESTYPE_WINDOW,
pWin->lastChild, X11_RESTYPE_NONE, NULL, DixDestroyAccess); pWin->lastChild, X11_RESTYPE_NONE, NULL, DixDestroyAccess);
@ -1397,7 +1397,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
goto PatchUp; goto PatchUp;
} }
if (val == xTrue) { if (val == xTrue) {
rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, rc = XaceHookResourceAccess(client, pWin->drawable.id,
X11_RESTYPE_WINDOW, pWin, X11_RESTYPE_NONE, NULL, DixGrabAccess); X11_RESTYPE_WINDOW, pWin, X11_RESTYPE_NONE, NULL, DixGrabAccess);
if (rc != Success) { if (rc != Success) {
error = rc; error = rc;
@ -2664,7 +2664,7 @@ MapWindow(WindowPtr pWin, ClientPtr client)
return Success; return Success;
/* general check for permission to map window */ /* general check for permission to map window */
if (XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, X11_RESTYPE_WINDOW, if (XaceHookResourceAccess(client, pWin->drawable.id, X11_RESTYPE_WINDOW,
pWin, X11_RESTYPE_NONE, NULL, DixShowAccess) != Success) pWin, X11_RESTYPE_NONE, NULL, DixShowAccess) != Success)
return Success; return Success;

View File

@ -239,7 +239,7 @@ proc_dri3_pixmap_from_buffer(ClientPtr client)
pixmap->drawable.id = stuff->pixmap; pixmap->drawable.id = stuff->pixmap;
/* security creation/labeling check */ /* security creation/labeling check */
rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pixmap, X11_RESTYPE_PIXMAP, rc = XaceHookResourceAccess(client, stuff->pixmap, X11_RESTYPE_PIXMAP,
pixmap, X11_RESTYPE_NONE, NULL, DixCreateAccess); pixmap, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (rc != Success) { if (rc != Success) {
@ -503,7 +503,7 @@ proc_dri3_pixmap_from_buffers(ClientPtr client)
pixmap->drawable.id = stuff->pixmap; pixmap->drawable.id = stuff->pixmap;
/* security creation/labeling check */ /* security creation/labeling check */
rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pixmap, X11_RESTYPE_PIXMAP, rc = XaceHookResourceAccess(client, stuff->pixmap, X11_RESTYPE_PIXMAP,
pixmap, X11_RESTYPE_NONE, NULL, DixCreateAccess); pixmap, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (rc != Success) { if (rc != Success) {

View File

@ -1395,7 +1395,7 @@ DoCreatePbuffer(ClientPtr client, int screenNum, XID fbconfigId,
if (!pPixmap) if (!pPixmap)
return BadAlloc; return BadAlloc;
err = XaceHook(XACE_RESOURCE_ACCESS, client, glxDrawableId, X11_RESTYPE_PIXMAP, err = XaceHookResourceAccess(client, glxDrawableId, X11_RESTYPE_PIXMAP,
pPixmap, X11_RESTYPE_NONE, NULL, DixCreateAccess); pPixmap, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (err != Success) { if (err != Success) {
(*pGlxScreen->pScreen->DestroyPixmap) (pPixmap); (*pGlxScreen->pScreen->DestroyPixmap) (pPixmap);

View File

@ -336,7 +336,7 @@ AnimCursorCreate(CursorPtr *cursors, CARD32 *deltas, int ncursor,
/* security creation/labeling check */ /* security creation/labeling check */
if (ac->timer) if (ac->timer)
rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, X11_RESTYPE_CURSOR, pCursor, rc = XaceHookResourceAccess(client, cid, X11_RESTYPE_CURSOR, pCursor,
X11_RESTYPE_NONE, NULL, DixCreateAccess); X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (rc != Success) { if (rc != Success) {

View File

@ -760,7 +760,7 @@ CreatePicture(Picture pid,
pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24); pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24);
/* security creation/labeling check */ /* security creation/labeling check */
*error = XaceHook(XACE_RESOURCE_ACCESS, client, pid, PictureType, pPicture, *error = XaceHookResourceAccess(client, pid, PictureType, pPicture,
X11_RESTYPE_PIXMAP, pDrawable, DixCreateAccess | DixSetAttrAccess); X11_RESTYPE_PIXMAP, pDrawable, DixCreateAccess | DixSetAttrAccess);
if (*error != Success) if (*error != Success)
goto out; goto out;

View File

@ -929,7 +929,7 @@ ProcRenderCreateGlyphSet(ClientPtr client)
if (!glyphSet) if (!glyphSet)
return BadAlloc; return BadAlloc;
/* security creation/labeling check */ /* security creation/labeling check */
rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->gsid, GlyphSetType, rc = XaceHookResourceAccess(client, stuff->gsid, GlyphSetType,
glyphSet, X11_RESTYPE_NONE, NULL, DixCreateAccess); glyphSet, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -1862,7 +1862,7 @@ ProcRenderCreateSolidFill(ClientPtr client)
if (!pPicture) if (!pPicture)
return error; return error;
/* security creation/labeling check */ /* security creation/labeling check */
error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType, error = XaceHookResourceAccess(client, stuff->pid, PictureType,
pPicture, X11_RESTYPE_NONE, NULL, DixCreateAccess); pPicture, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (error != Success) if (error != Success)
return error; return error;
@ -1901,7 +1901,7 @@ ProcRenderCreateLinearGradient(ClientPtr client)
if (!pPicture) if (!pPicture)
return error; return error;
/* security creation/labeling check */ /* security creation/labeling check */
error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType, error = XaceHookResourceAccess(client, stuff->pid, PictureType,
pPicture, X11_RESTYPE_NONE, NULL, DixCreateAccess); pPicture, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (error != Success) if (error != Success)
return error; return error;
@ -1941,7 +1941,7 @@ ProcRenderCreateRadialGradient(ClientPtr client)
if (!pPicture) if (!pPicture)
return error; return error;
/* security creation/labeling check */ /* security creation/labeling check */
error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType, error = XaceHookResourceAccess(client, stuff->pid, PictureType,
pPicture, X11_RESTYPE_NONE, NULL, DixCreateAccess); pPicture, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (error != Success) if (error != Success)
return error; return error;
@ -1980,7 +1980,7 @@ ProcRenderCreateConicalGradient(ClientPtr client)
if (!pPicture) if (!pPicture)
return error; return error;
/* security creation/labeling check */ /* security creation/labeling check */
error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType, error = XaceHookResourceAccess(client, stuff->pid, PictureType,
pPicture, X11_RESTYPE_NONE, NULL, DixCreateAccess); pPicture, X11_RESTYPE_NONE, NULL, DixCreateAccess);
if (error != Success) if (error != Success)
return error; return error;

View File

@ -373,7 +373,7 @@ ProcXFixesGetCursorImage(ClientPtr client)
pCursor = CursorForClient(client); pCursor = CursorForClient(client);
if (!pCursor) if (!pCursor)
return BadCursor; return BadCursor;
rc = XaceHook(XACE_RESOURCE_ACCESS, client, pCursor->id, X11_RESTYPE_CURSOR, rc = XaceHookResourceAccess(client, pCursor->id, X11_RESTYPE_CURSOR,
pCursor, X11_RESTYPE_NONE, NULL, DixReadAccess); pCursor, X11_RESTYPE_NONE, NULL, DixReadAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -522,7 +522,7 @@ ProcXFixesGetCursorImageAndName(ClientPtr client)
pCursor = CursorForClient(client); pCursor = CursorForClient(client);
if (!pCursor) if (!pCursor)
return BadCursor; return BadCursor;
rc = XaceHook(XACE_RESOURCE_ACCESS, client, pCursor->id, X11_RESTYPE_CURSOR, rc = XaceHookResourceAccess(client, pCursor->id, X11_RESTYPE_CURSOR,
pCursor, X11_RESTYPE_NONE, NULL, DixReadAccess | DixGetAttrAccess); pCursor, X11_RESTYPE_NONE, NULL, DixReadAccess | DixGetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;