In the Linux kernel, the following vulnerability has been resolved:
x86/mm/pat: Allocate split page tables as kernel page tables
A PTE is allocated directly without going through the standard page table
allocation routines (such as pte_alloc_one_kernel()) when the CPA code
splits a large page (__split_large_page()).
This means the page table constructor is never called nor is the page table
marked as a kernel page table.
The former results in the folio associated with the page table not being
marked as a page table (__pagetable_ctor() is never called thus neither is
__folio_set_pgtable()) nor are statistics updated to reflect
it (lruvec_stat_add_folio() is never called).
The latter issue of failing to mark the page table as a kernel page
table (ptdesc_set_kernel() is never called) is far more problematic.
Since commit:
5ba2f0a15564 ("mm: introduce deferred freeing for kernel page tables")
kernel page table freeing has been batched and since the
subsequent commit:
e37d5a2d60a3 ("iommu/sva: invalidate stale IOTLB entries for kernel address space")
IOTLB cache entries for kernel page tables have been invalidated upon
being freed.
Since split page tables are freed without this invalidation, the IOTLB
can contain stale entries for them.
Resolve the issue by using the ordinary PTE allocation API at split time.
This results in these kernel page tables invoking a page table constructor,
and thus requires a page table destructor.
Destructors are not always present, like for early allocated direct map
page tables). Conditionally call pagetable_dtor_free() if the PG_table
folio flag for the ptdesc is set, otherwise we free the page table via
pagetable_free().
Regardless of which path is taken page tables marked as kernel page tables,
which now includes split page tables, take the correct route through
pagetable_free_kernel().
There is a user-visible side effect in that split page tables will appear
in nr_page_table_pages in /proc/vmstat (as do other kernel page tables
allocated after early boot), however this is a positive change.
This issue started being markedly problematic after commit:
5ba2f0a15564 ("mm: introduce deferred freeing for kernel page tables")
so choose this as the Fixes target.
[ dhansen: rephrase in imperative mood ]
CVSS Vector: CVSS:3.1/AV:L/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H
CVSS Score: 8.2
AV:L - split_large_page() is reached from local set_memory_* via change_page_attr_set_clr()→__change_page_attr(); the path that allocates unmarked tables and later frees them is finit_module→module_memory_alloc()→execmem_alloc_rw()→execmem_force_rw()/set_memory_nx (split) then module_enable_text_rox()→set_memory_rox() (collapse). No remote protocol carries the input.
AC:L - On an x86 IOMMU_SVA host, a module whose text is carved from the execmem ROX 2M cache makes execmem_force_rw() split that PMD (pagetable_alloc without ptdesc_set_kernel) and set_memory_rox(CPA_COLLAPSE) free it in cpa_collapse_large_pages(); the same caller binds SVA, primes IOTLB walks, and sprays reuse without an uncontrolled race.
PR:H - may_init_module() requires capable(CAP_SYS_MODULE) in init_user_ns, which user namespaces cannot grant. Only EXECMEM_MODULE_TEXT with EXECMEM_ROX_CACHE both splits a huge mapping in split_large_page() and collapse-frees it; EXECMEM_BPF lacks ROX_CACHE so unprivileged bpf_jit_alloc_exec()/set_memory_rox does not produce these unmarked tables.
UI:N - The attacker issues their own init_module/finit_module (and optional delete_module) against a module they supply; no other user must mount an image, open a file, or bind a device on their behalf.
S:C - cpa_collapse_large_pages() calls pagetable_free() on the PTE table split_large_page() allocated without ptdesc_set_kernel(), so ptdesc_test_kernel() is false and pagetable_free_kernel() never runs iommu_sva_invalidate_kva_range(); a PASID SVA walk can treat the reused page as IOMMU translations, crossing the IOMMU DMA isolation boundary.
C:H - A stale IOTLB paging-structure cache entry for the freed split table lets the IOMMU interpret attacker-controlled reused page contents as PTEs, enabling arbitrary physical-memory DMA reads of kernel or other-process data.
I:H - The same stale IOTLB walk enables arbitrary physical-memory DMA writes, and the IOMMU may write Accessed and Dirty bits into the recycled page while walking it, a write-after-free of the unmarked CPA table.
A:H - Arbitrary DMA writes into reused memory and IOTLB write-after-free of the page cpa_collapse_large_pages() passed to pagetable_free() can corrupt kernel or page-table state, causing an oops, panic, or hang.
| Attack Vector |
Local |
Scope |
Changed |
| Attack Complexity |
Low |
Confidentiality Impact |
High |
| Privileges Required |
High |
Integrity Impact |
High |
| User Interaction |
None |
Availability Impact |
High |
AV:L - split_large_page() is reached from local set_memory_* via change_page_attr_set_clr()→__change_page_attr(); the path that allocates unmarked tables and later frees them is finit_module→module_memory_alloc()→execmem_alloc_rw()→execmem_force_rw()/set_memory_nx (split) then module_enable_text_rox()→set_memory_rox() (collapse). No remote protocol carries the input.
AC:L - On an x86 IOMMU_SVA host, a module whose text is carved from the execmem ROX 2M cache makes execmem_force_rw() split that PMD (pagetable_alloc without ptdesc_set_kernel) and set_memory_rox(CPA_COLLAPSE) free it in cpa_collapse_large_pages(); the same caller binds SVA, primes IOTLB walks, and sprays reuse without an uncontrolled race.
PR:H - may_init_module() requires capable(CAP_SYS_MODULE) in init_user_ns, which user namespaces cannot grant. Only EXECMEM_MODULE_TEXT with EXECMEM_ROX_CACHE both splits a huge mapping in split_large_page() and collapse-frees it; EXECMEM_BPF lacks ROX_CACHE so unprivileged bpf_jit_alloc_exec()/set_memory_rox does not produce these unmarked tables.
UI:N - The attacker issues their own init_module/finit_module (and optional delete_module) against a module they supply; no other user must mount an image, open a file, or bind a device on their behalf.
S:C - cpa_collapse_large_pages() calls pagetable_free() on the PTE table split_large_page() allocated without ptdesc_set_kernel(), so ptdesc_test_kernel() is false and pagetable_free_kernel() never runs iommu_sva_invalidate_kva_range(); a PASID SVA walk can treat the reused page as IOMMU translations, crossing the IOMMU DMA isolation boundary.
C:H - A stale IOTLB paging-structure cache entry for the freed split table lets the IOMMU interpret attacker-controlled reused page contents as PTEs, enabling arbitrary physical-memory DMA reads of kernel or other-process data.
I:H - The same stale IOTLB walk enables arbitrary physical-memory DMA writes, and the IOMMU may write Accessed and Dirty bits into the recycled page while walking it, a write-after-free of the unmarked CPA table.
A:H - Arbitrary DMA writes into reused memory and IOTLB write-after-free of the page cpa_collapse_large_pages() passed to pagetable_free() can corrupt kernel or page-table state, causing an oops, panic, or hang.
CVSS 3.1