OOB read in sec_pkcs7_verify_signature
Categories
(NSS :: Libraries, defect, P2)
Tracking
(Not tracked)
People
(Reporter: mdauer, Unassigned)
References
Details
(Keywords: ai-involved, csectype-bounds, sec-moderate)
Attachments
(1 file)
|
4.59 KB,
patch
|
Details | Diff | Splinter Review |
A crafted PKCS#7 SignedData message can cause sec_pkcs7_verify_signature() to read past the end of the digests[] array.
During decoding, digestAlgorithms[] retains every entry from the encoded message (including unrecognized OIDs), but digests[] only gets entries for recognized algorithms, unrecognized ones are skipped in sec_pkcs7_decoder_start_digests(). With input [unknown, unknown, SHA-256]:
digestAlgorithms[]: [unknown, unknown, SHA-256, NULL] — 3 entries
digests[]: [sha256_result, NULL] — 1 entry (16 bytes)
The verification loop searches digestAlgorithms[] for the signer's hash, finds SHA-256 at index 2, then reads digests[2] — 8 bytes past the end of the allocation:
for (i = 0; digestalgs[i] != NULL; i++) {
if (SECOID_FindOIDTag(&(digestalgs[i]->algorithm)) == digestTag)
break;
}
digest = digests[i]; // i == 2, but digests[] only has indices 0..1
I've attached a testcase that triggers an ASan crash. Since digests is arena-allocated and the OOB read is therefore technically access to valid memory from the perspective of ASan, the testcase manually allocates and copies the digests array.
Comment 1•9 months ago
|
||
Thanks Maurice! Do you think it's feasible to adjust our arena code in secport.c to manually poison (and unpoison) allocated but unused regions with ASAN?
| Reporter | ||
Comment 2•9 months ago
|
||
(In reply to Dennis Jackson from comment #1)
Thanks Maurice! Do you think it's feasible to adjust our arena code in secport.c to manually poison (and unpoison) allocated but unused regions with ASAN?
The arena related functions in NSPR already use PL_MAKE_MEM_NOACCESS , PL_MAKE_MEM_UNDEFINED and PL_MAKE_MEM_DEFINED to manually (un)poision memory inside the arena. The issue here is that we don't have redzones in between memory allocated inside the arena.
I'm not sure how much work it is to actually implement in NSPR, but I'm looking into that. It would certainly help us catch bugs that we may have missed so far.
Updated•8 months ago
|
Updated•8 months ago
|
Updated•8 months ago
|
Updated•2 months ago
|
Description
•