* [PATCH] khugepaged: Fix null-pointer dereference due to race
@ 2020-07-22 12:14 Kirill A. Shutemov
2020-07-22 13:30 ` David Hildenbrand
2020-07-22 17:54 ` Yang Shi
0 siblings, 2 replies; 4+ messages in thread
From: Kirill A. Shutemov @ 2020-07-22 12:14 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-mm, linux-kernel, Kirill A. Shutemov, syzbot+ed318e8b790ca72c5ad0
khugepaged has to drop mmap lock several times while collapsing a page.
The situation can change while the lock is dropped and we need to
re-validate that the VMA is still in place and the PMD is still subject
for collapse.
But we miss one corner case: while collapsing an anonymous pages the VMA
could be replaced with file VMA. If the file VMA doesn't have any
private pages we get NULL pointer dereference:
general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
anon_vma_lock_write include/linux/rmap.h:120 [inline]
collapse_huge_page mm/khugepaged.c:1110 [inline]
khugepaged_scan_pmd mm/khugepaged.c:1349 [inline]
khugepaged_scan_mm_slot mm/khugepaged.c:2110 [inline]
khugepaged_do_scan mm/khugepaged.c:2193 [inline]
khugepaged+0x3bba/0x5a10 mm/khugepaged.c:2238
The fix is to make sure that the VMA is anonymous in
hugepage_vma_revalidate(). The helper is only used for collapsing
anonymous pages.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Reported-by: syzbot+ed318e8b790ca72c5ad0@syzkaller.appspotmail.com
---
mm/khugepaged.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b043c40a21d4..700f5160f3e4 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -958,6 +958,9 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
return SCAN_ADDRESS_RANGE;
if (!hugepage_vma_check(vma, vma->vm_flags))
return SCAN_VMA_CHECK;
+ /* Anon VMA expected */
+ if (!vma->anon_vma || vma->vm_ops)
+ return SCAN_VMA_CHECK;
return 0;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] khugepaged: Fix null-pointer dereference due to race
2020-07-22 12:14 [PATCH] khugepaged: Fix null-pointer dereference due to race Kirill A. Shutemov
@ 2020-07-22 13:30 ` David Hildenbrand
2020-07-22 17:54 ` Yang Shi
1 sibling, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2020-07-22 13:30 UTC (permalink / raw)
To: Kirill A. Shutemov, Andrew Morton
Cc: linux-mm, linux-kernel, syzbot+ed318e8b790ca72c5ad0
On 22.07.20 14:14, Kirill A. Shutemov wrote:
> khugepaged has to drop mmap lock several times while collapsing a page.
> The situation can change while the lock is dropped and we need to
> re-validate that the VMA is still in place and the PMD is still subject
> for collapse.
>
> But we miss one corner case: while collapsing an anonymous pages the VMA
> could be replaced with file VMA. If the file VMA doesn't have any
> private pages we get NULL pointer dereference:
>
> general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> anon_vma_lock_write include/linux/rmap.h:120 [inline]
> collapse_huge_page mm/khugepaged.c:1110 [inline]
> khugepaged_scan_pmd mm/khugepaged.c:1349 [inline]
> khugepaged_scan_mm_slot mm/khugepaged.c:2110 [inline]
> khugepaged_do_scan mm/khugepaged.c:2193 [inline]
> khugepaged+0x3bba/0x5a10 mm/khugepaged.c:2238
>
> The fix is to make sure that the VMA is anonymous in
> hugepage_vma_revalidate(). The helper is only used for collapsing
> anonymous pages.
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
> Reported-by: syzbot+ed318e8b790ca72c5ad0@syzkaller.appspotmail.com
> ---
> mm/khugepaged.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index b043c40a21d4..700f5160f3e4 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -958,6 +958,9 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
> return SCAN_ADDRESS_RANGE;
> if (!hugepage_vma_check(vma, vma->vm_flags))
> return SCAN_VMA_CHECK;
> + /* Anon VMA expected */
> + if (!vma->anon_vma || vma->vm_ops)
> + return SCAN_VMA_CHECK;
> return 0;
> }
>
>
LGTM
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] khugepaged: Fix null-pointer dereference due to race
2020-07-22 12:14 [PATCH] khugepaged: Fix null-pointer dereference due to race Kirill A. Shutemov
@ 2020-07-22 17:54 ` Yang Shi
2020-07-22 17:54 ` Yang Shi
1 sibling, 0 replies; 4+ messages in thread
From: Yang Shi @ 2020-07-22 17:54 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: Andrew Morton, Linux MM, Linux Kernel Mailing List,
syzbot+ed318e8b790ca72c5ad0
On Wed, Jul 22, 2020 at 5:14 AM Kirill A. Shutemov
<kirill.shutemov@linux.intel.com> wrote:
>
> khugepaged has to drop mmap lock several times while collapsing a page.
> The situation can change while the lock is dropped and we need to
> re-validate that the VMA is still in place and the PMD is still subject
> for collapse.
>
> But we miss one corner case: while collapsing an anonymous pages the VMA
> could be replaced with file VMA. If the file VMA doesn't have any
> private pages we get NULL pointer dereference:
>
> general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> anon_vma_lock_write include/linux/rmap.h:120 [inline]
> collapse_huge_page mm/khugepaged.c:1110 [inline]
> khugepaged_scan_pmd mm/khugepaged.c:1349 [inline]
> khugepaged_scan_mm_slot mm/khugepaged.c:2110 [inline]
> khugepaged_do_scan mm/khugepaged.c:2193 [inline]
> khugepaged+0x3bba/0x5a10 mm/khugepaged.c:2238
>
> The fix is to make sure that the VMA is anonymous in
> hugepage_vma_revalidate(). The helper is only used for collapsing
> anonymous pages.
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
> Reported-by: syzbot+ed318e8b790ca72c5ad0@syzkaller.appspotmail.com
Acked-by: Yang Shi <yang.shi@linux.alibaba.com>
I think this is worth backporting to stable as well.
> ---
> mm/khugepaged.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index b043c40a21d4..700f5160f3e4 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -958,6 +958,9 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
> return SCAN_ADDRESS_RANGE;
> if (!hugepage_vma_check(vma, vma->vm_flags))
> return SCAN_VMA_CHECK;
> + /* Anon VMA expected */
> + if (!vma->anon_vma || vma->vm_ops)
> + return SCAN_VMA_CHECK;
> return 0;
> }
>
> --
> 2.26.2
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] khugepaged: Fix null-pointer dereference due to race
@ 2020-07-22 17:54 ` Yang Shi
0 siblings, 0 replies; 4+ messages in thread
From: Yang Shi @ 2020-07-22 17:54 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: Andrew Morton, Linux MM, Linux Kernel Mailing List,
syzbot+ed318e8b790ca72c5ad0
On Wed, Jul 22, 2020 at 5:14 AM Kirill A. Shutemov
<kirill.shutemov@linux.intel.com> wrote:
>
> khugepaged has to drop mmap lock several times while collapsing a page.
> The situation can change while the lock is dropped and we need to
> re-validate that the VMA is still in place and the PMD is still subject
> for collapse.
>
> But we miss one corner case: while collapsing an anonymous pages the VMA
> could be replaced with file VMA. If the file VMA doesn't have any
> private pages we get NULL pointer dereference:
>
> general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> anon_vma_lock_write include/linux/rmap.h:120 [inline]
> collapse_huge_page mm/khugepaged.c:1110 [inline]
> khugepaged_scan_pmd mm/khugepaged.c:1349 [inline]
> khugepaged_scan_mm_slot mm/khugepaged.c:2110 [inline]
> khugepaged_do_scan mm/khugepaged.c:2193 [inline]
> khugepaged+0x3bba/0x5a10 mm/khugepaged.c:2238
>
> The fix is to make sure that the VMA is anonymous in
> hugepage_vma_revalidate(). The helper is only used for collapsing
> anonymous pages.
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
> Reported-by: syzbot+ed318e8b790ca72c5ad0@syzkaller.appspotmail.com
Acked-by: Yang Shi <yang.shi@linux.alibaba.com>
I think this is worth backporting to stable as well.
> ---
> mm/khugepaged.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index b043c40a21d4..700f5160f3e4 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -958,6 +958,9 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
> return SCAN_ADDRESS_RANGE;
> if (!hugepage_vma_check(vma, vma->vm_flags))
> return SCAN_VMA_CHECK;
> + /* Anon VMA expected */
> + if (!vma->anon_vma || vma->vm_ops)
> + return SCAN_VMA_CHECK;
> return 0;
> }
>
> --
> 2.26.2
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-22 17:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 12:14 [PATCH] khugepaged: Fix null-pointer dereference due to race Kirill A. Shutemov
2020-07-22 13:30 ` David Hildenbrand
2020-07-22 17:54 ` Yang Shi
2020-07-22 17:54 ` Yang Shi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.