🇰🇷 한글 설명
Linux kernel XFS 파일시스템에서 확장 속성(xattr)을 leaf block에 추가할 때 freemap 조정 과정의 버그로, entries array와 free space 영역이 메모리상에서 겹치는 문제. 특정 크기의 xattr(namelen=3, valuelen=71)을 추가할 때 freemap이 일관성 없게 관리되어 assertion 실패와 파일시스템 셧다운 발생.
💡 쉬운 설명
Linux 파일 저장 시스템(XFS)에서 파일 속성을 추가할 때 메모리 관리 버그로 같은 메모리 영역을 두 번 사용하려고 시도. 이로 인해 파일시스템이 안전 시스템을 작동시켜 자동 중단.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
xfs: fix freemap adjustments when adding xattrs to leaf blocks
xfs/592 and xfs/794 both trip this assertion in the leaf block freemap
adjustment code after ~20 minutes of running on my test VMs:
ASSERT(ichdr->firstused >= ichdr->count * sizeof(xfs_attr_leaf_entry_t)
+ xfs_attr3_leaf_hdr_size(leaf));
Upon enabling quite a lot more debugging code, I narrowed this down to
fsstress trying to set a local extended attribute with namelen=3 and
valuelen=71. This results in an entry size of 80 bytes.
At the start of xfs_attr3_leaf_add_work, the freemap looks like this:
i 0 base 448 size 0 rhs 448 count 46
i 1 base 388 size 132 rhs 448 count 46
i 2 base 2120 size 4 rhs 448 count 46
firstused = 520
where "rhs" is the first byte past the end of the leaf entry array.
This is inconsistent -- the entries array ends at byte 448, but
freemap[1] says there's free space starting at byte 388!
By the end of the function, the freemap is in worse shape:
i 0 base 456 size 0 rhs 456 count 47
i 1 base 388 size 52 rhs 456 count 47
i 2 base 2120 size 4 rhs 456 count 47
firstused = 440
Important note: 388 is not aligned with the entries array element size
of 8 bytes.
Based on the incorrect freemap, the name area starts at byte 440, which
is below the end of the entries array! That's why the assertion
triggers and the filesystem shuts down.
How did we end up here? First, recall from the previous patch that the
freemap array in an xattr leaf block is not intended to be a
comprehensive map of all free space in the leaf block. In other words,
it's perfectly legal to have a leaf block with:
* 376 bytes in use by the entries array
* freemap[0] has [base = 376, size = 8]
* freemap[1] has [base = 388, size = 1500]
* the space between 376 and 388 is free, but the freemap stopped
tracking that some time ago
If we add one xattr, the entries array grows to 384 bytes, and
freemap[0] becomes [base = 384, size = 0]. So far, so good. But if we
add a second xattr, the entries array grows to 392 bytes, and freemap[0]
gets pushed up to [base = 392, size = 0]. This is bad, because
freemap[1] hasn't been updated, and now the entries array and the free
space claim the same space.
The fix here is to adjust all freemap entries so that none of them
collide with the entries array. Note that this fix relies on commit
2a2b5932db6758 ("xfs: fix attr leaf header freemap.size underflow") and
the previous patch that resets zero length freemap entries to have
base = 0.
📍 영향받는 시스템
Linux kernel XFS filesystem (대부분의 enterprise Linux 배포판 포함, 버전 정보는 patch 기반 확인 필요)
⚔️ 공격 벡터
로컬 권한 있는 사용자가 특정 크기의 확장 속성을 XFS 파일시스템에 추가 시도 시 발동 (특별한 외부 접근 불필요)
🛡️ 대응 방법
Linux kernel을 XFS freemap 조정 패치가 포함된 최신 버전으로 업데이트
🔧 검증 코드
'XFS 사용중'이면 영향 받을 수 있으며, uname -r로 커널 버전 확인 후 최신 LTS 버전으로 업데이트 권장
mount | grep -q xfs && echo 'XFS 사용중' || echo 'XFS 미사용'