Potential read beyond bounds caused by WidevineVideoFrame::InitToBlack()
Categories
(Core :: Audio/Video: GMP, defect, P3)
Tracking
()
People
(Reporter: mozillabugs, Assigned: aosmond)
References
Details
(Keywords: csectype-bounds, reporter-external, sec-moderate, Whiteboard: [adv-main114-])
Attachments
(1 file, 1 external file)
|
32.24 KB,
text/plain
|
Details |
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...
| Reporter | ||
Comment 1•3 years ago
|
||
| Reporter | ||
Comment 2•3 years ago
|
||
BTW, the more realistic sizes aWidth == 131071 and aHeight == 131071 cause the same overflow.
Updated•3 years ago
|
Comment 3•3 years ago
|
||
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
Updated•3 years ago
|
Comment 4•3 years ago
|
||
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.
Comment 5•3 years ago
|
||
The severity field is not set for this bug.
:jimm, could you have a look please?
For more information, please visit auto_nag documentation.
Updated•3 years ago
|
| Assignee | ||
Updated•3 years ago
|
| Assignee | ||
Updated•3 years ago
|
| Assignee | ||
Comment 6•3 years ago
|
||
Comment 7•3 years ago
|
||
r=media-playback-reviewers,padenot
https://hg.mozilla.org/integration/autoland/rev/d0ef58853bb1496858e18720829b15efc3f0e6c7
https://hg.mozilla.org/mozilla-central/rev/d0ef58853bb1
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•2 years ago
|
Description
•