Skip to content

Commit 4e4f225

Browse files
committed
mm/hugetlb: fix missing hugetlb_lock for resv uncharge
jira LE-1907 cve CVE-2024-36000 Rebuild_History Non-Buildable kernel-4.18.0-553.16.1.el8_10 commit-author Peter Xu <[email protected]> commit b76b469 Empty-Commit: Cherry-Pick Conflicts during history rebuild. Will be included in final tarball splat. Ref for failed cherry-pick at: ciq/ciq_backports/kernel-4.18.0-553.16.1.el8_10/b76b4690.failed There is a recent report on UFFDIO_COPY over hugetlb: https://lore.kernel.org/all/[email protected]/ 350: lockdep_assert_held(&hugetlb_lock); Should be an issue in hugetlb but triggered in an userfault context, where it goes into the unlikely path where two threads modifying the resv map together. Mike has a fix in that path for resv uncharge but it looks like the locking criteria was overlooked: hugetlb_cgroup_uncharge_folio_rsvd() will update the cgroup pointer, so it requires to be called with the lock held. Link: https://lkml.kernel.org/r/[email protected] Fixes: 79aa925 ("hugetlb_cgroup: fix reservation accounting") Signed-off-by: Peter Xu <[email protected]> Reported-by: [email protected] Reviewed-by: Mina Almasry <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> (cherry picked from commit b76b469) Signed-off-by: Jonathan Maple <[email protected]> # Conflicts: # mm/hugetlb.c
1 parent a06aed5 commit 4e4f225

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
mm/hugetlb: fix missing hugetlb_lock for resv uncharge
2+
3+
jira LE-1907
4+
cve CVE-2024-36000
5+
Rebuild_History Non-Buildable kernel-4.18.0-553.16.1.el8_10
6+
commit-author Peter Xu <[email protected]>
7+
commit b76b46902c2d0395488c8412e1116c2486cdfcb2
8+
Empty-Commit: Cherry-Pick Conflicts during history rebuild.
9+
Will be included in final tarball splat. Ref for failed cherry-pick at:
10+
ciq/ciq_backports/kernel-4.18.0-553.16.1.el8_10/b76b4690.failed
11+
12+
There is a recent report on UFFDIO_COPY over hugetlb:
13+
14+
https://lore.kernel.org/all/[email protected]/
15+
16+
350: lockdep_assert_held(&hugetlb_lock);
17+
18+
Should be an issue in hugetlb but triggered in an userfault context, where
19+
it goes into the unlikely path where two threads modifying the resv map
20+
together. Mike has a fix in that path for resv uncharge but it looks like
21+
the locking criteria was overlooked: hugetlb_cgroup_uncharge_folio_rsvd()
22+
will update the cgroup pointer, so it requires to be called with the lock
23+
held.
24+
25+
Link: https://lkml.kernel.org/r/[email protected]
26+
Fixes: 79aa925bf239 ("hugetlb_cgroup: fix reservation accounting")
27+
Signed-off-by: Peter Xu <[email protected]>
28+
Reported-by: [email protected]
29+
Reviewed-by: Mina Almasry <[email protected]>
30+
Cc: David Hildenbrand <[email protected]>
31+
32+
Signed-off-by: Andrew Morton <[email protected]>
33+
(cherry picked from commit b76b46902c2d0395488c8412e1116c2486cdfcb2)
34+
Signed-off-by: Jonathan Maple <[email protected]>
35+
36+
# Conflicts:
37+
# mm/hugetlb.c
38+
diff --cc mm/hugetlb.c
39+
index 1bba953dfe5e,53e0ab5c0845..000000000000
40+
--- a/mm/hugetlb.c
41+
+++ b/mm/hugetlb.c
42+
@@@ -2460,11 -3268,19 +2460,20 @@@ struct page *alloc_huge_page(struct vm_
43+
44+
rsv_adjust = hugepage_subpool_put_pages(spool, 1);
45+
hugetlb_acct_memory(h, -rsv_adjust);
46+
++<<<<<<< HEAD
47+
+ if (deferred_reserve)
48+
+ hugetlb_cgroup_uncharge_page_rsvd(hstate_index(h),
49+
+ pages_per_huge_page(h), page);
50+
++=======
51+
+ if (deferred_reserve) {
52+
+ spin_lock_irq(&hugetlb_lock);
53+
+ hugetlb_cgroup_uncharge_folio_rsvd(hstate_index(h),
54+
+ pages_per_huge_page(h), folio);
55+
+ spin_unlock_irq(&hugetlb_lock);
56+
+ }
57+
++>>>>>>> b76b46902c2d (mm/hugetlb: fix missing hugetlb_lock for resv uncharge)
58+
}
59+
-
60+
- if (!memcg_charge_ret)
61+
- mem_cgroup_commit_charge(folio, memcg);
62+
- mem_cgroup_put(memcg);
63+
-
64+
- return folio;
65+
+ return page;
66+
67+
out_uncharge_cgroup:
68+
hugetlb_cgroup_uncharge_cgroup(idx, pages_per_huge_page(h), h_cg);
69+
* Unmerged path mm/hugetlb.c

0 commit comments

Comments
 (0)