Commit 9c9e4aa
committed
mm: hugetlb: independent PMD page table shared count
jira VULN-46929
cve CVE-2024-57883
commit-author Liu Shixin <liushixin2@huawei.com>
commit 59d9094
upstream-diff Stable 5.15 backport 8410996eb6fea116fe1483ed977aacf580eee7b4
was used for the actual (clean) cherry-pick. Additionally the `atomic_t
pt_share_count' field in `include/linux/mm_types.h' was wrapped in
RH_KABI_BROKEN_INSERT macro to avoid kABI checker complains. It's
justified, because the inserted field (it's included, as
CONFIG_ARCH_WANT_HUGE_PMD_SHARE gets enabled for at least
`kernel-x86_64-rhel.config') is placed within a union which already
contained a field of the same type `atomic_t pt_frag_refcount', so the
size of it cannot change.
The folio refcount may be increased unexpectly through try_get_folio() by
caller such as split_huge_pages. In huge_pmd_unshare(), we use refcount
to check whether a pmd page table is shared. The check is incorrect if
the refcount is increased by the above caller, and this can cause the page
table leaked:
BUG: Bad page state in process sh pfn:109324
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x66 pfn:0x109324
flags: 0x17ffff800000000(node=0|zone=2|lastcpupid=0xfffff)
page_type: f2(table)
raw: 017ffff800000000 0000000000000000 0000000000000000 0000000000000000
raw: 0000000000000066 0000000000000000 00000000f2000000 0000000000000000
page dumped because: nonzero mapcount
...
CPU: 31 UID: 0 PID: 7515 Comm: sh Kdump: loaded Tainted: G B 6.13.0-rc2master+ #7
Tainted: [B]=BAD_PAGE
Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015
Call trace:
show_stack+0x20/0x38 (C)
dump_stack_lvl+0x80/0xf8
dump_stack+0x18/0x28
bad_page+0x8c/0x130
free_page_is_bad_report+0xa4/0xb0
free_unref_page+0x3cc/0x620
__folio_put+0xf4/0x158
split_huge_pages_all+0x1e0/0x3e8
split_huge_pages_write+0x25c/0x2d8
full_proxy_write+0x64/0xd8
vfs_write+0xcc/0x280
ksys_write+0x70/0x110
__arm64_sys_write+0x24/0x38
invoke_syscall+0x50/0x120
el0_svc_common.constprop.0+0xc8/0xf0
do_el0_svc+0x24/0x38
el0_svc+0x34/0x128
el0t_64_sync_handler+0xc8/0xd0
el0t_64_sync+0x190/0x198
The issue may be triggered by damon, offline_page, page_idle, etc, which
will increase the refcount of page table.
1. The page table itself will be discarded after reporting the
"nonzero mapcount".
2. The HugeTLB page mapped by the page table miss freeing since we
treat the page table as shared and a shared page table will not be
unmapped.
Fix it by introducing independent PMD page table shared count. As
described by comment, pt_index/pt_mm/pt_frag_refcount are used for s390
gmap, x86 pgds and powerpc, pt_share_count is used for x86/arm64/riscv
pmds, so we can reuse the field as pt_share_count.
Link: https://lkml.kernel.org/r/20241216071147.3984217-1-liushixin2@huawei.com
Fixes: 39dde65 ("[PATCH] shared page table for hugetlb page")
Signed-off-by: Liu Shixin <liushixin2@huawei.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Ken Chen <kenneth.w.chen@intel.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nanyong Sun <sunnanyong@huawei.com>
Cc: Jane Chu <jane.chu@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 59d9094)
Signed-off-by: Marcin Wcisło <marcin.wcislo@conclusive.pl>1 parent d23c840 commit 9c9e4aa
3 files changed
+14
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2436 | 2436 | | |
2437 | 2437 | | |
2438 | 2438 | | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
2439 | 2442 | | |
2440 | 2443 | | |
2441 | 2444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6718 | 6718 | | |
6719 | 6719 | | |
6720 | 6720 | | |
6721 | | - | |
| 6721 | + | |
6722 | 6722 | | |
6723 | 6723 | | |
6724 | 6724 | | |
| |||
6733 | 6733 | | |
6734 | 6734 | | |
6735 | 6735 | | |
6736 | | - | |
| 6736 | + | |
6737 | 6737 | | |
6738 | 6738 | | |
6739 | 6739 | | |
| |||
6744 | 6744 | | |
6745 | 6745 | | |
6746 | 6746 | | |
6747 | | - | |
6748 | | - | |
6749 | | - | |
6750 | | - | |
6751 | | - | |
| 6747 | + | |
6752 | 6748 | | |
6753 | 6749 | | |
6754 | 6750 | | |
6755 | 6751 | | |
6756 | 6752 | | |
6757 | 6753 | | |
6758 | 6754 | | |
| 6755 | + | |
6759 | 6756 | | |
6760 | 6757 | | |
6761 | 6758 | | |
6762 | 6759 | | |
6763 | 6760 | | |
6764 | | - | |
6765 | | - | |
| 6761 | + | |
| 6762 | + | |
| 6763 | + | |
6766 | 6764 | | |
6767 | 6765 | | |
6768 | 6766 | | |
6769 | | - | |
| 6767 | + | |
6770 | 6768 | | |
6771 | 6769 | | |
6772 | 6770 | | |
| |||
0 commit comments