Source: mesa
Version: 25.0.7-2+deb13u1
Severity: important
Tags: security upstream patch

Any web page can crash a browser on Debian 13 when WebGL runs on
llvmpipe, and the crash comes from a stack overflow in Mesa that
upstream fixed in 25.1.0 and that trixie never got. With Firefox the
page kills the whole browser with no click, because Firefox runs WebGL
in its parent process on Linux. llvmpipe is the GL driver on VMs
without 3D acceleration, machines without a supported GPU and remote
desktops.

In src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c (25.0.7),
lp_build_skip_branch() pushes one 48-byte entry per nested if onto the
80-entry if_stack array, and the bound is an assert() only. The 81st
nested if writes past the array and overwrites if_stack_size and five
function pointers that follow it in the stack-allocated struct
lp_build_nir_context with Mesa pointers. The corrupted if_stack_size
then sends the next push about 2^31 entries out of range, and the
process faults.

Upstream fixed this in commit 8aae76014437 "llvmpipe: don't assert on
exceeding if_stack size" (MR 33338), first released in mesa-25.1.0.
The unchecked array exists from 24.3.0 on. trixie has 25.0.7-2+deb13u1
and is affected. bookworm (22.3.6) has no if_stack, and forky, sid and
trixie-backports are fixed. We found no CVE for it.

We reproduced it in a Debian 13 container with Xvfb and the stock mesa
25.0.7-2+deb13u1 llvmpipe. The attached nest.html compiles a fragment
shader with 90 nested ifs on load. Firefox 160.0 and 161.0b1 linked
and drew it at 80 levels and the parent process died with SIGSEGV at
81, 82, 90 and 120 levels. gdb with the Debian dbgsym package shows
the fault in lp_build_if() called from lp_build_skip_branch()
(lp_bld_nir_soa.c:2083) with if_stack_size holding 0xa0864661, the low
32 bits of the gallivm pointer plus one. The trixie package has not
changed since our runs.

The upstream commit is attached as is. It changes nine lines in one
function and applies to the 25.0.7 source.

Attached: details.txt, nest.html, mesa-8aae7601-llvmpipe-if-stack.patch.

The Security Team asked for this to be filed as a public bug.

Thanks,
ozgun kultekin, wakefield (wakefield.co)
Mesa 25.0.7 in Debian 13 trixie: llvmpipe if_stack overflow from a shader with 
more than 80 nested if statements

Package
  mesa 25.0.7-2+deb13u1 (trixie, current stable version as of 2026-11-26), 
libgallium / llvmpipe, LLVM 19.1.7.
  Upstream fix: 8aae76014437cb32fb34f7d12240e36333f4ffd8 "llvmpipe: don't 
assert on exceeding if_stack size" (MR 33338), first released in mesa-25.1.0.
  The unchecked if_stack was added in mesa-24.3.0. bookworm (22.3.6) has no 
if_stack. forky and sid (26.x) and trixie-backports (25.2.6 and later) are 
fixed.

Bug
  src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c, lp_build_skip_branch() 
(25.0.7 lines 2066-2085).
  Every NIR if that llvmpipe does not flatten pushes a struct lp_build_if_state 
(48 bytes) onto bld_base->if_stack[LP_MAX_TGSI_NESTING] (80 entries). The bound 
is an assert() only. lp_should_flatten_cf_list() never flattens a branch whose 
body holds another if, so a chain of nested ifs reaches this code.
  The 81st push writes if_stack[80]. lp_build_if() fills those 48 bytes, which 
overwrites if_stack_size with the low 32 bits of the gallivm pointer and then 
the load_ubo, load_kernel_arg, load_global, store_global and atomic_global 
function pointers that follow it in struct lp_build_nir_context (a stack local 
in lp_build_nir_soa_func).
  if_stack_size++ then holds low32(gallivm)+1, and the next push or pop indexes 
if_stack about 2^31 entries out of range.

Trigger
  nest.html: a WebGL2 page that compiles, links and draws a fragment shader 
with n nested ifs (default 90). Each level holds a loop with a uniform bound 
and a texture fetch, so the branch is neither lowered nor flattened. No user 
input.
  Open it as nest.html?n=90 in any browser that runs WebGL on llvmpipe. Native 
GL/GLES programs that compile the same shader hit the same code.

Results (Debian 13 container, Xvfb, stock mesa 25.0.7-2+deb13u1 llvmpipe, 
Firefox official builds, no user input)
  Firefox 160.0, n=60: linked and drawn, browser alive
  Firefox 160.0, n=80: linked and drawn, browser alive
  Firefox 160.0, n=90 and n=120: browser parent process exits with SIGSEGV (rc 
139) 4-7 s after load
  Firefox 161.0b1, n=80: linked and drawn, browser alive
  Firefox 161.0b1, n=81, 82, 90: browser parent process exits with SIGSEGV 
after 4 s
  Firefox runs WebGL on the parent process's CanvasRenderer thread on Linux, so 
the whole browser exits with every tab.

gdb, Firefox 160.0, n=90, Debian mesa-libgallium-dbgsym installed
  Thread 55 "CanvasRenderer" received signal SIGSEGV, Segmentation fault.
  lp_build_if (ifthen=0x801ddf6c5a50, gallivm=0x7fffa0864660, 
condition=0x7fff9ff9edf0)
  => 0x7fffddb6482a <lp_build_if+26>:  mov    %rbp,(%rbx)
  #0  lp_build_if (ifthen=0x801ddf6c5a50, gallivm=0x7fffa0864660, 
condition=0x7fff9ff9edf0)
  #1  lp_build_skip_branch (bld_base=0x7fffc63f24d0, flatten=<optimized out>) 
at ../src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c:2083
  #2  visit_if (bld_base=<optimized out>, if_stmt=0x7fffbae7a1f0) at 
../src/gallium/auxiliary/gallivm/lp_bld_nir.c:2860
  #3  visit_cf_list (bld_base=bld_base@entry=0x7fffc63f24d0, 
list=0x7fffbae7afb8) at ../src/gallium/auxiliary/gallivm/lp_bld_nir.c:2895
  #4  visit_if (...) at ../src/gallium/auxiliary/gallivm/lp_bld_nir.c:2861
  ... (visit_if / visit_cf_list repeated for every nesting level)
  p bld_base->if_stack_size = 2693154401 (0xa0864661 = low 32 bits of gallivm + 
1)
  ifthen - bld_base = 0x330 + 0xa0864661 * 48, the address derived from the 
corrupted if_stack_size.

Fix
  mesa-8aae7601-llvmpipe-if-stack.patch is the upstream commit as published. It 
applies to the 25.0.7 source (same function, nine lines).

<<< text/html; charset="US-ASCII"; name="nest.html": Unrecognized >>>

Attachment: mesa-8aae7601-llvmpipe-if-stack.patch
Description: Binary data

Reply via email to