Closed Bug 1827035 Opened 3 years ago Closed 3 years ago

Potential read beyond bounds caused by WidevineVideoFrame::InitToBlack()

Categories

(Core :: Audio/Video: GMP, defect, P3)

defect

Tracking

()

RESOLVED FIXED
114 Branch
Tracking Status
firefox-esr102 --- wontfix
firefox113 --- wontfix
firefox114 --- fixed

People

(Reporter: mozillabugs, Assigned: aosmond)

References

Details

(Keywords: csectype-bounds, reporter-external, sec-moderate, Whiteboard: [adv-main114-])

Attachments

(1 file, 1 external file)

WidevineVideoFrame::InitToBlack() (dom/media/gmp/widevine-adapter/WidevineVideoFrame.cpp) checks for overflow improperly, potentially underallocating a buffer and causing a consequent read beyond bounds. The bug is in line 107, which can -- despite the comment on line 106 -- experience an overflow because it uses int32_t math, while the CheckedInt expressions on lines 104-05 use uint64_t math (in the dominant 64-bit builds):

   100: bool WidevineVideoFrame::InitToBlack(int32_t aWidth, int32_t aHeight,
   101:                                      int64_t aTimeStamp) {
   102:   MOZ_ASSERT(aWidth >= 0 && aHeight >= 0,
   103:              "Frame dimensions should be positive");
   104:   CheckedInt<size_t> ySizeChk = aWidth;
   105:   ySizeChk *= aHeight;
   106:   // If w*h didn't overflow, half of them won't.
   107:   const size_t uSize = ((aWidth + 1) / 2) * ((aHeight + 1) / 2);
   108:   CheckedInt<size_t> yuSizeChk = ySizeChk + uSize;
   109:   if (!yuSizeChk.isValid()) {
   110:     return false;
   111:   }
   112:   WidevineBuffer* buffer = new WidevineBuffer(yuSizeChk.value());
   113:   const size_t& ySize = ySizeChk.value();
   114:   // Black in YCbCr is (0,128,128).
   115:   memset(buffer->Data(), 0, ySize);
   116:   memset(buffer->Data() + ySize, 128, uSize); [won't WBB because uSize == 0]
   ...
   124:   SetPlaneOffset(cdm::VideoPlane::kYPlane, 0); [OK]
   125:   SetStride(cdm::VideoPlane::kYPlane, aWidth);
   126:   // Note: U and V planes are stored at the same place in order to
   127:   // save memory since their contents are the same.
   128:   SetPlaneOffset(cdm::VideoPlane::kUPlane, ySize); [Oh-oh, beyond bounds!]
   129:   SetStride(cdm::VideoPlane::kUPlane, (aWidth + 1) / 2);
   130:   SetPlaneOffset(cdm::VideoPlane::kVPlane, ySize); [Oh-oh, beyond bounds!]
   131:   SetStride(cdm::VideoPlane::kVPlane, (aWidth + 1) / 2);
   132:   SetTimestamp(aTimeStamp);
   133: 
   134:   return true;
   135: }

I have verified the overflow in a sample program (attached) that uses CheckedInt with aWidth = 0x7fffffff, aHeight == 7 and aTimeStamp == 0. Under these conditions, uSize overflows to 0, which would cause the frame's U and V planes to be located beyond the buffer's end (lines 128 and 130). The sample program builds in VS 2022. Change the path in the #include of IntegerTypeTraits.h appropriately for your build system.

So far I have been unable to cause FF to call this function; when I attempt to load Widevine content from https://shaka-player-demo.appspot.com/demo , FF's plugin_container process hangs forever inside the Widevine DLL on the call to create() from ChromiumCDMAdapter::GMPGetAPI(), so I don't know whether some other check prevents such a large aWidth from getting into InitToBlack().

See also https://bugzilla.mozilla.org/show_bug.cgi?id=1349604 which didn't quite fix the problem...

Flags: sec-bounty?
Attached file ffbug_2120.cpp —

BTW, the more realistic sizes aWidth == 131071 and aHeight == 131071 cause the same overflow.

Group: core-security → media-core-security
Keywords: csectype-bounds

Those sizes don't sound all that realistic for commercial DRMd content. How easily can random malicious people get production tools and (certs/keys/licenses/whatever) to create this content? If it's easy maybe we should call this sec-high

Flags: needinfo?(dminor)
Keywords: sec-moderate
Flags: needinfo?(dminor) → needinfo?(kinetik)

We should fix the code here, but as far as I can tell, it's not possible for WidevineVideoFrame::InitToBlack() to be called with aWidth or aHeight larger than 65535 - for MP4 it's limited here by the 16.16 fixed point conversion and for WebM it's limited here by the IsValidVideoRegion() check which limits the region to a maximum of 16384x16384.

Flags: needinfo?(kinetik)

The severity field is not set for this bug.
:jimm, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(jmathies)
Flags: needinfo?(jmathies) → needinfo?(aosmond)
Assignee: nobody → aosmond
Severity: -- → S3
Priority: -- → P3
Flags: needinfo?(aosmond)
Attached file Bug 1827035. —
Group: media-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 114 Branch
Flags: sec-bounty? → sec-bounty+
Whiteboard: [adv-main114]
Whiteboard: [adv-main114] → [adv-main114+]
See Also: → 1349604
Whiteboard: [adv-main114+] → [adv-main114-]
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: