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)
People
(Reporter: mdauer, Assigned: jschanck)
References
Details
(Keywords: ai-involved, sec-other, Whiteboard: [adv-main152-])
Attachments
(1 file, 1 external file)
|
5.37 KB,
text/plain
|
Details |
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
- Apply the attached patch:
hg import heap-overflow-ssl_DecodeResumptionToken.patch - Build with ASan:
./build.sh -c --asan - Run the test:
cd tests/ && DOMSUF="localdomain" HOST="localhost" NSS_TESTS="ssl_gtests" NSS_CYCLES="standard" GTESTFILTER="TlsConnectStreamTls13.ResumptionTokenSessionIDOverflow" ./all.sh
| Reporter | ||
Updated•8 months ago
|
| Reporter | ||
Comment 1•8 months ago
|
||
==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
| Reporter | ||
Updated•8 months ago
|
| Assignee | ||
Updated•8 months ago
|
| Assignee | ||
Updated•8 months ago
|
Comment 2•8 months ago
|
||
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?
| Assignee | ||
Comment 5•6 months ago
|
||
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
Updated•6 months ago
|
Updated•6 months ago
|
Updated•6 months ago
|
Updated•5 months ago
|
Updated•5 months ago
|
Updated•2 months ago
|
Description
•