🇰🇷 한글 설명
Zephyr RTOS의 엔트로피 기반 난수 생성기(rand_get)가 엔트로피 장치가 준비되지 않았을 때 -ENODEV를 반환하며 조기 종료하고, 호출자의 출력 버퍼를 초기화하지 않은 채 남겨 이전 메모리 내용이 난수로 반환됩니다. 이로 인해 CoAP 토큰, TCP 초기 시퀀스 번호, DHCP 트랜잭션 ID 등 비암호학적 난수 값이 상수이거나 오래된 메모리 값이 되어 네트워크로 노출될 수 있습니다.
💡 쉬운 설명
기기의 난수 생성 장치가 준비되지 않으면 무작위여야 할 값 대신 고정된 값이나 이전에 쓰이던 메모리 내용이 사용됩니다. 이 때문에 공격자가 예측하거나 네트워크로 전송된 메모리 정보를 엿볼 수 있습니다.
🇺🇸 원문 (English)
The entropy-device random number generator in subsys/random/random_entropy_device.c returned early with -ENODEV from rand_get() as soon as device_is_ready() failed, before reaching the non-cryptographic system-timer fallback further down the same function. Because z_impl_sys_rand_get() returns void and discards that error — and the public sys_rand_get() syscall is itself declared void, so it cannot report failure — the caller's output buffer was left untouched and its previous contents were handed back as random data. The thin wrappers make this a plain uninitialized read: sys_rand32_get() declares uint32_t ret;, calls sys_rand_get(&ret, sizeof(ret)) and returns ret.
The "not ready" state is a normal runtime condition rather than a fault. Entropy drivers initialise at PRE_KERNEL_1 with CONFIG_ENTROPY_INIT_PRIORITY (default 50), so any earlier initialiser — kernel objects run at priority 30 — observes an unready device; the sibling generator subsys/random/random_xoshiro128.c and z_early_rand_get() in kernel/init.c both already carried an explicit timer fallback for exactly this case. The state is also permanent for the boot when an entropy driver's init hook fails, which several in-tree drivers can do on real hardware (entropy_stm32 on an RNG clock configuration error, entropy_psa_crypto when psa_crypto_init() fails, entropy_nrf_cracen, entropy_esp32, entropy_virtio).
When this occurs, every non-cryptographic random value in the system is either a constant or stale memory. coap_next_token() in subsys/net/lib/coap/coap.c fills a static buffer, so every CoAP token becomes the same .bss constant; tcp_init_isn() in subsys/net/ip/tcp.c returns an uninitialized stack word as the TCP initial sequence number; DHCPv4/DHCPv6 transaction IDs, WebSocket masking keys and RTP SSRCs are similarly degraded, and arch/arm64/core/pac.c derives per-thread Pointer Authentication keys from the same source. Where the bytes are transmitted directly — SSH packet padding, the netmidi2 session nonce, a DTLS connection ID on builds without CONFIG_CSPRNG_ENABLED — stale caller stack or heap contents are disclosed on the wire.
The fix initialises ret to -ENODEV and only calls entropy_get_entropy() when the device is ready, so the not-ready case now falls through to the timer fallback and the buffer is always written. The cryptographically secure path is unchanged: sys_csrand_get() still propagates the error to the caller and never silently degrades. An attacker cannot induce the unready state, but can observe and exploit the resulting non-random values remotely on an affected device.
📍 영향받는 시스템
Zephyr RTOS의 subsys/random/random_entropy_device.c를 포함하는 해당 취약 버전 (패치 이전 버전의 Zephyr 기반 임베디드 장치)
⚔️ 공격 벡터
공격자는 장치의 준비되지 않은 상태를 유발할 수 없지만, 상태가 발생한 장치에서 생성된 예측 가능한 토큰, 시퀀스 번호, 노출된 메모리 내용을 원격으로 관찰하고 악용할 수 있습니다.
🛡️ 대응 방법
Zephyr를 취약점 수정이 포함된 최신 버전으로 업데이트하여 rand_get()이 준비되지 않은 경우에도 타이머 기반 폴백을 거쳐 버퍼가 항상 기록되도록 합니다.
🔧 검증 코드
출력에서 rand_get 구현 내 ret 변수가 -ENODEV로 초기화되어 있으면 패치가 적용된 것이고, 초기화 없이 조기 return하는 코드가 보이면 취약한 버전입니다. 파일이 없으면 Zephyr 소스 트리를 직접 확인하거나 사용 중인 Zephyr 버전을 점검해야 합니다.
grep -rn "sys_rand32_get\|ret = -ENODEV" $(find / -path '*zephyr*' -name random_entropy_device.c 2>/dev/null | head -1) 2>/dev/null | head -5