mesa: fix misaligned pointer returned by dlist_alloc
authorCharmaine Lee <charmainel@vmware.com>
Wed, 2 Feb 2022 23:12:12 +0000 (15:12 -0800)
committerMarge Bot <emma+marge@anholt.net>
Sat, 5 Feb 2022 22:45:01 +0000 (22:45 +0000)
In cases where the to-be-allocated node size with padding exceeds BLOCK_SIZE
but without padding doesn't, a new block is not created and no padding is done
to the previous instruction, causing a misaligned pointer to be returned.

v2: Per Ilia Mirkin's suggestion, remove the extra condition in the first
    if statement, let it unconditionally pad the last instruction if needed.
    The updated currentPos will then be taken into account in the
    block size checking.

This fixes crash seen with lightsmark and Optuma apitraces

Fixes:  05605d7f537c4 (' mesa: remove display list OPCODE_NOP')

Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Neha Bhende <bhenden@vmware.com>
Tested-by: Neha Bhende <bhenden@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14871>

src/mesa/main/dlist.c

index fcf6b2e..64070b6 100644 (file)
@@ -1506,8 +1506,7 @@ dlist_alloc(struct gl_context *ctx, OpCode opcode, GLuint bytes, bool align8)
 
    /* If this node needs to start on an 8-byte boundary, pad the last node. */
    if (sizeof(void *) == 8 && align8 &&
-       ctx->ListState.CurrentPos % 2 == 1 &&
-       ctx->ListState.CurrentPos + 1 + numNodes + contNodes <= BLOCK_SIZE) {
+       ctx->ListState.CurrentPos % 2 == 1) {
       Node *last = ctx->ListState.CurrentBlock + ctx->ListState.CurrentPos -
                    ctx->ListState.LastInstSize;
       last->InstSize++;