🇰🇷 한글 설명
Linux 커널 SCSI target 서브시스템의 delayed_cmd_lock 획득 시 인터럽트를 비활성화하지 않아 발생하는 잠금 문제입니다. 직접 완료(direct completion) 경로에서 인터럽트 컨텍스트와 충돌하여 CPU가 잠금을 무한히 대기하는 교착 상태가 발생할 수 있습니다. 해당 조건은 complete_type=1 설정과 ORDERED 작업 속성 사용 시에만 성립합니다.
💡 쉬운 설명
서버의 저장장치 제어 기능에서 두 작업이 같은 자물쇠를 서로 다른 방식으로 잠그면서 충돌이 생길 수 있습니다. 특정 설정에서만 발생하며, 충돌이 생기면 해당 CPU가 멈춘 상태로 대기하게 됩니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
scsi: target: Disable interrupts while holding delayed_cmd_lock
target_do_delayed_work() takes dev->delayed_cmd_lock with a plain
spin_lock(). It runs from system_percpu_wq, so interrupts stay enabled
while the lock is held. Every other acquisition of that lock uses
spin_lock_irqsave(): target_handle_task_attr() and
transport_complete_ordered_sync() in target_core_transport.c, and
target_non_ordered_release() in target_core_device.c.
That was safe while every caller of transport_complete_task_attr() ran
in process context: target_complete_ok_work() from target_completion_wq,
transport_complete_qf() from dev->qf_work_queue, and
transport_generic_request_failure() from the submit and execute paths.
Since commit 06933066d88a ("scsi: target: Add support for completing
commands from backend context") that is no longer true. With
complete_type=1 on a fabric that sets direct_compl_supp,
target_complete() runs target_complete_ok_work() inline in the backend's
completion context, which target_complete_cmd_with_sense() documents as
"May be called from interrupt context". For iblock that is the bio
end_io.
target_complete_ok_work() starts with transport_complete_task_attr(),
which takes delayed_cmd_lock in two ways:
- Every ORDERED command is put on dev->delayed_cmd_list by
target_handle_task_attr() and dispatched from there by
target_do_delayed_work(), which marks it SCF_TASK_ORDERED_SYNC. Its
completion therefore goes through transport_complete_ordered_sync().
- A SIMPLE command that completes while an ORDERED command is pending
drops the last reference to the killed dev->non_ordered, and
percpu_ref_put() then runs target_non_ordered_release() in the
completing context.
Both take the lock and, if commands are waiting, call
schedule_work(&dev->delayed_cmd_work), which queues on system_percpu_wq,
i.e. on the CPU that took the completion. Further completions for the
same queue are typically delivered there too, so one arriving while the
work holds the lock spins on it forever.
Reaching this needs complete_type=1, which is not the default
(vhost-scsi, the only fabric with direct_compl_supp, defaults to
TARGET_QUEUE_COMPL), a backend whose I/O completes from interrupt
context, and ORDERED commands from the initiator. Linux virtio_scsi
guests send only VIRTIO_SCSI_S_SIMPLE and never take the ordered path;
any guest that uses the ORDERED task attribute, which vhost-scsi
accepts, does.
target_do_delayed_work() is a work item and always runs in process
context, so spin_lock_irq() is sufficient.
Found by inspection; no runtime report. A single ORDERED command goes
through both acquisitions, so with CONFIG_PROVE_LOCKING the first one
completed through direct completion should produce an inconsistent lock
state report on delayed_cmd_lock (hardirq or softirq, depending on where
the backend completes).
📍 영향받는 시스템
Linux 커널 SCSI target 서브시스템을 사용하는 vhost-scsi 등 환경 (수정 커밋 이전 커널 버전, 정확한 범위는 배포판 패치 정보 확인 필요)
⚔️ 공격 벡터
특정 설정(complete_type=1)과 ORDERED 작업 속성을 사용하는 게스트가 I/O를 반복 요청하여 교착 상태를 유도할 수 있으며, 직접적인 원격 코드 실행이나 권한 상승 증거는 없음
🛡️ 대응 방법
배포판에서 제공하는 해당 커널 보안/버그 수정 업데이트를 적용하고, 불필요한 complete_type=1 설정을 피하십시오.
🔧 검증 코드
출력된 커널 버전을 배포판 보안 공지의 패치 버전과 비교하여 수정이 포함되었는지 확인하고, grep 결과가 나오면 해당 모듈이 존재하는 시스템이므로 패치 적용 여부를 우선 점검하십시오.
uname -r && grep -rl 'delayed_cmd_lock' /lib/modules/$(uname -r) 2>/dev/null | head -n 1