Skip to content
Memory corruption Disclosed report Advanced

Missing bounds check in RtpHeaderParser::ParseOneByteExtensionHeader() causes reads beyond buffer end

The RTP header extension parser reads extension data without checking that the packet contains enough bytes for the declared length. An attacker could send a malformed RTP packet to cause out-of-bounds reads, though the reporter is unsure if this is exploitable.

q1 Follow

Originally disclosed on Mozilla

  • Fixed in 11 months
  • Paid in 9 months
  • Disclosed after 11 months
Text
RtpHeaderParser::ParseOneByteExtensionHeader() (media\webrtc\trunk\webrtc\modules\rtp_rtcp\source\rtp_utility.cc) reads data from a packet extension without first checking whether the packet is long enough to contain the data.

This omission can cause the function to read data beyond the packet's end.

I am unsure whether this bug can be manifested.

This bug still exists in trunk.

Details:

370: void RtpHeaderParser::ParseOneByteExtensionHeader(
371:     RTPHeader& header,
372:     const RtpHeaderExtensionMap* ptrExtensionMap,
373:     const uint8_t* ptrRTPDataExtensionEnd,
374:     const uint8_t* ptr) const {
375:   if (!ptrExtensionMap) {
376:     return;
377:   }
378: 

Line 379 validates the reads on line 388-89...

379:   while (ptrRTPDataExtensionEnd - ptr > 0) {
380:     //  0
381:     //  0 1 2 3 4 5 6 7
382:     // +-+-+-+-+-+-+-+-+
383:     // |  ID   |  len  |
384:     // +-+-+-+-+-+-+-+-+
385: 
386:     // Note that 'len' is the header extension element length, which is the
387:     // number of bytes - 1.
388:     const uint8_t id = (*ptr & 0xf0) >> 4;
389:     const uint8_t len = (*ptr & 0x0f);
390:     ptr++;
391: ...
398:     RTPExtensionType type;
399:     if (ptrExtensionMap->GetType(id, &type) != 0) {
400:       // If we encounter an unknown extension, just skip over it.
401:       LOG(LS_WARNING) << "Failed to find extension id: "
402:                       << static_cast<int>(id);
403:     } else {
404:       switch (type) {

...but none of the cases check |len| (read from the packet on line 389) against |ptrRTPDataExtensionEnd - ptr| to see whether the packet extension contains enough data to allow |len| bytes to be read. So, for example, lines 417-18, below, read 3 bytes from the location at |ptr|, even though |ptrRTPDataExtensionEnd - ptr| would == 0 if, on entry, |ptrRTPDataExtensionEnd - ptr| had been 1:

405:         case kRtpExtensionTransmissionTimeOffset: {
406:           if (len != 2) {
407:             LOG(LS_WARNING) << "Incorrect transmission time offset len: "
408:                             << len;
409:             return;
410:           }
411:           //  0                   1                   2                   3
412:           //  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
413:           // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
414:           // |  ID   | len=2 |              transmission offset              |
415:           // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
416: 
417:           header.extension.transmissionTimeOffset =
418:               ByteReader<int32_t, 3>::ReadBigEndian(ptr);
419:           header.extension.hasTransmissionTimeOffset = true;
420:           break;
421:         }

All of the remaining cases do something similar, including the last, which reads a string:

493:         case kRtpExtensionRID: {
494:           //   0                   1                   2
495:           //   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
496:           //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
497:           //  |  ID   | L=?   |UTF-8 RID value......          |...
498:           //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
499: 
500:           // TODO(jesup) - avoid allocating on each packet - high watermark the RID buffer?
501:           char* ptrRID = new char[len+1];
502:           memcpy(ptrRID, ptr, len);
503:           ptrRID[len] = '\0';
504:           header.extension.rid = ptrRID;
505:           header.extension.hasRID = true;
506:           break;
507:         }
...
512:       }
513:     }
514:     ptr += (len + 1);
515:     uint8_t num_bytes = ParsePaddingBytes(ptrRTPDataExtensionEnd, ptr);
516:     ptr += num_bytes;
517:   }
518: }

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.

How it worked

Root cause

The parser does not validate the extension element length against the remaining packet size before reading the element's data.

Impact

A malformed RTP packet could cause out-of-bounds reads, potentially leading to a crash or information disclosure, but the reporter is unsure whether the bug can be manifested.

What the attacker needed

Ability to send crafted RTP packets

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

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

When a program reads data from a network packet, it must first check that the packet is actually long enough to hold the data it expects. Here, the code trusts a length value inside the packet and reads that many bytes without verifying the packet has them, so it can read past the end of the buffer. This is called an out-of-bounds read and can crash the program or leak memory.

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.