🇰🇷 한글 설명
Linux 커널의 nvmet 구성 요소에서 configfs를 통한 max_qid 수정과 컨트롤러 할당 과정 사이에 레이스 컨디션(경쟁 상태)이 발생합니다. 이로 인해 할당된 메모리 크기보다 더 큰 큐를 사용하려 시도하게 되어 KASAN out-of-bounds 경고 및 메모리 손상이 발생할 수 있습니다.
💡 쉬운 설명
시스템 설정값이 바뀌는 순간에 새로운 장치가 만들어지면, 메모리 공간을 실제 필요한 것보다 작게 준비하는 문제가 생깁니다. 이로 인해 데이터가 정해진 범위를 벗어나 저장되어 시스템 오류나 보안 문제가 발생할 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
nvmet: fix max_qid race between configfs and controller allocation
The function nvmet_subsys_attr_qid_max_store() can race against
nvmet_alloc_ctrl() when a subsystem's max_qid limit is modified.
Suppose max_qid is currently 64. If nvmet_alloc_ctrl() executes:
ctrl->sqs = kzalloc_objs(struct nvmet_sq *, subsys->max_qid + 1);
and at this exact point, a userspace process changes max_qid to 128,
nvmet_subsys_attr_qid_max_store() will set the new max_qid value. It
attempts to delete active controllers to force a reconnect, but the
new controller won't be deleted because it hasn't been added to the
subsys->ctrls list yet.
nvmet_alloc_ctrl() then proceeds and adds the new controller to the
subsys->ctrls list. Later, when nvmet_install_queue() is called, it
will see max_qid set to 128, but the memory allocated for sqs is only
sized for 64 entries. This results in a KASAN out-of-bounds warning
and potential memory corruptions.
Fix this by protecting the queue allocations and list insertion in
nvmet_alloc_ctrl() with down_read(&nvmet_config_sem). Because
nvmet_subsys_attr_qid_max_store() acquires down_write(&nvmet_config_sem)
to modify the attribute, this safely prevents the configfs writer from
modifying max_qid during controller creation.
Copy the max_qid from the subsystem to the controller's structure
during the allocation; ctrl->max_qid never changes as long as the
controller remains in LIVE state, so this will prevent similar race
conditions.
📍 영향받는 시스템
Linux Kernel (nvmet subsystem 관련 버전)
⚔️ 공격 벡터
사용자 공간(userspace)에서 configfs를 통해 max_qid 값을 조작하여 레이스 컨디션 유도
🛡️ 대응 방법
커널 패치를 통해 nvmet_alloc_ctrl() 함수 내에 세마포어(nvmet_config_sem) 보호 로직을 적용하여 동기화 수행
🔧 검증 코드
출력된 커널 버전이 해당 취약점이 해결된 패치 버전인지 배포판 보안 공지를 통해 확인