🇰🇷 한글 설명
Linux 커널의 kernfs에서 LSM(Linux Security Module) 초기화 훅이 호출되기 전에 노드의 부모 링크가 설정되지 않아 발생하는 NULL 포인터 역참조 취약점입니다. SELinux가 활성화된 환경에서 새로운 cgroup 디렉토리를 생성할 때 커널 패닉이 발생할 수 있습니다.
💡 쉬운 설명
새로운 폴더를 만들 때 보안 설정을 먼저 확인하는데, 이때 폴더의 부모 정보가 아직 등록되지 않아 컴퓨터가 길을 잃고 멈춰버리는 문제입니다. 이로 인해 시스템이 갑자기 꺼지거나 재부팅될 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
kernfs: link kn to its parent before the LSM init hook
After commit 12e9e3cd03b5 ("simpe_xattr: use per-sb cache"),
kernfs_xattr_set() and kernfs_xattr_get() compute the cache via
kernfs_root(kn) before any other check. kernfs_root(kn) walks
kn->__parent first and falls back to kn->dir.root, both of which are
NULL on a freshly kmem_cache_zalloc()'d kn. kn->__parent was being set
in kernfs_new_node() after __kernfs_new_node() returned, and kn->dir.root
is set even later by kernfs_create_dir_ns() / kernfs_create_empty_dir().
The LSM kernfs_init_security hook is invoked from inside
__kernfs_new_node(), before either field has been initialized.
selinux_kernfs_init_security() ends with kernfs_xattr_set(kn,
XATTR_NAME_SELINUX, ...). kernfs_root(kn) then returns NULL, and
&((struct kernfs_root *)NULL)->xa_cache evaluates to
offsetof(struct kernfs_root, xa_cache) which faults:
BUG: kernel NULL pointer dereference, address: 00000000000000e0
RIP: 0010:simple_xattr_set+0x27/0x8b0
Call Trace:
kernfs_xattr_set+0x63/0xb0
selinux_kernfs_init_security+0x13b/0x270
security_kernfs_init_security+0x36/0xc0
__kernfs_new_node+0x182/0x290
kernfs_new_node+0x80/0xc0
kernfs_create_dir_ns+0x2b/0xa0
cgroup_create+0x116/0x380
cgroup_mkdir+0x7c/0x1a0
Reproduces deterministically at PID 1 (systemd) on an SELinux-enabled
distro. The first cgroup mkdir under /sys/fs/cgroup with a labelled
parent panics the kernel.
The LSM hook's contract is that the kn_dir argument is the parent of
the new kn, so kn->__parent should already point at kn_dir when the
hook runs. Move kernfs_get(parent) and rcu_assign_pointer of
kn->__parent from kernfs_new_node() into __kernfs_new_node() right
before the security hook, and unwind the parent reference on the
err_out4 path. kernfs_root(kn) then takes its parent branch during
the hook and returns parent->dir.root, which is the correct root.
This also closes the same-shape latent bug in kernfs_xattr_get() (which
today is hidden only by kernfs_iattrs_noalloc() returning NULL on a
fresh kn).
📍 영향받는 시스템
LSM(SELinux 등)이 활성화된 Linux 커널 (특정 커밋 12e9e3cd03b6 이후 버전 포함)
⚔️ 공격 벡터
로컬 사용자가 cgroup 디렉토리를 생성하여 커널 패닉을 유도하는 방식 (DoS)
🛡️ 대응 방법
해당 취약점이 수정된 최신 Linux 커널 버전으로 업데이트하십시오.
🔧 검증 코드
출력된 커널 버전이 해당 취약점이 패치된 버전인지 배포판 보안 공지를 통해 확인하십시오.