Closed Bug 2020596 Opened 8 months ago Closed 6 months ago

Heap buffer overflow in ssl_DecodeResumptionToken via oversized sessionID

Categories

(NSS :: Libraries, defect, P2)

Tracking

(nss 3.124, firefox-esr115 wontfix, firefox-esr140 wontfix, firefox150 wontfix, firefox151 wontfix, firefox152 fixed)

RESOLVED FIXED
Tracking Status
nss --- 3.124
firefox-esr115 --- wontfix
firefox-esr140 --- wontfix
firefox150 --- wontfix
firefox151 --- wontfix
firefox152 --- fixed

People

(Reporter: mdauer, Assigned: jschanck)

References

Details

(Keywords: ai-involved, sec-other, Whiteboard: [adv-main152-])

Attachments

(1 file, 1 external file)

ssl_DecodeResumptionToken in lib/ssl/sslnonce.c copies a variable-length sessionID (up to 255 bytes, controlled by a 1-byte length prefix) into the fixed 32-byte sid->u.ssl3.sessionID buffer without bounds checking. This causes a heap buffer overflow of up to 223 bytes when processing a crafted resumption token via SSL_SetResumptionToken.

if (sslRead_ReadVariable(&reader, 1, &readerBuffer) != SECSuccess) {
    PORT_SetError(SEC_ERROR_INVALID_ARGS);
    return SECFailure;
}
if (readerBuffer.len) {
    PORT_Assert(readerBuffer.buf);
    PORT_Memcpy(sid->u.ssl3.sessionID, readerBuffer.buf, readerBuffer.len);
    //          ^^^^ 32 bytes                              ^^^^ up to 255 bytes
}

The overflow corrupts adjacent heap fields including SECItem pointers (srvName, signedCertTimestamps, alpnSelection), causing invalid frees via ssl_FreeSID. The resumption token lacks cryptographic integrity protection, so an attacker with write access to stored tokens (e.g., compromised session cache) can trigger the overflow. A network MITM or malicious TLS peer cannot trigger this bug.

STR

  1. Apply the attached patch: hg import heap-overflow-ssl_DecodeResumptionToken.patch
  2. Build with ASan: ./build.sh -c --asan
  3. Run the test: cd tests/ && DOMSUF="localdomain" HOST="localhost" NSS_TESTS="ssl_gtests" NSS_CYCLES="standard" GTESTFILTER="TlsConnectStreamTls13.ResumptionTokenSessionIDOverflow" ./all.sh
Attachment #9549332 - Attachment is patch: false
==17107==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7ff1ef241e32 bp 0x7ffee3e23790 sp 0x7ffee3e23750 T0)
==17107==The signal is caused by a READ memory access.
==17107==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
    #0 0x7ff1ef241e32 in bool __sanitizer::atomic_compare_exchange_strong<__sanitizer::atomic_uint8_t>(__sanitizer::atomic_uint8_t volatile*, __sanitizer::atomic_uint8_t::Type*, __sanitizer::atomic_uint8_t::Type, __sanitizer::memory_order) /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_atomic_clang.h:84
    #1 0x7ff1ef241e32 in __asan::Allocator::AtomicallySetQuarantineFlagIfAllocated(__asan::AsanChunk*, void*, __sanitizer::BufferedStackTrace*) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_allocator.cpp:668
    #2 0x7ff1ef241e32 in __asan::Allocator::Deallocate(void*, unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_allocator.cpp:732
    #3 0x7ff1ef31f75a in free /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:52
    #4 0x7ff1ef0c3749 in PR_Free ../../../../pr/src/malloc/prmem.c:449
    #5 0x7ff1ef1ab28b in PORT_Free_Util ../../lib/util/secport.c:173
    #6 0x7ff1ef1a800c in SECITEM_FreeItem_Util ../../lib/util/secitem.c:288
    #7 0x55c550c36f88 in ssl_DestroySID ../../lib/ssl/sslnonce.c:179
    #8 0x55c550c3725e in ssl_FreeLockedSID ../../lib/ssl/sslnonce.c:222
    #9 0x55c550c37285 in ssl_FreeSID ../../lib/ssl/sslnonce.c:237
    #10 0x55c550c67305 in SSLExp_SetResumptionToken ../../lib/ssl/sslsock.c:4650
    #11 0x55c5507d3518 in nss_test::TlsConnectStreamTls13_ResumptionTokenSessionIDOverflow_Test::TestBody() ../../gtests/ssl_gtest/ssl_resumption_unittest.cc:1644
    #12 0x55c550b8d0cc in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ../../gtests/google_test/gtest/src/gtest.cc:2607
    #13 0x55c550b7989a in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ../../gtests/google_test/gtest/src/gtest.cc:2643
    #14 0x55c550b2d3f8 in testing::Test::Run() ../../gtests/google_test/gtest/src/gtest.cc:2682
    #15 0x55c550b2e92e in testing::TestInfo::Run() ../../gtests/google_test/gtest/src/gtest.cc:2861
    #16 0x55c550b2fd41 in testing::TestSuite::Run() ../../gtests/google_test/gtest/src/gtest.cc:3015
    #17 0x55c550b522c4 in testing::internal::UnitTestImpl::RunAllTests() ../../gtests/google_test/gtest/src/gtest.cc:5855
    #18 0x55c550b90534 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ../../gtests/google_test/gtest/src/gtest.cc:2607
    #19 0x55c550b7c38a in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ../../gtests/google_test/gtest/src/gtest.cc:2643
    #20 0x55c550b4e984 in testing::UnitTest::Run() ../../gtests/google_test/gtest/src/gtest.cc:5438
    #21 0x55c5505cd599 in RUN_ALL_TESTS() ../../gtests/google_test/gtest/include/gtest/gtest.h:2490
    #22 0x55c5505cd869 in main ../../gtests/ssl_gtest/ssl_gtest.cc:47
    #23 0x7ff1ee836634  (/usr/lib/libc.so.6+0x27634) (BuildId: 5e2075850f8de86da4eead11213c59d926ca3796)
    #24 0x7ff1ee8366e8 in __libc_start_main (/usr/lib/libc.so.6+0x276e8) (BuildId: 5e2075850f8de86da4eead11213c59d926ca3796)
    #25 0x55c550103bd4 in _start (/home/mdauer/Mercurial/dist/Debug/bin/ssl_gtest+0x235bd4) (BuildId: ded0f79041b07bf5e71921c15c049c8857800a1d)

==17107==Register values:
rax = 0x0000000000000002  rbx = 0x00007ff1ef3c8980  rcx = 0x0000000000000000  rdx = 0x0000000000000003
rdi = 0x4141414141414141  rsi = 0x4141414141414141  rbp = 0x00007ffee3e23790  rsp = 0x00007ffee3e23750
 r8 = 0x00007ffee3e237b0   r9 = 0x0000000000000001  r10 = 0x0000000000000016  r11 = 0x000055c550103bd5
r12 = 0x00007ffee3e237b0  r13 = 0x4141414141414141  r14 = 0x4141414141414131  r15 = 0x0000000000000001
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../../../../pr/src/malloc/prmem.c:449 in PR_Free
Keywords: ai-involved
Severity: -- → S3
Priority: -- → P2
Assignee: nobody → jschanck
Status: NEW → ASSIGNED

an attacker with write access to stored tokens (e.g., compromised session cache) can trigger the overflow

Seems like that requires an attacker who has already achieved a sandbox escape?

Keywords: sec-other
Duplicate of this bug: 2023205
Duplicate of this bug: 2027368
Attached file (secure) —

Pushed by jschanck@mozilla.com:
https://hg.mozilla.org/projects/nss/rev/ec2bed6e28a5
add runtime check on decoded resumption token session id. r=nss-reviewers,djackson

Status: ASSIGNED → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Group: crypto-core-security → core-security-release
QA Whiteboard: [sec] [qa-triage-done-c153/b152]
Whiteboard: [adv-main-152-]
Whiteboard: [adv-main-152-] → [adv-main152-]
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: