diff options
author | Kirill A. Shutemov <kirill.shutemov@linux.intel.com> | 2017-11-29 19:11:30 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-11-29 21:40:43 -0500 |
commit | f4f0a3d85b50a65a348e2b8635041d6b30f01deb (patch) | |
tree | 11b100039752f93f1ca110a7c8f02cae39448f7a | |
parent | 5d38f049cee1e1c4a7ac55aa79d37d01ddcc3860 (diff) |
mm/hugetlb: fix NULL-pointer dereference on 5-level paging machine
I made a mistake during converting hugetlb code to 5-level paging: in
huge_pte_alloc() we have to use p4d_alloc(), not p4d_offset().
Otherwise it leads to crash -- NULL-pointer dereference in pud_alloc()
if p4d table is not yet allocated.
It only can happen in 5-level paging mode. In 4-level paging mode
p4d_offset() always returns pgd, so we are fine.
Link: http://lkml.kernel.org/r/20171122121921.64822-1-kirill.shutemov@linux.intel.com
Fixes: c2febafc6773 ("mm: convert generic code to 5-level paging")
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: <stable@vger.kernel.org> [4.11+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | mm/hugetlb.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 698e8fb34031..9a334f5fb730 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c | |||
@@ -4635,7 +4635,9 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, | |||
4635 | pte_t *pte = NULL; | 4635 | pte_t *pte = NULL; |
4636 | 4636 | ||
4637 | pgd = pgd_offset(mm, addr); | 4637 | pgd = pgd_offset(mm, addr); |
4638 | p4d = p4d_offset(pgd, addr); | 4638 | p4d = p4d_alloc(mm, pgd, addr); |
4639 | if (!p4d) | ||
4640 | return NULL; | ||
4639 | pud = pud_alloc(mm, p4d, addr); | 4641 | pud = pud_alloc(mm, p4d, addr); |
4640 | if (pud) { | 4642 | if (pud) { |
4641 | if (sz == PUD_SIZE) { | 4643 | if (sz == PUD_SIZE) { |