Skip to content
Memory corruption Disclosed report CVE-2016-1971

Missing status check in I420VideoFrame::CreateFrame creates memory-safety bug

q1 Follow

Originally disclosed on Mozilla

  • Fixed in 44 days
  • Paid in 53 days
  • Disclosed after 44 days
Text
I420VideoFrame::CreateFrame (media\webrtc\trunk\webrtc\common_video\i420_video_frame.cc) doesn't check (or propagate) the return code from its calls to Plane::Copy. In consequence, if Plane::Copy fails due to OOM (which could be intermittent), CreateFrame still sets its |width_| and |height_| members. If the new height and/or width are larger than the old one(s), this causes other code (such as ViEExternalRendererImpl::RenderFrame) to use the larger height and/or width when reading the frame's plane buffers, which causes that code to read memory to which it has no right.

The bug is still present in today's trunk: http://hg.mozilla.org/mozilla-central/file/5a6ef7c09c12/media/webrtc/trunk/webrtc/common_video/i420_video_frame.cc .

Details
-------

The bug is in lines 57-9: 

48: int I420VideoFrame::CreateFrame(int size_y, const uint8_t* buffer_y,
49:                                 int size_u, const uint8_t* buffer_u,
50:                                 int size_v, const uint8_t* buffer_v,
51:                                 int width, int height,
52:                                 int stride_y, int stride_u, int stride_v) {
53:   if (size_y < 1 || size_u < 1 || size_v < 1)
54:     return -1;
55:   if (CheckDimensions(width, height, stride_y, stride_u, stride_v) < 0)
56:     return -1;
57:   y_plane_.Copy(size_y, stride_y, buffer_y);
58:   u_plane_.Copy(size_u, stride_u, buffer_u);
59:   v_plane_.Copy(size_v, stride_v, buffer_v);
60:   width_ = width;
61:   height_ = height;
62:   return 0;
63: }

The definition of Plane::Copy (from media\webrtc\trunk\webrtc\common_video\plane.cc) is thus:

69: int Plane::Copy(int size, int stride, const uint8_t* buffer) {
70:   if (MaybeResize(size) < 0)
71:     return -1;
72:   memcpy(buffer_.get(), buffer, size);
73:   plane_size_ = size;
74:   stride_ = stride;
75:   return 0;
76: }


The bug can be simulated in the debugger as follows:

   1.  Start FF with one window, one tab;
   2.  Start FF Hello and create a conversation;
   3.  Undock the Hello window from the main window;
   4.  Copy the conversation link into the address bar and join the conversation;
   5.  Share tabs in the Hello window after it's connected;
   6.  Attach a debugger to FF;
   7.  Set a breakpoint on I420VideoFrame::CreateFrame at the call to |y_plane_.Copy| with the condition |height != height_|.
   8.  Rapidly increase the vertical size of the main window;
   9.  When the breakpoint fires:
       a. record the values of |height| and |height_|; and
       b. step into each call to |plane::Copy| and simulate an OOM by skipping the call to |MaybeResize| and instead giving control to |return -1;|

   10. Notice how I420VideoFrame::CreateFrame unconditionally sets |height_ = height|.
   11. Set a breakpoint on ViEExternalRendererImpl::RenderFrame (media\webrtc\trunk\webrtc\video_engine\vie_renderer.cc), where it calls ExtractBuffer.
   12. Let execution proceed.
   13. When the breakpoint fires, step into ExtractBuffer (module webrtc_libyuv.cc) and examine |input_frame.height|. It should be the same as the new value you saw at the breakpoint in I420VideoFrame::CreateFrame;
   14. Now compute |input_frame.y_plane.allocated_size_ / input_frame.y_plane.stride_| and notice that it equals the old, smaller value of |height_| instead of |input_frame.height|.
   15. Notice how ExtractBuffer uses |input_frame.height()| (== |input_frame.height|) to compute the bounds for its inner |for| loop;
   16. If you're using WinDBG (but not VS, alas) set a read breakpoint on the byte just beyond the buffer's end, let execution proceed, and watch it fire (or, if you increased the size of the window a lot, watch it read access-violate).

The original report as published on Mozilla's Bugzilla, by q1. 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 medium-severity memory corruption bug in WebRTC: Audio/Video. Mozilla made it public on 5 December 2015 as CVE-2016-1971.

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 q1

View all

71 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.