🇰🇷 한글 설명
Linux 커널의 ntfs3 파일 시스템에서 디렉토리 생성(mkdir)과 마운트 작업이 동시에 발생할 때 발생하는 레이스 컨디션 취약점입니다. ntfs_create_inode() 과정에서 잘못된 함수 호출로 인해 rwsem(읽기-쓰기 세마포어)의 상태가 초기화되어 잠금 메커니즘이 손상됩니다. 이로 인해 잠금 해제 시 언더플로우가 발생하거나 이후의 inode 잠금 시도가 무한 대기에 빠질 수 있습니다.
💡 쉬운 설명
파일을 만드는 작업과 새로운 저장 장치를 연결하는 작업이 동시에 일어날 때, 시스템의 '잠금 장치'가 고장 나는 문제입니다. 이로 인해 컴퓨터가 멈추거나 시스템이 응답하지 않는 상태가 될 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
fs/ntfs3: use d_instantiate_new() in ntfs_create_inode() and murder syzbot's "WARNING in do_new_mount" saga
ntfs_create_inode() creates a new inode via ntfs_new_inode(). It hashes
it with insert_inode_locked() and so it's marked as I_NEW until
unlock_new_inode().
ntfs 3 calls d_instantiate() in between though... Since the dentry was
already hashed by the lookup before the create any path walk finds it
without touching the parent's i_rwsem and so can lock the inode.
If the inode is a directory unlock_new_inode() calls
lockdep_annotate_inode_mutex_key() and marks i_rwsem with the
i_mutex_dir_key class.
That resets the count and the owner of a lock somebody else may already
hold by now...
syzbot has been spamming us with the same godforsaken bug
"WARNING in do_new_mount"
since 2023. I can't take it anymore so I went looking. Afaict, syzbot's
executor chdirs into a freshly mounted ntfs3 image, creates a
directory and then mounts some pseudofs on it. Everytime the mkdir()
takes longer than syzbot waits mount() runs concurrently:
mkdir("./sys") mount(NULL, "./sys", "sysfs")
ntfs_create_inode()
d_instantiate()
user_path_at() finds the dentry
do_lock_mount()
inode_lock(inode)
namespace_lock()
unlock_new_inode()
lockdep_annotate_inode_mutex_key()
init_rwsem(&inode->i_rwsem)
unlock_mount()
inode_unlock(inode)
The mount side then releases a lock that according to the rwsem nobody
holds:
DEBUG_RWSEMS_WARN_ON((rwsem_owner(sem) != current) && ...):
count = 0x0, magic = 0xffff888043a854e8, owner = 0x0,
curr 0xffff888000244880, list empty
WARNING: CPU: 0 PID: 5346 at kernel/locking/rwsem.c:1368 __up_write
Call Trace:
inode_unlock include/linux/fs.h:877 [inline]
unlock_mount fs/namespace.c:2892 [inline]
do_new_mount_fc fs/namespace.c:3828 [inline]
do_new_mount+0x777/0xa40 fs/namespace.c:3887
On PREEMPT_RT the same thing shows up as
DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current)
WARNING: kernel/locking/rtmutex_common.h:193 at rt_mutex_slowunlock
The up_write() underflows the reset count. A following inode_lock() on
that directory then never returns. A path walk into the new directory
racing with the mkdir() corrupts the lock the same way via
inode_lock_shared() in lookup_slow().
Switch to d_instantiate_new() and drop the trailing unlock_new_inode().
All error paths bail out before that point with I_NEW still set and
keep using discard_new_inode().
May we never see this fscking bug report again.
📍 영향받는 시스템
Linux Kernel (ntfs3 파일 시스템을 사용하는 버전)
⚔️ 공격 벡터
로컬 사용자가 ntfs3 파일 시스템 내에서 디렉토리 생성과 마운트 작업을 정밀하게 타이밍을 맞춰 동시에 수행하여 유도
🛡️ 대응 방법
ntfs_create_inode()에서 d_instantiate() 대신 d_instantiate_new()를 사용하도록 커널 패치 적용
🔧 검증 코드
출력된 커널 버전을 확인하여 해당 취약점이 수정된 최신 보안 패치 버전인지 확인하십시오.