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

Underflow in srtp_unprotect could cause memory-safety bug

q1 Follow

Originally disclosed on Mozilla

  • Fixed in 48 days
  • Paid in 55 days
  • Disclosed after 48 days
Text
srtp_unprotect (netwerk\srtp\src\srtp\srtp.c) can experience an integer underflow. If it does, it calls a decryption function with a buffer pointer pointing to memory to which it has no right, and with a very large buffer length. This call could scramble large portions of memory, causing incorrect and possibly insecure behavior.

It is unclear whether the bug can be invoked, because that depends upon behavior of a decryption function that I don't currently understand.

(There is also a similar bug in srtp_unprotect_rtcp).


Details
-------

The bug is in this code:

950: err_status_t
951: srtp_unprotect(srtp_ctx_t *ctx, void *srtp_hdr, int *pkt_octet_len) {
...
1073:   if (stream->rtp_services & sec_serv_conf) {
1074:     enc_start = (uint32_t *)hdr + uint32s_in_rtp_header + hdr->cc;  
1075:     if (hdr->x == 1) {
1076:       srtp_hdr_xtnd_t *xtn_hdr = (srtp_hdr_xtnd_t *)enc_start;
1077:       enc_start += (ntohs(xtn_hdr->length) + 1);
1078:     }  
1079:     enc_octet_len = (uint32_t)(*pkt_octet_len - tag_len 
1080: 			       - ((enc_start - (uint32_t *)hdr) << 2));
1081:   } else {
1082:     enc_start = NULL;
1083:   }
...
1162:   if (enc_start) {
1163:     status = cipher_decrypt(stream->rtp_cipher, 
1164: 			    (uint8_t *)enc_start, &enc_octet_len);
1165:     if (status)
1166:       return err_status_cipher_fail;
1167:   }

which does not check whether |hdr->cc| (line 1074) and |xtn_hdr->length| (line 1077) are such that any portion of the region described by |enc_start| and |enc_octet_len| lies outside of the packet that begins at |hdr| and extends for |*pkt_octet_len| bytes.

When using Firefox Hello, |cipher_decrypt| devolves to |aes_icm_encrypt_ismacryp| (netwerk\srtp\src\crypto\cipher\aes_icm.c), which checks the decryption buffer length thusly:

344: err_status_t
345: aes_icm_encrypt_ismacryp(aes_icm_ctx_t *c,
346:               unsigned char *buf, unsigned int *enc_len, 
347:               int forIsmacryp) {
348:   unsigned int bytes_to_encr = *enc_len;
349:   unsigned int i;
350:   uint32_t *b;
351:
352:   /* check that there's enough segment left but not for ismacryp*/
353:   if (!forIsmacryp && (bytes_to_encr + htons(c->counter.v16[7])) > 0xffff)
354:     return err_status_terminus;
...

with |forIsmacryp| == false. I don't understand how |c->counter.v16[7]| is used. If it can ever be >= 0x0400 (>= 4 when decoded), then an attacking peer can send a malformed packet that yields an |*enc_len| <= 0xfffffffc, which will pass the test on line 353 and cause aes_icm_encrypt_ismacryp to scramble |*enc_len| bytes of memory.

|c->counter.v16[7]| has never been nonzero in my testing using Firefox Hello.

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: Networking. Mozilla made it public on 7 December 2015 as CVE-2016-1970.

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.