🇰🇷 한글 설명
Zephyr의 TLS 소켓 계층에서 전역 클라이언트 세션 캐시를 관리할 때 적절한 상호 배제가 이루어지지 않아 발생하는 취약점입니다. 여러 스레드에서 동시에 TLS 연결을 시도할 경우 Use-After-Free 및 Double-Free 오류가 발생하여 mbedTLS 힙 메모리가 손상될 수 있습니다.
💡 쉬운 설명
여러 명의 사용자가 동시에 보안 연결을 시도할 때, 시스템이 공유 메모리 공간을 안전하게 잠그지 않아 데이터가 꼬이는 문제입니다. 이로 인해 프로그램이 갑자기 종료되거나 시스템이 오작동할 수 있습니다.
🇺🇸 원문 (English)
Zephyr's TLS socket layer in subsys/net/lib/sockets/sockets_tls.c keeps a single process-global array, client_cache, of cached client sessions that is shared by every TLS socket context. The functions that mutate and read it — tls_session_save(), tls_session_get(), tls_session_cache_reset(), and the settings restore handler — allocate, free, and dereference each entry's heap buffer (entry->session). Before the fix these accesses were serialized only by the per-socket context mutex ctx->lock (assigned per socket in ctx_set_lock()), which provides no mutual exclusion between different sockets touching the shared cache.
Because CONFIG_NET_SOCKETS_TLS_MAX_CLIENT_SESSION_COUNT defaults to 1, any two concurrent client sockets contend for the same slot. A thread in tls_session_get() reading entry->session inside mbedtls_ssl_session_load() can run concurrently with another thread in tls_session_save() that selects the same entry for reuse and executes mbedtls_free(entry->session) before reallocating — a use-after-free read, and a double-free when two saves evict the same entry. Both corrupt the mbedTLS heap. The cache is reached on ordinary client paths: at connect time via tls_session_store()/tls_session_restore(), and (on main) whenever a TLS 1.3 session ticket arrives during recv()/poll() via tls_session_store_current().
Exploitation requires an application that opts into per-socket client session caching (the TLS_SESSION_CACHE socket option, off by default) and runs concurrent TLS client connections on multiple threads; the timing that opens the window is influenced by the remote peer(s), so a malicious or compromised server can raise session-ticket frequency to widen it. The reliably-demonstrable impact is memory corruption leading to a crash or heap corruption (denial of service). The fix adds a dedicated session_cache_lock mutex taken across every accessor of client_cache, serializing all reads and frees and closing the race.
📍 영향받는 시스템
Zephyr OS (TLS_SESSION_CACHE 옵션이 활성화되고 멀티스레드 환경에서 실행되는 경우)
⚔️ 공격 벡터
악의적인 서버가 세션 티켓을 빈번하게 전송하여 레이스 컨디션 발생 타이밍을 조절함으로써 메모리 손상을 유도함
🛡️ 대응 방법
클라이언트 세션 캐시 접근 시 전용 뮤텍스(session_cache_lock)를 사용하여 모든 읽기 및 해제 작업을 직렬화하도록 패치 적용
🔧 검증 코드
명령어 결과로 session_cache_lock을 사용하는 코드 로직이 확인되면 취약점이 수정된 버전입니다.
grep -r "session_cache_lock" subsys/net/lib/sockets/sockets_tls.c
📊 CVSS Vector String
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H
💻 영향받는 소프트웨어
IBM WebSphere Application Server