🇰🇷 한글 설명
Linux 커널의 thermal core에서 thermal zone 제거 시 발생하는 레이스 컨디션 취약점입니다. thermal_zone_pm_complete()와 thermal_zone_device_resume()가 poll_queue 지연 작업을 재초기화하면서, thermal_zone_device_unregister()의 작업 취소 과정에서 실행 중인 항목을 놓쳐 Use-After-Free(UAF)가 발생할 수 있습니다.
💡 쉬운 설명
컴퓨터의 열을 관리하는 기능이 꺼지는 과정에서 작업 순서가 꼬여 발생하는 문제입니다. 이로 인해 이미 삭제된 메모리 영역에 접근하려고 시도하여 시스템 오류나 보안 문제가 생길 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
thermal: core: Address thermal zone removal races with resume
Since thermal_zone_pm_complete() and thermal_zone_device_resume()
re-initialize the poll_queue delayed work for the given thermal zone,
the cancel_delayed_work_sync() in thermal_zone_device_unregister()
may miss some already running work items and the thermal zone may
be freed prematurely [1].
There are two failing scenarios that both start with
running thermal_pm_notify_complete() right before invoking
thermal_zone_device_unregister() for one of the thermal zones.
In the first scenario, there is a work item already running for
the given thermal zone when thermal_pm_notify_complete() calls
thermal_zone_pm_complete() for that thermal zone and it continues to
run when thermal_zone_device_unregister() starts. Since the poll_queue
delayed work has been re-initialized by thermal_pm_notify_complete(), the
running work item will be missed by the cancel_delayed_work_sync() in
thermal_zone_device_unregister() and if it continues to run past the
freeing of the thermal zone object, a use-after-free will occur.
In the second scenario, thermal_zone_device_resume() queued up by
thermal_pm_notify_complete() runs right after the thermal_zone_exit()
called by thermal_zone_device_unregister() has returned. The poll_queue
delayed work is re-initialized by it before cancel_delayed_work_sync() is
called by thermal_zone_device_unregister(), so it may continue to run
after the freeing of the thermal zone object, which also leads to a
use-after-free.
Address the first failing scenario by ensuring that no thermal work
items will be running when thermal_pm_notify_complete() is called.
For this purpose, first move the cancel_delayed_work() call from
thermal_zone_pm_complete() to thermal_zone_pm_prepare() to prevent
new work from entering the workqueue going forward. Next, switch
over to using a dedicated workqueue for thermal events and update
the code in thermal_pm_notify() to flush that workqueue after
thermal_pm_notify_prepare() has returned which will take care of
all leftover thermal work already on the workqueue (that leftover
work would do nothing useful anyway because all of the thermal zones
have been flagged as suspended).
The second failing scenario is addressed by adding a tz->state check
to thermal_zone_device_resume() to prevent it from re-initializing
the poll_queue delayed work if the thermal zone is going away.
Note that the above changes will also facilitate relocating the suspend
and resume of thermal zones closer to the suspend and resume of devices,
respectively.
📍 영향받는 시스템
Linux Kernel (thermal core 관련 모듈 사용 시스템)
⚔️ 공격 벡터
특정 시점에 thermal zone의 suspend/resume 및 unregister 동작을 유도하여 메모리 오류 유발
🛡️ 대응 방법
Linux 커널을 최신 보안 패치가 적용된 버전으로 업데이트하여 thermal workqueue 관리 로직 적용
🔧 검증 코드
커널 버전과 thermal 관련 설정 활성화 여부를 확인하여 패치 적용 가능 여부를 판단합니다.
uname -a && grep -i 'thermal' /proc/config.gz 2>/dev/null || zgrep -i 'CONFIG_THERMAL' /proc/config*