🇰🇷 한글 설명
Linux 커널의 CXL 포트 계층 구조에서 cxl_detach_ep() 함수 호출 시 parent_port를 해제된 후 사용하는 Use-After-Free 취약점이 발견되었습니다. 이는 자식 포트와 부모 포트 간의 생명주기 보장이 이루어지지 않아 발생하며, 동시적인 장치 제거 과정에서 메모리 오염을 유발할 수 있습니다.
💡 쉬운 설명
컴퓨터 부품을 제거하는 과정에서 이미 사라진 부품의 정보를 다시 건드리려다 발생하는 오류입니다. 이로 인해 시스템이 불안정해지거나 예상치 못한 메모리 오류가 발생할 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
cxl/port: Fix use after free of parent_port in cxl_detach_ep()
cxl_detach_ep() is called during bottom-up removal when all CXL memory
devices beneath a switch port have been removed. For each port in the
hierarchy it locks both the port and its parent, removes the endpoint,
and if the port is now empty, marks it dead and unregisters the port
by calling delete_switch_port(). There are two places during this work
where the parent_port may be used after freeing:
First, a concurrent detach may have already processed a port by the
time a second worker finds it via bus_find_device(). Without pinning
parent_port, it may already be freed when we discover port->dead and
attempt to unlock the parent_port. In a production kernel that's a
silent memory corruption, with lock debug, it looks like this:
[]DEBUG_LOCKS_WARN_ON(__owner_task(owner) != get_current())
[]WARNING: kernel/locking/mutex.c:949 at __mutex_unlock_slowpath+0x1ee/0x310
[]Call Trace:
[]mutex_unlock+0xd/0x20
[]cxl_detach_ep+0x180/0x400 [cxl_core]
[]devm_action_release+0x10/0x20
[]devres_release_all+0xa8/0xe0
[]device_unbind_cleanup+0xd/0xa0
[]really_probe+0x1a6/0x3e0
Second, delete_switch_port() releases three devm actions registered
against parent_port. The last of those is unregister_port() and it
calls device_unregister() on the child port, which can cascade. If
parent_port is now also empty the device core may unregister and free
it too. So by the time delete_switch_port() returns, parent_port may
be free, and the subsequent device_unlock(&parent_port->dev) operates
on freed memory. The kernel log looks same as above, with a different
offset in cxl_detach_ep().
Both of these issues stem from the absence of a lifetime guarantee
between a child port and its parent port.
Establish a lifetime rule for ports: child ports hold a reference to
their parent device until release. Take the reference when the port
is allocated and drop it when released. This ensures the parent is
valid for the full lifetime of the child and eliminates the use after
free window in cxl_detach_ep().
This is easily reproduced with a reload of cxl_acpi in QEMU with CXL
devices present.
📍 영향받는 시스템
CXL(Compute Express Link) 기능을 사용하는 Linux 커널 시스템
⚔️ 공격 벡터
CXL 장치의 동시 제거 또는 재설정 과정을 유도하여 메모리 오염 유발
🛡️ 대응 방법
자식 포트가 부모 포트의 참조 카운트를 유지하도록 커널 패치를 적용하여 생명주기 관리 규칙을 확립해야 합니다.
🔧 검증 코드
현재 실행 중인 커널 버전을 확인하여 해당 취약점이 수정된 최신 패치 버전인지 확인합니다.