"consumed == child->consumed" assert failed in sec_asn1d_reuse_encoding
Categories
(NSS :: Libraries, defect, P3)
Tracking
(firefox-esr91 wontfix, firefox100 wontfix, firefox101 wontfix, firefox102 fixed)
People
(Reporter: gustavo.grieco, Assigned: jschanck)
References
(Blocks 1 open bug)
Details
(Keywords: reporter-external, sec-moderate, Whiteboard: [post-critsmash-triage][adv-main102+])
Attachments
(3 files)
Comment 1•8 years ago
|
||
Updated•8 years ago
|
Comment 2•8 years ago
|
||
Comment 3•8 years ago
|
||
Comment 4•7 years ago
|
||
Comment 5•7 years ago
|
||
Comment 6•7 years ago
|
||
Comment 7•7 years ago
|
||
Updated•4 years ago
|
Assignee | ||
Comment 8•3 years ago
|
||
Took a look at this today, but did not finish. Some notes below.
Here's a der-ascii formatted reproducer.
SEQUENCE {
SEQUENCE {
INTEGER { 0 }
SEQUENCE {
OBJECT_IDENTIFIER { 0 }
}
SEQUENCE indefinite {
SET indefinite {
SEQUENCE indefinite {
OBJECT_IDENTIFIER { 2.5.4.10 }
PrintableString { "xxxxxxxx" }
}
}
}
SEQUENCE {
UTCTime { "000000000000Z" }
UTCTime { "999999999999Z" }
}
}
SEQUENCE {
OBJECT_IDENTIFIER { 2.5.4.6 }
}
BIT_STRING { 0 }
}
The issue is in the handling of
SEQUENCE indefinite {
SET indefinite {
SEQUENCE indefinite {
OBJECT_IDENTIFIER { 2.5.4.10 }
PrintableString { "xxxxxxxx" }
}
}
}
We read this chunk twice. We first save the entire sequence into a CERTCertificate derIssuer
field. Then we parse it into the issuer
field. On the second pass we seem to lose the "indefinite" flag while decoding the outer sequence and we leave an EOC unconsumed.
Apart from the assertion, this doesn't cause any problems. That's because we update the buffer position based on the number of bytes consumed in the first pass, consumed
, rather than in the second child->consumed
.
PORT_Assert(consumed == child->consumed);
[...]
state->consumed += consumed;
My sense right now is that this is a bug rather than a security issue.
Of course there's clearly a correctness problem, and it's possible that it can manifest in a more dangerous way.
Assignee | ||
Comment 9•3 years ago
|
||
An error occurs when parsing an indefinite-length encoded SEQUENCE that is inside an indefinite-length encoded GROUP (SEQUENCE-OF or SET-OF).
tldr; the parser interprets a single EOC as ending both the SEQUENCE and the GROUP containing it.
In an iteration over elements of a GROUP (sec_asn1d_next_in_group
), the child of the current state is responsible for parsing the GROUP's end-of-contents octets---a call to sec_asn1d_parse_end_of_contents(state->child)
sets the endofcontents
flag for state->child
and a later call to sec_asn1d_next_in_group
checks state->child->endofcontents
and terminates the iteration (here).
An iteration over elements of a SEQUENCE (sec_asn1d_next_in_sequence
), on the other hand, terminates when the child's template points to a template terminator (here). The current state, not its child, handles the end-of-contents octets, and a call to sec_asn1d_parse_end_of_contents(state)
sets the endofcontents
flag for state
even though this is not needed to signal the end of iteration over the SEQUENCE.
The error occurs when state
points to an indefinite-length encoded GROUP
and state->child
points to an indefinite-length encoded SEQUENCE. The call to sec_asn1d_parse_end_of_contents
to read the SEQUENCE's end-of-contents octets sets the endofcontents
flag for state->child
, and this is misinterpreted as an end-of-iteration signal for the surrounding GROUP.
When the GROUP's end-of-contents octets are present, this always leads to a decoding error. When they are not present, the decoder can mistakenly accept malformed ASN.1.
Assignee | ||
Comment 10•3 years ago
|
||
Assignee | ||
Updated•3 years ago
|
Reporter | ||
Comment 11•3 years ago
|
||
I'm the original reporter of this issue and I'm happy to see some activity 5 years after this was found.
When they are not present, the decoder can mistakenly accept malformed ASN.1.
Giver your analysis, I'm wondering if this affects certificates parsed by Firefox or it is just localized in the specific calls of the NSS printer.
Assignee | ||
Comment 12•3 years ago
|
||
This affects a legacy decoder that is not used to parse WebPKI X.509 certificates in Firefox. We need to do some further investigation to rule out an impact on PKCS#7 and PKCS#12 as used in Firefox. Our current assessment is that any possible impact is quite limited. To expand on my "accept malformed ASN.1" comment: I suspect the worst-case here is that the decoder admits an item that is missing a trailing EOC.
Assignee | ||
Comment 14•3 years ago
|
||
Assignee | ||
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Comment 15•3 years ago
|
||
Updated•3 years ago
|
Updated•3 years ago
|
Comment 16•3 years ago
|
||
We are awarding a bounty for this issue, but it's a bit on the small end I'm afraid. Our bounty program only covers NSS to the extent it's used in Firefox and this one doesn't seem to.
Updated•2 years ago
|
Updated•9 months ago
|
Description
•