🇰🇷 한글 설명
Linux 커널의 mm/gup 코드에서 FOLL_FORCE와 COW(Copy-on-Write) 메커니즘 간의 보안 취약점이 발견되었습니다. 공격자는 이를 악용하여 tmpfs/shmem 파일의 쓰기 권한이 없더라도 내용을 수정하거나 memfd 쓰기 봉인을 우회할 수 있습니다.
💡 쉬운 설명
컴퓨터의 메모리 관리 방식의 허점을 이용해, 읽기 전용으로 설정된 파일을 강제로 수정할 수 있는 보안 결함입니다. 이를 통해 권한이 없는 사용자가 시스템의 중요한 데이터를 몰래 바꿀 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
mm/gup: fix FOLL_FORCE COW security issue and remove FOLL_COW
Ever since the Dirty COW (CVE-2016-5195) security issue happened, we know
that FOLL_FORCE can be possibly dangerous, especially if there are races
that can be exploited by user space.
Right now, it would be sufficient to have some code that sets a PTE of a
R/O-mapped shared page dirty, in order for it to erroneously become
writable by FOLL_FORCE. The implications of setting a write-protected PTE
dirty might not be immediately obvious to everyone.
And in fact ever since commit 9ae0f87d009c ("mm/shmem: unconditionally set
pte dirty in mfill_atomic_install_pte"), we can use UFFDIO_CONTINUE to map
a shmem page R/O while marking the pte dirty. This can be used by
unprivileged user space to modify tmpfs/shmem file content even if the
user does not have write permissions to the file, and to bypass memfd
write sealing -- Dirty COW restricted to tmpfs/shmem (CVE-2022-2590).
To fix such security issues for good, the insight is that we really only
need that fancy retry logic (FOLL_COW) for COW mappings that are not
writable (!VM_WRITE). And in a COW mapping, we really only broke COW if
we have an exclusive anonymous page mapped. If we have something else
mapped, or the mapped anonymous page might be shared (!PageAnonExclusive),
we have to trigger a write fault to break COW. If we don't find an
exclusive anonymous page when we retry, we have to trigger COW breaking
once again because something intervened.
Let's move away from this mandatory-retry + dirty handling and rely on our
PageAnonExclusive() flag for making a similar decision, to use the same
COW logic as in other kernel parts here as well. In case we stumble over
a PTE in a COW mapping that does not map an exclusive anonymous page, COW
was not properly broken and we have to trigger a fake write-fault to break
COW.
Just like we do in can_change_pte_writable() added via commit 64fe24a3e05e
("mm/mprotect: try avoiding write faults for exclusive anonymous pages
when changing protection") and commit 76aefad628aa ("mm/mprotect: fix
soft-dirty check in can_change_pte_writable()"), take care of softdirty
and uffd-wp manually.
For example, a write() via /proc/self/mem to a uffd-wp-protected range has
to fail instead of silently granting write access and bypassing the
userspace fault handler. Note that FOLL_FORCE is not only used for debug
access, but also triggered by applications without debug intentions, for
example, when pinning pages via RDMA.
This fixes CVE-2022-2590. Note that only x86_64 and aarch64 are
affected, because only those support CONFIG_HAVE_ARCH_USERFAULTFD_MINOR.
Fortunately, FOLL_COW is no longer required to handle FOLL_FORCE. So
let's just get rid of it.
Thanks to Nadav Amit for pointing out that the pte_dirty() check in
FOLL_FORCE code is problematic and might be exploitable.
Note 1: We don't check for the PTE being dirty because it doesn't matter
for making a "was COWed" decision anymore, and whoever modifies the
page has to set the page dirty either way.
Note 2: Kernels before extended uffd-wp support and before
PageAnonExclusive (< 5.19) can simply revert the problematic
commit instead and be safe regarding UFFDIO_CONTINUE. A backport to
v5.19 requires minor adjustments due to lack of
vma_soft_dirty_enabled().
📍 영향받는 시스템
x86_64 및 aarch64 아키텍처를 사용하는 Linux 커널 (PageAnonExclusive 미지원 버전 포함)
⚔️ 공격 벡터
UFFDIO_CONTINUE를 사용하여 읽기 전용으로 매핑된 shmem 페이지의 PTE를 dirty로 설정한 후 FOLL_FORCE를 통해 쓰기 권한을 획득
🛡️ 대응 방법
Linux 커널을 최신 보안 패치가 적용된 버전(v5.19 이상 권장 또는 해당 취약점이 수정된 백포트 버전)으로 업데이트
🔧 검증 코드
출력된 커널 버전을 확인하여 취약점이 해결된 최신 패치 버전인지 확인합니다.