🇰🇷 한글 설명
Linux 커널의 Btrfs 파일 시스템에서 delayed ref head를 추가하는 과정 중 오류가 발생할 경우 qgroup 레코드가 중복 해제(double free)되는 취약점이 발견되었습니다. 이 문제는 함수 호출 시 객체의 소유권 관리 책임이 호출자와 피호출자 모두에게 있어 발생했으며, 소유권 구조를 변경하여 해결되었습니다.
💡 쉬운 설명
컴퓨터 메모리를 관리할 때 이미 삭제한 메모리를 또 삭제하려고 시도하여 시스템 오류를 일으키는 버그입니다. 이로 인해 시스템이 멈추거나 보안 공격에 악용될 수 있는 위험이 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
btrfs: fix double free of qgroup record after failure to add delayed ref head
In the previous code it was possible to incur into a double kfree()
scenario when calling add_delayed_ref_head(). This could happen if the
record was reported to already exist in the
btrfs_qgroup_trace_extent_nolock() call, but then there was an error
later on add_delayed_ref_head(). In this case, since
add_delayed_ref_head() returned an error, the caller went to free the
record. Since add_delayed_ref_head() couldn't set this kfree'd pointer
to NULL, then kfree() would have acted on a non-NULL 'record' object
which was pointing to memory already freed by the callee.
The problem comes from the fact that the responsibility to kfree the
object is on both the caller and the callee at the same time. Hence, the
fix for this is to shift the ownership of the 'qrecord' object out of
the add_delayed_ref_head(). That is, we will never attempt to kfree()
the given object inside of this function, and will expect the caller to
act on the 'qrecord' object on its own. The only exception where the
'qrecord' object cannot be kfree'd is if it was inserted into the
tracing logic, for which we already have the 'qrecord_inserted_ret'
boolean to account for this. Hence, the caller has to kfree the object
only if add_delayed_ref_head() reports not to have inserted it on the
tracing logic.
As a side-effect of the above, we must guarantee that
'qrecord_inserted_ret' is properly initialized at the start of the
function, not at the end, and then set when an actual insert
happens. This way we avoid 'qrecord_inserted_ret' having an invalid
value on an early exit.
The documentation from the add_delayed_ref_head() has also been updated
to reflect on the exact ownership of the 'qrecord' object.
📍 영향받는 시스템
Btrfs 파일 시스템을 사용하는 Linux 커널 버전
⚔️ 공격 벡터
Btrfs 파일 시스템의 qgroup 관련 작업 중 특정 오류 상황을 유도하여 메모리 오류 발생
🛡️ 대응 방법
Btrfs qgroup 레코드 소유권 로직이 수정된 최신 Linux 커널로 업데이트
🔧 검증 코드
출력된 커널 버전이 해당 취약점이 패치된 최신 보안 업데이트 버전인지 확인