Closed Bug 2018939 Opened 9 months ago Closed 8 months ago

OOB read in sec_pkcs7_verify_signature

Categories

(NSS :: Libraries, defect, P2)

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1998526

People

(Reporter: mdauer, Unassigned)

References

Details

(Keywords: ai-involved, csectype-bounds, sec-moderate)

Attachments

(1 file)

Attached patch patch.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.

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?

(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.

See Also: → 2019233
Severity: -- → S3
Priority: -- → P2
Status: NEW → RESOLVED
Closed: 8 months ago
Duplicate of bug: 1998526
Resolution: --- → DUPLICATE
Group: crypto-core-security
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: