|
|
0fd959 |
From 8f27c9536131c71dddc120344ed5cd3643e99135 Mon Sep 17 00:00:00 2001
|
|
|
0fd959 |
From: Adam Jackson <ajax@redhat.com>
|
|
|
0fd959 |
Date: Mon, 10 Nov 2014 12:13:43 -0500
|
|
|
0fd959 |
Subject: [PATCH 32/33] glx: Length checking for RenderLarge requests (v2)
|
|
|
0fd959 |
[CVE-2014-8098 3/8]
|
|
|
0fd959 |
|
|
|
0fd959 |
This is a half-measure until we start passing request length into the
|
|
|
0fd959 |
varsize function, but it's better than the nothing we had before.
|
|
|
0fd959 |
|
|
|
0fd959 |
v2: Verify that there's at least a large render header's worth of
|
|
|
0fd959 |
dataBytes (Julien Cristau)
|
|
|
0fd959 |
|
|
|
0fd959 |
Reviewed-by: Michal Srb <msrb@suse.com>
|
|
|
0fd959 |
Reviewed-by: Andy Ritger <aritger@nvidia.com>
|
|
|
0fd959 |
Signed-off-by: Adam Jackson <ajax@redhat.com>
|
|
|
0fd959 |
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
|
|
|
0fd959 |
Signed-off-by: Fedora X Ninjas <x@fedoraproject.org>
|
|
|
0fd959 |
---
|
|
|
0fd959 |
glx/glxcmds.c | 57 ++++++++++++++++++++++++++++++++++-----------------------
|
|
|
0fd959 |
1 file changed, 34 insertions(+), 23 deletions(-)
|
|
|
0fd959 |
|
|
|
0fd959 |
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
|
|
|
0fd959 |
index 5b37e37..317e113 100644
|
|
|
0fd959 |
--- a/glx/glxcmds.c
|
|
|
0fd959 |
+++ b/glx/glxcmds.c
|
|
|
0fd959 |
@@ -2099,6 +2099,8 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc)
|
|
|
0fd959 |
|
|
|
0fd959 |
__GLX_DECLARE_SWAP_VARIABLES;
|
|
|
0fd959 |
|
|
|
0fd959 |
+ REQUEST_AT_LEAST_SIZE(xGLXRenderLargeReq);
|
|
|
0fd959 |
+
|
|
|
0fd959 |
req = (xGLXRenderLargeReq *) pc;
|
|
|
0fd959 |
if (client->swapped) {
|
|
|
0fd959 |
__GLX_SWAP_SHORT(&req->length);
|
|
|
0fd959 |
@@ -2114,12 +2116,14 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc)
|
|
|
0fd959 |
__glXResetLargeCommandStatus(cl);
|
|
|
0fd959 |
return error;
|
|
|
0fd959 |
}
|
|
|
0fd959 |
+ if (safe_pad(req->dataBytes) < 0)
|
|
|
0fd959 |
+ return BadLength;
|
|
|
0fd959 |
dataBytes = req->dataBytes;
|
|
|
0fd959 |
|
|
|
0fd959 |
/*
|
|
|
0fd959 |
** Check the request length.
|
|
|
0fd959 |
*/
|
|
|
0fd959 |
- if ((req->length << 2) != __GLX_PAD(dataBytes) + sz_xGLXRenderLargeReq) {
|
|
|
0fd959 |
+ if ((req->length << 2) != safe_pad(dataBytes) + sz_xGLXRenderLargeReq) {
|
|
|
0fd959 |
client->errorValue = req->length;
|
|
|
0fd959 |
/* Reset in case this isn't 1st request. */
|
|
|
0fd959 |
__glXResetLargeCommandStatus(cl);
|
|
|
0fd959 |
@@ -2129,7 +2133,7 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc)
|
|
|
0fd959 |
|
|
|
0fd959 |
if (cl->largeCmdRequestsSoFar == 0) {
|
|
|
0fd959 |
__GLXrenderSizeData entry;
|
|
|
0fd959 |
- int extra;
|
|
|
0fd959 |
+ int extra = 0;
|
|
|
0fd959 |
size_t cmdlen;
|
|
|
0fd959 |
int err;
|
|
|
0fd959 |
|
|
|
0fd959 |
@@ -2142,13 +2146,17 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc)
|
|
|
0fd959 |
return __glXError(GLXBadLargeRequest);
|
|
|
0fd959 |
}
|
|
|
0fd959 |
|
|
|
0fd959 |
+ if (dataBytes < __GLX_RENDER_LARGE_HDR_SIZE)
|
|
|
0fd959 |
+ return BadLength;
|
|
|
0fd959 |
+
|
|
|
0fd959 |
hdr = (__GLXrenderLargeHeader *) pc;
|
|
|
0fd959 |
if (client->swapped) {
|
|
|
0fd959 |
__GLX_SWAP_INT(&hdr->length);
|
|
|
0fd959 |
__GLX_SWAP_INT(&hdr->opcode);
|
|
|
0fd959 |
}
|
|
|
0fd959 |
- cmdlen = hdr->length;
|
|
|
0fd959 |
opcode = hdr->opcode;
|
|
|
0fd959 |
+ if ((cmdlen = safe_pad(hdr->length)) < 0)
|
|
|
0fd959 |
+ return BadLength;
|
|
|
0fd959 |
|
|
|
0fd959 |
/*
|
|
|
0fd959 |
** Check for core opcodes and grab entry data.
|
|
|
0fd959 |
@@ -2170,17 +2178,13 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc)
|
|
|
0fd959 |
if (extra < 0) {
|
|
|
0fd959 |
return BadLength;
|
|
|
0fd959 |
}
|
|
|
0fd959 |
- /* large command's header is 4 bytes longer, so add 4 */
|
|
|
0fd959 |
- if (cmdlen != __GLX_PAD(entry.bytes + 4 + extra)) {
|
|
|
0fd959 |
- return BadLength;
|
|
|
0fd959 |
- }
|
|
|
0fd959 |
}
|
|
|
0fd959 |
- else {
|
|
|
0fd959 |
- /* constant size command */
|
|
|
0fd959 |
- if (cmdlen != __GLX_PAD(entry.bytes + 4)) {
|
|
|
0fd959 |
- return BadLength;
|
|
|
0fd959 |
- }
|
|
|
0fd959 |
+
|
|
|
0fd959 |
+ /* the +4 is safe because we know entry.bytes is small */
|
|
|
0fd959 |
+ if (cmdlen != safe_pad(safe_add(entry.bytes + 4, extra))) {
|
|
|
0fd959 |
+ return BadLength;
|
|
|
0fd959 |
}
|
|
|
0fd959 |
+
|
|
|
0fd959 |
/*
|
|
|
0fd959 |
** Make enough space in the buffer, then copy the entire request.
|
|
|
0fd959 |
*/
|
|
|
0fd959 |
@@ -2207,6 +2211,7 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc)
|
|
|
0fd959 |
** We are receiving subsequent (i.e. not the first) requests of a
|
|
|
0fd959 |
** multi request command.
|
|
|
0fd959 |
*/
|
|
|
0fd959 |
+ int bytesSoFar; /* including this packet */
|
|
|
0fd959 |
|
|
|
0fd959 |
/*
|
|
|
0fd959 |
** Check the request number and the total request count.
|
|
|
0fd959 |
@@ -2225,11 +2230,18 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc)
|
|
|
0fd959 |
/*
|
|
|
0fd959 |
** Check that we didn't get too much data.
|
|
|
0fd959 |
*/
|
|
|
0fd959 |
- if ((cl->largeCmdBytesSoFar + dataBytes) > cl->largeCmdBytesTotal) {
|
|
|
0fd959 |
+ if ((bytesSoFar = safe_add(cl->largeCmdBytesSoFar, dataBytes)) < 0) {
|
|
|
0fd959 |
+ client->errorValue = dataBytes;
|
|
|
0fd959 |
+ __glXResetLargeCommandStatus(cl);
|
|
|
0fd959 |
+ return __glXError(GLXBadLargeRequest);
|
|
|
0fd959 |
+ }
|
|
|
0fd959 |
+
|
|
|
0fd959 |
+ if (bytesSoFar > cl->largeCmdBytesTotal) {
|
|
|
0fd959 |
client->errorValue = dataBytes;
|
|
|
0fd959 |
__glXResetLargeCommandStatus(cl);
|
|
|
0fd959 |
return __glXError(GLXBadLargeRequest);
|
|
|
0fd959 |
}
|
|
|
0fd959 |
+
|
|
|
0fd959 |
memcpy(cl->largeCmdBuf + cl->largeCmdBytesSoFar, pc, dataBytes);
|
|
|
0fd959 |
cl->largeCmdBytesSoFar += dataBytes;
|
|
|
0fd959 |
cl->largeCmdRequestsSoFar++;
|
|
|
0fd959 |
@@ -2241,17 +2253,16 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc)
|
|
|
0fd959 |
** This is the last request; it must have enough bytes to complete
|
|
|
0fd959 |
** the command.
|
|
|
0fd959 |
*/
|
|
|
0fd959 |
- /* NOTE: the two pad macros have been added below; they are needed
|
|
|
0fd959 |
- ** because the client library pads the total byte count, but not
|
|
|
0fd959 |
- ** the per-request byte counts. The Protocol Encoding says the
|
|
|
0fd959 |
- ** total byte count should not be padded, so a proposal will be
|
|
|
0fd959 |
- ** made to the ARB to relax the padding constraint on the total
|
|
|
0fd959 |
- ** byte count, thus preserving backward compatibility. Meanwhile,
|
|
|
0fd959 |
- ** the padding done below fixes a bug that did not allow
|
|
|
0fd959 |
- ** large commands of odd sizes to be accepted by the server.
|
|
|
0fd959 |
+ /* NOTE: the pad macro below is needed because the client library
|
|
|
0fd959 |
+ ** pads the total byte count, but not the per-request byte counts.
|
|
|
0fd959 |
+ ** The Protocol Encoding says the total byte count should not be
|
|
|
0fd959 |
+ ** padded, so a proposal will be made to the ARB to relax the
|
|
|
0fd959 |
+ ** padding constraint on the total byte count, thus preserving
|
|
|
0fd959 |
+ ** backward compatibility. Meanwhile, the padding done below
|
|
|
0fd959 |
+ ** fixes a bug that did not allow large commands of odd sizes to
|
|
|
0fd959 |
+ ** be accepted by the server.
|
|
|
0fd959 |
*/
|
|
|
0fd959 |
- if (__GLX_PAD(cl->largeCmdBytesSoFar) !=
|
|
|
0fd959 |
- __GLX_PAD(cl->largeCmdBytesTotal)) {
|
|
|
0fd959 |
+ if (safe_pad(cl->largeCmdBytesSoFar) != cl->largeCmdBytesTotal) {
|
|
|
0fd959 |
client->errorValue = dataBytes;
|
|
|
0fd959 |
__glXResetLargeCommandStatus(cl);
|
|
|
0fd959 |
return __glXError(GLXBadLargeRequest);
|
|
|
0fd959 |
--
|
|
|
0fd959 |
1.9.3
|
|
|
0fd959 |
|