The patch titled Subject: mm/hugetlb: fix use after free when subpool max_hpages accounting is not enabled has been removed from the -mm tree. Its filename was mm-hugetlb-fix-use-after-free-when-subpool-max_hpages-accounting-is-not-enabled.patch This patch was dropped because it was merged into mainline or a subsystem tree ------------------------------------------------------ From: Miaohe Lin <linmiaohe@xxxxxxxxxx> Subject: mm/hugetlb: fix use after free when subpool max_hpages accounting is not enabled If a hugetlbfs filesystem is created with the min_size option and without the size option, used_hpages is always 0 and might lead to release subpool prematurely because it indicates no pages are used now while there might be. In order to fix this issue, we should check used_hpages == 0 iff max_hpages accounting is enabled. As max_hpages accounting should be enabled in most common case, this is not worth a Cc stable. [mike.kravetz@xxxxxxxxxx: new changelog] Link: https://lkml.kernel.org/r/20210126115510.53374-1-linmiaohe@xxxxxxxxxx Signed-off-by: Hongxiang Lou <louhongxiang@xxxxxxxxxx> Signed-off-by: Miaohe Lin <linmiaohe@xxxxxxxxxx> Reviewed-by: Mike Kravetz <mike.kravetz@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/hugetlb.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) --- a/mm/hugetlb.c~mm-hugetlb-fix-use-after-free-when-subpool-max_hpages-accounting-is-not-enabled +++ a/mm/hugetlb.c @@ -97,16 +97,26 @@ static inline void ClearPageHugeFreed(st /* Forward declaration */ static int hugetlb_acct_memory(struct hstate *h, long delta); -static inline void unlock_or_release_subpool(struct hugepage_subpool *spool) +static inline bool subpool_is_free(struct hugepage_subpool *spool) { - bool free = (spool->count == 0) && (spool->used_hpages == 0); + if (spool->count) + return false; + if (spool->max_hpages != -1) + return spool->used_hpages == 0; + if (spool->min_hpages != -1) + return spool->rsv_hpages == spool->min_hpages; + + return true; +} +static inline void unlock_or_release_subpool(struct hugepage_subpool *spool) +{ spin_unlock(&spool->lock); /* If no pages are used, and no other handles to the subpool * remain, give up any reservations based on minimum size and * free the subpool */ - if (free) { + if (subpool_is_free(spool)) { if (spool->min_hpages != -1) hugetlb_acct_memory(spool->hstate, -spool->min_hpages); _ Patches currently in -mm which might be from linmiaohe@xxxxxxxxxx are mm-memory_hotplug-use-helper-function-zone_end_pfn-to-get-end_pfn.patch mm-mlock-stop-counting-mlocked-pages-when-none-vma-is-found.patch mm-rmap-correct-some-obsolete-comments-of-anon_vma.patch mm-rmap-remove-unneeded-semicolon-in-page_not_mapped.patch mm-rmap-fix-obsolete-comment-in-__page_check_anon_rmap.patch mm-rmap-use-page_not_mapped-in-try_to_unmap.patch mm-rmap-correct-obsolete-comment-of-page_get_anon_vma.patch mm-rmap-fix-potential-pte_unmap-on-an-not-mapped-pte.patch mm-zsmallocc-convert-to-use-kmem_cache_zalloc-in-cache_alloc_zspage.patch mm-zsmallocc-use-page_private-to-access-page-private.patch