🇰🇷 한글 설명
Zephyr Bluetooth Mesh의 액세스 계층 지연 메시지 큐(delayable_msg.c)에서 두 협력 스레드가 동기화 없이 리스트와 작업 항목을 공유하여 경쟁 상태가 발생합니다. 이로 인해 NULL 기반 포인터 쓰기가 발생해 시스템 워크큐 스레드가 중단되거나 노드가 재설정될 수 있으며, 메시지 중복 전송도 일어날 수 있습니다.
💡 쉬운 설명
메시 네트워크의 기기가 여러 메시지를 동시에 처리하면서 내부 대기열이 꼬여 기기가 멈추거나 재부팅될 수 있습니다. 네트워크 키를 가진 구성원이 이를 유발할 수 있습니다.
🇺🇸 원문 (English)
The Bluetooth Mesh Access-layer delayable message queue in subsys/bluetooth/mesh/delayable_msg.c shares three intrusive lists (busy_ctx, free_ctx, free_chunks) and one k_work_delayable between two cooperative threads with no synchronization: bt_mesh_delayable_msg_manage() runs on the Bluetooth host RX thread, while delayable_msg_handler() runs on the system workqueue. Both block while the lists are in an intermediate state — the enqueuer in bt_rand(), both in bt_mesh_access_send() — which lets the other context observe torn state. delayable_msg_handler() used the result of sys_slist_get() on busy_ctx without a NULL check, and allocate_delayable_msg_ctx() tested sys_slist_is_empty() and then assumed a separate sys_slist_get() would succeed.
Because CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG and CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CTX_ENABLED default to y, every model response to a received mesh message is parked on this queue, so the enqueuer runs as a direct consequence of inbound traffic. A peer that can get access-layer messages accepted by a model (it must hold the NetKey and a bound AppKey, so a legitimate or compromised network member) controls the arrival rate, the size of the elicited responses and the destination address, and thereby controls occupancy of the 4-entry context pool and the 40-entry chunk pool. Exhausting the chunk pool forces bt_mesh_delayable_msg_manage() down the purge path, which sends and releases the only queued message and leaves busy_ctx empty while the delayable work item is still armed; if the enqueuer then yields, the handler runs against the empty list.
The result is a read-modify-write through a NULL-based pointer (pending_msg->fired_time += 10) at a fixed low address on the system workqueue thread. On typical targets that faults, aborting the system workqueue thread — which stops all workqueue-driven functionality, including the mesh timing machinery — or resetting the node, so the impact is loss of availability of the affected node. The write value and address are fixed and no attacker-controlled length or index is involved, so this is not exploitable for memory corruption or code execution. The same unsynchronized window also allowed one message context to be selected and released by two contexts at once, producing duplicated transmissions, duplicated send-completion callbacks and crossed chunk ownership.
The fix serializes every list mutation with a k_spinlock that is never held across a blocking call, makes push_msg_from_delayable_msgs() detach the queue head atomically so a message being sent is on no list, removes the unchecked sys_slist_get() from delayable_msg_handler(), and drops any message that reaches the front of the queue while the stack is suspended or reset.
📍 영향받는 시스템
Zephyr RTOS의 Bluetooth Mesh 구현(CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG 활성화 빌드), 수정 이전 버전
⚔️ 공격 벡터
NetKey와 바인딩된 AppKey를 보유한 네트워크 구성원이 액세스 메시지 전송률과 응답 크기를 조절해 컨텍스트/청크 풀을 고갈시키고 경쟁 상태를 유발
🛡️ 대응 방법
Zephyr 패치 적용: 리스트 변경을 k_spinlock으로 직렬화하고, 큐 헤드를 원자적으로 분리하며, delayable_msg_handler()의 확인 없는 sys_slist_get() 제거
🔧 검증 코드
출력에 k_spinlock 사용 구문이 존재하면 패치가 적용된 것이고, 아무 결과도 없으면 패치가 적용되지 않은 취약한 상태일 가능성이 높습니다.
grep -rn "k_spinlock" $(find / -path '*/subsys/bluetooth/mesh/delayable_msg.c' 2>/dev/null | head -1) 2>/dev/null | head -5