🇰🇷 한글 설명
Linux 커널의 Btrfs 파일 시스템에서 스냅샷 생성 실패 시 발생하는 Use-After-Free 취약점입니다. 스냅샷 생성 중 오류가 발생하여 구조체가 해제되었음에도 불구하고, 해당 구조체가 트랜잭션 목록에 남아 있어 이후 다른 작업이 해제된 메모리에 접근할 수 있습니다.
💡 쉬운 설명
파일 시스템의 스냅샷을 만드는 도중 오류가 나면, 컴퓨터가 이미 사용이 끝났다고 판단해 버린 메모리 주소를 나중에 다시 사용하려고 시도하는 문제입니다. 이 과정에서 시스템이 충돌하거나 보안 문제가 생길 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
btrfs: fix use-after-free after failure to create a snapshot
At ioctl.c:create_snapshot(), we allocate a pending snapshot structure and
then attach it to the transaction's list of pending snapshots. After that
we call btrfs_commit_transaction(), and if that returns an error we jump
to 'fail' label, where we kfree() the pending snapshot structure. This can
result in a later use-after-free of the pending snapshot:
1) We allocated the pending snapshot and added it to the transaction's
list of pending snapshots;
2) We call btrfs_commit_transaction(), and it fails either at the first
call to btrfs_run_delayed_refs() or btrfs_start_dirty_block_groups().
In both cases, we don't abort the transaction and we release our
transaction handle. We jump to the 'fail' label and free the pending
snapshot structure. We return with the pending snapshot still in the
transaction's list;
3) Another task commits the transaction. This time there's no error at
all, and then during the transaction commit it accesses a pointer
to the pending snapshot structure that the snapshot creation task
has already freed, resulting in a user-after-free.
This issue could actually be detected by smatch, which produced the
following warning:
fs/btrfs/ioctl.c:843 create_snapshot() warn: '&pending_snapshot->list' not removed from list
So fix this by not having the snapshot creation ioctl directly add the
pending snapshot to the transaction's list. Instead add the pending
snapshot to the transaction handle, and then at btrfs_commit_transaction()
we add the snapshot to the list only when we can guarantee that any error
returned after that point will result in a transaction abort, in which
case the ioctl code can safely free the pending snapshot and no one can
access it anymore.
📍 영향받는 시스템
Btrfs 파일 시스템을 사용하는 Linux 커널 버전
⚔️ 공격 벡터
로컬 사용자가 특수하게 조작된 ioctl 호출을 통해 스냅샷 생성 과정에서 오류를 유도하여 메모리 오류 발생
🛡️ 대응 방법
Btrfs 스냅샷 생성 로직이 수정된 최신 Linux 커널로 업데이트
🔧 검증 코드
출력된 커널 버전이 취약점이 패치된 최신 버전인지 확인