Commit d7056d3
committed
mm/hugetlb: unshare page tables during VMA split, not before
jira VULN-71585
cve CVE-2025-38084
commit-author Jann Horn <[email protected]>
commit 081056d
upstream-diff Stable 5.15 backport 366298f2b04d2bf1f2f2b7078405bdf9df9bd5d0
was used for the actual (clean) cherry-pick
Currently, __split_vma() triggers hugetlb page table unsharing through
vm_ops->may_split(). This happens before the VMA lock and rmap locks are
taken - which is too early, it allows racing VMA-locked page faults in our
process and racing rmap walks from other processes to cause page tables to
be shared again before we actually perform the split.
Fix it by explicitly calling into the hugetlb unshare logic from
__split_vma() in the same place where THP splitting also happens. At that
point, both the VMA and the rmap(s) are write-locked.
An annoying detail is that we can now call into the helper
hugetlb_unshare_pmds() from two different locking contexts:
1. from hugetlb_split(), holding:
- mmap lock (exclusively)
- VMA lock
- file rmap lock (exclusively)
2. hugetlb_unshare_all_pmds(), which I think is designed to be able to
call us with only the mmap lock held (in shared mode), but currently
only runs while holding mmap lock (exclusively) and VMA lock
Backporting note:
This commit fixes a racy protection that was introduced in commit
b30c14c ("hugetlb: unshare some PMDs when splitting VMAs"); that
commit claimed to fix an issue introduced in 5.13, but it should actually
also go all the way back.
[[email protected]: v2]
Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Fixes: 39dde65 ("[PATCH] shared page table for hugetlb page")
Signed-off-by: Jann Horn <[email protected]>
Cc: Liam Howlett <[email protected]>
Reviewed-by: Lorenzo Stoakes <[email protected]>
Reviewed-by: Oscar Salvador <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: <[email protected]> [b30c14c: hugetlb: unshare some PMDs when splitting VMAs]
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
(cherry picked from commit 081056d)
Signed-off-by: Marcin Wcisło <[email protected]>1 parent 6b0f840 commit d7056d3
3 files changed
+53
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| 218 | + | |
218 | 219 | | |
219 | 220 | | |
220 | 221 | | |
| |||
420 | 421 | | |
421 | 422 | | |
422 | 423 | | |
| 424 | + | |
| 425 | + | |
423 | 426 | | |
424 | 427 | | |
425 | 428 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
4630 | 4630 | | |
4631 | 4631 | | |
4632 | 4632 | | |
| 4633 | + | |
| 4634 | + | |
4633 | 4635 | | |
| 4636 | + | |
| 4637 | + | |
4634 | 4638 | | |
4635 | 4639 | | |
4636 | 4640 | | |
4637 | 4641 | | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
4638 | 4645 | | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
4639 | 4649 | | |
4640 | | - | |
4641 | | - | |
4642 | | - | |
4643 | | - | |
4644 | | - | |
4645 | 4650 | | |
4646 | 4651 | | |
4647 | 4652 | | |
4648 | | - | |
4649 | | - | |
| 4653 | + | |
| 4654 | + | |
| 4655 | + | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
| 4663 | + | |
| 4664 | + | |
| 4665 | + | |
4650 | 4666 | | |
4651 | | - | |
4652 | | - | |
4653 | 4667 | | |
4654 | 4668 | | |
4655 | 4669 | | |
| |||
7055 | 7069 | | |
7056 | 7070 | | |
7057 | 7071 | | |
| 7072 | + | |
| 7073 | + | |
| 7074 | + | |
| 7075 | + | |
| 7076 | + | |
| 7077 | + | |
7058 | 7078 | | |
7059 | 7079 | | |
7060 | | - | |
| 7080 | + | |
| 7081 | + | |
7061 | 7082 | | |
7062 | 7083 | | |
7063 | 7084 | | |
| |||
7081 | 7102 | | |
7082 | 7103 | | |
7083 | 7104 | | |
7084 | | - | |
| 7105 | + | |
| 7106 | + | |
| 7107 | + | |
| 7108 | + | |
| 7109 | + | |
7085 | 7110 | | |
7086 | 7111 | | |
7087 | 7112 | | |
| |||
7094 | 7119 | | |
7095 | 7120 | | |
7096 | 7121 | | |
7097 | | - | |
| 7122 | + | |
| 7123 | + | |
| 7124 | + | |
7098 | 7125 | | |
7099 | 7126 | | |
7100 | 7127 | | |
| |||
7109 | 7136 | | |
7110 | 7137 | | |
7111 | 7138 | | |
7112 | | - | |
| 7139 | + | |
| 7140 | + | |
7113 | 7141 | | |
7114 | 7142 | | |
7115 | 7143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
851 | 851 | | |
852 | 852 | | |
853 | 853 | | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
854 | 858 | | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
855 | 863 | | |
856 | 864 | | |
857 | 865 | | |
| |||
0 commit comments