Skip to content
Disclosed report CVE-2012-0441

Insufficient length checking in QuickDER decoder

Kaspar Follow

Originally disclosed on Mozilla

  • Fixed in 3 months
  • Paid in 18 months
  • Disclosed after 3 months
Text
Created attachment 585661
Possible fix

I'm afraid I have to begin the new year with not so nice news - the "QuickDER" ASN.1 decoder in NSS has a flaw with rather serious consequences: while it rejects bogus (oversized) lengths when trying to match a buffer against a given template, it fails to properly detect a number of zero-length items which are illegal as per X.690.

This can cause all sorts of troubles: one of them is reported in bug 697420 (which happened to be the starting point for my discovery, actually). Depending on what exactly NSS - or the application - does after having called SEC_QuickDERDecodeItem, nasty bugs will occur, such as:

1) CERT_DecodeOCSPResponse() will mistakenly assume that it has successfully parsed a response, even if that response includes a zero-length ENUMERATED value. It will return the response to the caller, and when code subsequently - and rightfully - tries to clean up said response, CERT_DestroyOCSPResponse() will crash... because it's getting a bogus pointer from ocsp_GetResponseSignature(response), which it tries to dereference.

2) CERT_DecodeBasicConstraintValue is another case where illegal zero-length items lead to a serious problem: if a certificate includes a basicConstraints extension where the "CA" BOOLEAN is encoded with zero length, NSS mistakenly treats such a cert as a CA certificate (not as bad as Moxie's findings from 2002 about MS CAPI and basicConstraints, but still, quite worrying).

I stopped looking for further issues at that point, but it would be quite surprising if these were the only ones. From my reading of X.690, of the 25 ASN.1 UNIVERSAL types currently recognized/defined in secasn1t.h, the following 7 can never have zero length (when properly DER encoded): BOOLEAN, INTEGER, BIT STRING, OBJECT_IDENTIFIER, ENUMERATED, UTCTime, GeneralizedTime. QuickDER should abort further processing when the template specifies one of these types and the buffer being processed holds such an illegal encoding.

It's probably debatable what level of content checking should go into QuickDER (and what checks are better done in code which actually parses the values, such as DER_GetInteger), but some minimal zero-length sanity checks seem justified in QuickDER. The attached patch is a possible approach; note that due to re-indentation, the changes might appear larger at first sight than they effectively are.

A demo "exploit" for the two issues mentioned above can be seen by visiting https://orod.velox.ch. First, the CA cert attached to this bug needs to be installed and trusted for SSL. A default setup of Firefox will then crash immediately in CERT_DestroyOCSPResponse() when opening the above URL. Note that the "CA cert" isn't really a certificate with "CA" set to TRUE, but NSS considers it a valid CA cert.

As ASN.1 is at the heart of many parts of NSS (there are dozens of SEC_QuickDERDecodeItem calls in lib/, X.509/PKIX processing heavily depends on it), the potential impact of this issue should not be underestimated. Applications - and NSS itself - must be able to rely on SEC_QuickDERDecodeItem() rejecting invalid ASN.1 data, when asked to match this input against a given template. Note that the "classic" DER decoder, i.e. SEC_ASN1DecodeItem, has checks for illegal zero-length items, and will e.g. reject an OCSP response where the response status isn't encoded properly.

Finally, let me point out that the patch also includes a second, belt-and-suspenders type fix: when returning a "dest" item with zero length (for those ASN.1 types where this is acceptable as per X.690, such as strings), QuickDER should not fill bogus pointers into dest->data - if code dealing with a SECItem afterwards only checks for a non-NULL data pointer without looking at the SECItem's length at the same time, even more subtle bugs may surface (the CERT_DecodeBasicConstraintValue actually being an example of this).

I did not yet request a CVE ID number for this issue - let me know if I should do this, or if Mozilla can get an assignment.

The original report as published on Mozilla's Bugzilla, by Kaspar. 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 security bug in Libraries. Mozilla made it public on 31 March 2012 as CVE-2012-0441.

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