Closed
Bug 1226804
Opened 11 years ago
Closed 10 years ago
UBSan: signed integer overflow in CERT_DecodeCertPackage
Categories
(NSS :: Libraries, defect)
NSS
Libraries
Tracking
(firefox45 affected)
RESOLVED
FIXED
3.24
| Tracking | Status | |
|---|---|---|
| firefox45 | --- | affected |
People
(Reporter: tsmith, Assigned: franziskus)
References
(Blocks 1 open bug)
Details
(Keywords: csectype-intoverflow, testcase)
Attachments
(2 files, 1 obsolete file)
|
17 bytes,
application/x-x509-ca-cert
|
Details | |
|
1.38 KB,
patch
|
mt
:
review+
|
Details | Diff | Splinter Review |
I found this while fuzzing the CERT_DecodeCertFromPackage function.
It seems that this can lead to returning the wrong error type. Not sure how bad that is but the code would not be behaving as expected.
https://dxr.mozilla.org/mozilla-central/source/security/nss/lib/pkcs7/certread.c#334
certread.c:334:31: runtime error: signed integer overflow: 2147483647 + 4 cannot be represented in type 'int'
#0 0x7f84cf5101d0 in CERT_DecodeCertPackage /home/user/code/san_nss/nss/lib/pkcs7/certread.c:334:31
#1 0x7f84cf515187 in CERT_DecodeCertFromPackage /home/user/code/san_nss/nss/lib/pkcs7/certread.c:532:10
#2 0x4dfb87 in Fuzz_CERT_DecodeCertFromPackage /home/user/code/san_nss/nss/cmd/checkcert/checkcert.c:87:10
#3 0x4e12d1 in fuzz /home/user/code/san_nss/nss/cmd/checkcert/checkcert.c:185:5
#4 0x4e267c in main /home/user/code/san_nss/nss/cmd/checkcert/checkcert.c:248:5
#5 0x7f84cc044ec4 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287
#6 0x419305 in _start (/home/user/Desktop/cert-decode/checkcert+0x419305)
SUMMARY: AddressSanitizer: undefined-behavior certread.c:334:31 in
| Reporter | ||
Comment 1•11 years ago
|
||
| Reporter | ||
Updated•11 years ago
|
Summary: UBSan: left shift of negative value in DER_GetInteger_Util → UBSan: signed integer overflow in CERT_DecodeCertPackage
| Assignee | ||
Comment 2•10 years ago
|
||
I'm a bit confused here. This breaks in CERT_DecodeCertFromPackage but checkcert.c is never calling that function. What are you using to produce this error?
To fix this it should probably be sufficient to make sure that (seqLen + seqLenLen + 2) is big enough to hold int+int+2 in certread.c:334 and certread.c:335.
Flags: needinfo?(twsmith)
| Reporter | ||
Comment 3•10 years ago
|
||
(In reply to Franziskus Kiefer [:fkiefer or :franziskus] from comment #2)
> I'm a bit confused here. This breaks in CERT_DecodeCertFromPackage but
> checkcert.c is never calling that function. What are you using to produce
> this error?
I have replaced checkcert.c with a fuzzer :) It is calling CERT_DecodeCertFromPackage with the fuzzed DER data. Nothing special I am just using an existing tools place in the build as a hack to build my fuzzer.
Flags: needinfo?(twsmith)
| Assignee | ||
Comment 4•10 years ago
|
||
Making seqLen and seqLenLen long solves the overflow and thus sets the correct error.
I don't think this is a security critical bug as the function fails anyway but sets SEC_ERROR_EXTRA_INPUT instead of SEC_ERROR_INPUT_LEN.
Assignee: nobody → franziskuskiefer
Attachment #8707833 -
Flags: review?(martin.thomson)
Comment 5•10 years ago
|
||
Comment on attachment 8707833 [details] [diff] [review]
Bug1226804.patch
Review of attachment 8707833 [details] [diff] [review]:
-----------------------------------------------------------------
I think that you need PRUint64 here. long is only guaranteed to be 32 bits wide. Not that this will ever happen in practice, of course.
BTW, this code is not particularly good. It looks more like a BER decoder than a DER decoder.
Attachment #8707833 -
Flags: review?(martin.thomson)
Comment 6•10 years ago
|
||
That's because it is. It's PKCS#7. CMS uses BER. Mozilla and Microsoft both support cert packages delivered in BER form (Microsoft via the CMS flag, Mozilla implicitly)
| Reporter | ||
Comment 7•10 years ago
|
||
(In reply to Franziskus Kiefer [:fkiefer or :franziskus] from comment #4)
> I don't think this is a security critical bug as the function fails anyway
> but sets SEC_ERROR_EXTRA_INPUT instead of SEC_ERROR_INPUT_LEN.
Should I unhide this issue? If not what should the sec-rating be?
| Assignee | ||
Comment 8•10 years ago
|
||
now with PRUint64
I think we can unhide this. Getting a wrong error code here is of no use to anyone afaik.
Attachment #8707833 -
Attachment is obsolete: true
Attachment #8709923 -
Flags: review?(martin.thomson)
| Reporter | ||
Updated•10 years ago
|
Group: crypto-core-security
Comment 9•10 years ago
|
||
Comment on attachment 8709923 [details] [diff] [review]
Bug1226804.patch
Review of attachment 8709923 [details] [diff] [review]:
-----------------------------------------------------------------
Let's wait for 3.23 to start before landing this one.
Attachment #8709923 -
Flags: review?(martin.thomson) → review+
| Assignee | ||
Comment 10•10 years ago
|
||
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → 3.24
You need to log in
before you can comment on or make changes to this bug.
Description
•