|
|
a04e0a |
From bd134231e282d9eb126b6fdaa40bb383180fa72b Mon Sep 17 00:00:00 2001
|
|
|
a04e0a |
From: Peter Hutterer <peter.hutterer@who-t.net>
|
|
|
a04e0a |
Date: Tue, 5 Jul 2022 11:11:06 +1000
|
|
|
a04e0a |
Subject: [PATCH xserver 3/3] xkb: add request length validation for
|
|
|
a04e0a |
XkbSetGeometry
|
|
|
a04e0a |
|
|
|
a04e0a |
No validation of the various fields on that report were done, so a
|
|
|
a04e0a |
malicious client could send a short request that claims it had N
|
|
|
a04e0a |
sections, or rows, or keys, and the server would process the request for
|
|
|
a04e0a |
N sections, running out of bounds of the actual request data.
|
|
|
a04e0a |
|
|
|
a04e0a |
Fix this by adding size checks to ensure our data is valid.
|
|
|
a04e0a |
|
|
|
a04e0a |
ZDI-CAN 16062, CVE-2022-2319.
|
|
|
a04e0a |
|
|
|
a04e0a |
This vulnerability was discovered by:
|
|
|
a04e0a |
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative
|
|
|
a04e0a |
|
|
|
a04e0a |
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
|
|
|
a04e0a |
(cherry picked from commit 6907b6ea2b4ce949cb07271f5b678d5966d9df42)
|
|
|
a04e0a |
---
|
|
|
a04e0a |
xkb/xkb.c | 43 ++++++++++++++++++++++++++++++++++++++-----
|
|
|
a04e0a |
1 file changed, 38 insertions(+), 5 deletions(-)
|
|
|
a04e0a |
|
|
|
a04e0a |
diff --git a/xkb/xkb.c b/xkb/xkb.c
|
|
|
a04e0a |
index 36464a770..27d19793e 100644
|
|
|
a04e0a |
--- a/xkb/xkb.c
|
|
|
a04e0a |
+++ b/xkb/xkb.c
|
|
|
a04e0a |
@@ -5160,7 +5160,7 @@ _GetCountedString(char **wire_inout, ClientPtr client, char **str)
|
|
|
a04e0a |
}
|
|
|
a04e0a |
|
|
|
a04e0a |
static Status
|
|
|
a04e0a |
-_CheckSetDoodad(char **wire_inout,
|
|
|
a04e0a |
+_CheckSetDoodad(char **wire_inout, xkbSetGeometryReq *req,
|
|
|
a04e0a |
XkbGeometryPtr geom, XkbSectionPtr section, ClientPtr client)
|
|
|
a04e0a |
{
|
|
|
a04e0a |
char *wire;
|
|
|
a04e0a |
@@ -5171,6 +5171,9 @@ _CheckSetDoodad(char **wire_inout,
|
|
|
a04e0a |
Status status;
|
|
|
a04e0a |
|
|
|
a04e0a |
dWire = (xkbDoodadWireDesc *) (*wire_inout);
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, dWire, dWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
any = dWire->any;
|
|
|
a04e0a |
wire = (char *) &dWire[1];
|
|
|
a04e0a |
if (client->swapped) {
|
|
|
a04e0a |
@@ -5273,7 +5276,7 @@ _CheckSetDoodad(char **wire_inout,
|
|
|
a04e0a |
}
|
|
|
a04e0a |
|
|
|
a04e0a |
static Status
|
|
|
a04e0a |
-_CheckSetOverlay(char **wire_inout,
|
|
|
a04e0a |
+_CheckSetOverlay(char **wire_inout, xkbSetGeometryReq *req,
|
|
|
a04e0a |
XkbGeometryPtr geom, XkbSectionPtr section, ClientPtr client)
|
|
|
a04e0a |
{
|
|
|
a04e0a |
register int r;
|
|
|
a04e0a |
@@ -5284,6 +5287,9 @@ _CheckSetOverlay(char **wire_inout,
|
|
|
a04e0a |
|
|
|
a04e0a |
wire = *wire_inout;
|
|
|
a04e0a |
olWire = (xkbOverlayWireDesc *) wire;
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, olWire, olWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
if (client->swapped) {
|
|
|
a04e0a |
swapl(&olWire->name);
|
|
|
a04e0a |
}
|
|
|
a04e0a |
@@ -5295,6 +5301,9 @@ _CheckSetOverlay(char **wire_inout,
|
|
|
a04e0a |
xkbOverlayKeyWireDesc *kWire;
|
|
|
a04e0a |
XkbOverlayRowPtr row;
|
|
|
a04e0a |
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, rWire, rWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
if (rWire->rowUnder > section->num_rows) {
|
|
|
a04e0a |
client->errorValue = _XkbErrCode4(0x20, r, section->num_rows,
|
|
|
a04e0a |
rWire->rowUnder);
|
|
|
a04e0a |
@@ -5303,6 +5312,9 @@ _CheckSetOverlay(char **wire_inout,
|
|
|
a04e0a |
row = XkbAddGeomOverlayRow(ol, rWire->rowUnder, rWire->nKeys);
|
|
|
a04e0a |
kWire = (xkbOverlayKeyWireDesc *) &rWire[1];
|
|
|
a04e0a |
for (k = 0; k < rWire->nKeys; k++, kWire++) {
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, kWire, kWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
if (XkbAddGeomOverlayKey(ol, row,
|
|
|
a04e0a |
(char *) kWire->over,
|
|
|
a04e0a |
(char *) kWire->under) == NULL) {
|
|
|
a04e0a |
@@ -5336,6 +5348,9 @@ _CheckSetSections(XkbGeometryPtr geom,
|
|
|
a04e0a |
register int r;
|
|
|
a04e0a |
xkbRowWireDesc *rWire;
|
|
|
a04e0a |
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, sWire, sWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
if (client->swapped) {
|
|
|
a04e0a |
swapl(&sWire->name);
|
|
|
a04e0a |
swaps(&sWire->top);
|
|
|
a04e0a |
@@ -5361,6 +5376,9 @@ _CheckSetSections(XkbGeometryPtr geom,
|
|
|
a04e0a |
XkbRowPtr row;
|
|
|
a04e0a |
xkbKeyWireDesc *kWire;
|
|
|
a04e0a |
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, rWire, rWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
if (client->swapped) {
|
|
|
a04e0a |
swaps(&rWire->top);
|
|
|
a04e0a |
swaps(&rWire->left);
|
|
|
a04e0a |
@@ -5375,6 +5393,9 @@ _CheckSetSections(XkbGeometryPtr geom,
|
|
|
a04e0a |
for (k = 0; k < rWire->nKeys; k++, kWire++) {
|
|
|
a04e0a |
XkbKeyPtr key;
|
|
|
a04e0a |
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, kWire, kWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
key = XkbAddGeomKey(row);
|
|
|
a04e0a |
if (!key)
|
|
|
a04e0a |
return BadAlloc;
|
|
|
a04e0a |
@@ -5400,7 +5421,7 @@ _CheckSetSections(XkbGeometryPtr geom,
|
|
|
a04e0a |
register int d;
|
|
|
a04e0a |
|
|
|
a04e0a |
for (d = 0; d < sWire->nDoodads; d++) {
|
|
|
a04e0a |
- status = _CheckSetDoodad(&wire, geom, section, client);
|
|
|
a04e0a |
+ status = _CheckSetDoodad(&wire, req, geom, section, client);
|
|
|
a04e0a |
if (status != Success)
|
|
|
a04e0a |
return status;
|
|
|
a04e0a |
}
|
|
|
a04e0a |
@@ -5409,7 +5430,7 @@ _CheckSetSections(XkbGeometryPtr geom,
|
|
|
a04e0a |
register int o;
|
|
|
a04e0a |
|
|
|
a04e0a |
for (o = 0; o < sWire->nOverlays; o++) {
|
|
|
a04e0a |
- status = _CheckSetOverlay(&wire, geom, section, client);
|
|
|
a04e0a |
+ status = _CheckSetOverlay(&wire, req, geom, section, client);
|
|
|
a04e0a |
if (status != Success)
|
|
|
a04e0a |
return status;
|
|
|
a04e0a |
}
|
|
|
a04e0a |
@@ -5443,6 +5464,9 @@ _CheckSetShapes(XkbGeometryPtr geom,
|
|
|
a04e0a |
xkbOutlineWireDesc *olWire;
|
|
|
a04e0a |
XkbOutlinePtr ol;
|
|
|
a04e0a |
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, shapeWire, shapeWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
shape =
|
|
|
a04e0a |
XkbAddGeomShape(geom, shapeWire->name, shapeWire->nOutlines);
|
|
|
a04e0a |
if (!shape)
|
|
|
a04e0a |
@@ -5453,12 +5477,18 @@ _CheckSetShapes(XkbGeometryPtr geom,
|
|
|
a04e0a |
XkbPointPtr pt;
|
|
|
a04e0a |
xkbPointWireDesc *ptWire;
|
|
|
a04e0a |
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, olWire, olWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
ol = XkbAddGeomOutline(shape, olWire->nPoints);
|
|
|
a04e0a |
if (!ol)
|
|
|
a04e0a |
return BadAlloc;
|
|
|
a04e0a |
ol->corner_radius = olWire->cornerRadius;
|
|
|
a04e0a |
ptWire = (xkbPointWireDesc *) &olWire[1];
|
|
|
a04e0a |
for (p = 0, pt = ol->points; p < olWire->nPoints; p++, pt++, ptWire++) {
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, ptWire, ptWire + 1))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
pt->x = ptWire->x;
|
|
|
a04e0a |
pt->y = ptWire->y;
|
|
|
a04e0a |
if (client->swapped) {
|
|
|
a04e0a |
@@ -5564,12 +5594,15 @@ _CheckSetGeom(XkbGeometryPtr geom, xkbSetGeometryReq * req, ClientPtr client)
|
|
|
a04e0a |
return status;
|
|
|
a04e0a |
|
|
|
a04e0a |
for (i = 0; i < req->nDoodads; i++) {
|
|
|
a04e0a |
- status = _CheckSetDoodad(&wire, geom, NULL, client);
|
|
|
a04e0a |
+ status = _CheckSetDoodad(&wire, req, geom, NULL, client);
|
|
|
a04e0a |
if (status != Success)
|
|
|
a04e0a |
return status;
|
|
|
a04e0a |
}
|
|
|
a04e0a |
|
|
|
a04e0a |
for (i = 0; i < req->nKeyAliases; i++) {
|
|
|
a04e0a |
+ if (!_XkbCheckRequestBounds(client, req, wire, wire + XkbKeyNameLength))
|
|
|
a04e0a |
+ return BadLength;
|
|
|
a04e0a |
+
|
|
|
a04e0a |
if (XkbAddGeomKeyAlias(geom, &wire[XkbKeyNameLength], wire) == NULL)
|
|
|
a04e0a |
return BadAlloc;
|
|
|
a04e0a |
wire += 2 * XkbKeyNameLength;
|
|
|
a04e0a |
--
|
|
|
a04e0a |
2.36.1
|
|
|
a04e0a |
|