• Mike Kravetz's avatar
    mm/hugetlb.c: fix reservation race when freeing surplus pages · 1a46e6ec
    Mike Kravetz authored
    commit e5bbc8a6 upstream.
    
    return_unused_surplus_pages() decrements the global reservation count,
    and frees any unused surplus pages that were backing the reservation.
    
    Commit 7848a4bf ("mm/hugetlb.c: add cond_resched_lock() in
    return_unused_surplus_pages()") added a call to cond_resched_lock in the
    loop freeing the pages.
    
    As a result, the hugetlb_lock could be dropped, and someone else could
    use the pages that will be freed in subsequent iterations of the loop.
    This could result in inconsistent global hugetlb page state, application
    api failures (such as mmap) failures or application crashes.
    
    When dropping the lock in return_unused_surplus_pages, make sure that
    the global reservation count (resv_huge_pages) remains sufficiently
    large to prevent someone else from claiming pages about to be freed.
    
    Analyzed by Paul Cassella.
    
    Fixes: 7848a4bf ("mm/hugetlb.c: add cond_resched_lock() in return_unused_surplu...
    1a46e6ec
hugetlb.c 119 KB