Closed Bug 790083 Opened 14 years ago Closed 13 years ago

libsrtp reads past the end of a key buffer when setting up the internal prng (used in testing)

Categories

(Core :: WebRTC: Networking, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla19
Tracking Status
firefox18 --- affected

People

(Reporter: jesup, Assigned: jesup)

References

Details

(Whiteboard: [WebRTC], [blocking-webrtc+] [qa-])

Attachments

(3 files)

Found via ASAN. Ironically, the code documents that it reads 2 bytes past the end of the buffer. Also ironically, Google (in their Android version of libsrtp) carries a patch for this exact problem. I have my own, but it may make more sense to take theirs if it has the same characteristics -- and I'm not sure their patch is 100% safe in all cases, though in all current cases it probably is. We will plan to upstream this (or google's) patch. I'm a libsrtp maintainer, so I can update the master source as well.
Attachment #659874 - Flags: review?(ekr)
Whiteboard: [WebRTC]
Whiteboard: [WebRTC] → [WebRTC], [blocking-webrtc+]
This applies on top of the patches in bug 792325 - direct import of srtp into netwerk
Depends on: 792325
Note this also 'fixes' a case where passing certain non multiple-of-16-plus-14 sized buffers might cause it to use random stack garbage for a key. Really that's a bad case anyways, this just stops it from doing something unpredictable.
Attachment #659874 - Flags: review?(tterribe)
Comment on attachment 659874 [details] [diff] [review] Patch for past-end-of-key read Review of attachment 659874 [details] [diff] [review]: ----------------------------------------------------------------- ::: media/webrtc/trunk/third_party/libsrtp/srtp/crypto/cipher/aes_icm.c @@ +174,4 @@ > else > return err_status_bad_param; > > + /* Adds trailing whitespace. @@ +182,5 @@ > + v128_set_to_zero(&c->offset); > + > + copy_len = key_len - base_key_len; > + /* force last two octets of the offset to be left zero (for srtp compatibility) */ > + if (copy_len > 14) By my reading of the code at the top of this function, key_len may have the values 17...30, 38, or 46, and the corresponding base_key_len has the values 16, 24, or 32, respectively. So key_len - base_key_len is never larger than 14, and this check should be unnecessary. Harmless to leave it in, of course (unless you wanted to do branch coverage analysis some day). Unfortunately libsrtp doesn't appear to use asserts, or I'd recommend just replacing it with one of those to guard against future changes to the code.
Attachment #659874 - Flags: review?(tterribe) → review+
ekr: waiting for a review from you on this...
Comment on attachment 662570 [details] [diff] [review] Fix over-read in srtp (m-c direct import version) Review of attachment 662570 [details] [diff] [review]: ----------------------------------------------------------------- ::: netwerk/srtp/src/crypto/cipher/aes_icm.c @@ +173,5 @@ > base_key_len = key_len - 14; > else > return err_status_bad_param; > > + /* NIt: trailing whitespac.e
Attachment #662570 - Flags: review+
Status: NEW → RESOLVED
Closed: 13 years ago
Flags: in-testsuite?
Resolution: --- → FIXED
Without this fix, any execution of libsrtp under ASAN fails. Is that enough?
We can't easily test ASAN issues in non-ASAN builds. As this was an already-known safe read-past (with no security impact) unless the allocation happened to be at the end of a page followed by an unmapped page, there's really nothing to test.
Flags: in-testsuite? → in-testsuite-
Whiteboard: [WebRTC], [blocking-webrtc+] → [WebRTC], [blocking-webrtc+] [qa-]
Comment on attachment 659874 [details] [diff] [review] Patch for past-end-of-key read Review of attachment 659874 [details] [diff] [review]: ----------------------------------------------------------------- Cleaning up unfinished reviews
Attachment #659874 - Flags: review?(ekr) → review+
FYI, this patch has been upstreamed on the new github master for libsrtp (it's Issue 7 there)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: