* [PATCH] hugetlbfs: Fix off-by-one error in hugetlb_vmdelete_list()
@ 2021-12-28 23:42 Sean Christopherson
2021-12-29 3:52 ` Mike Kravetz
0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2021-12-28 23:42 UTC (permalink / raw)
To: Mike Kravetz
Cc: linux-mm, linux-kernel, syzbot+4e697fe80a31aa7efe21, kvm,
Paolo Bonzini, Sean Christopherson
Pass "end - 1" instead of "end" when walking the interval tree in
hugetlb_vmdelete_list() to fix an inclusive vs. exclusive bug. The two
callers that pass a non-zero "end" treat it as exclusive, whereas the
interval tree iterator expects an inclusive "last". E.g. punching a hole
in a file that precisely matches the size of a single hugepage, with a
vma starting right on the boundary, will result in unmap_hugepage_range()
being called twice, with the second call having start==end.
The off-by-one error doesn't cause functional problems as
__unmap_hugepage_range() turns into a massive nop due to short-circuiting
its for-loop on "address < end". But, the mmu_notifier invocations to
invalid_range_{start,end}() are passed a bogus zero-sized range, which
may be unexpected behavior for secondary MMUs.
The bug was exposed by commit ed922739c919 ("KVM: Use interval tree to do
fast hva lookup in memslots"), currently queued in the KVM tree for 5.17,
which added a WARN to detect ranges with start==end.
Reported-by: syzbot+4e697fe80a31aa7efe21@syzkaller.appspotmail.com
Fixes: 1bfad99ab425 ("hugetlbfs: hugetlb_vmtruncate_list() needs to take a range to delete")
Cc: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
Not sure if this should go to stable@. It's mostly harmless, and likely
nothing more than a minor performance blip when it's not harmless.
fs/hugetlbfs/inode.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 49d2e686be74..a7c6c7498be0 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -409,10 +409,11 @@ hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end)
struct vm_area_struct *vma;
/*
- * end == 0 indicates that the entire range after
- * start should be unmapped.
+ * end == 0 indicates that the entire range after start should be
+ * unmapped. Note, end is exclusive, whereas the interval tree takes
+ * an inclusive "last".
*/
- vma_interval_tree_foreach(vma, root, start, end ? end : ULONG_MAX) {
+ vma_interval_tree_foreach(vma, root, start, end ? end - 1 : ULONG_MAX) {
unsigned long v_offset;
unsigned long v_end;
--
2.34.1.448.ga2b2bfdf31-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hugetlbfs: Fix off-by-one error in hugetlb_vmdelete_list()
2021-12-28 23:42 [PATCH] hugetlbfs: Fix off-by-one error in hugetlb_vmdelete_list() Sean Christopherson
@ 2021-12-29 3:52 ` Mike Kravetz
2021-12-29 23:29 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Mike Kravetz @ 2021-12-29 3:52 UTC (permalink / raw)
To: Sean Christopherson
Cc: linux-mm, linux-kernel, syzbot+4e697fe80a31aa7efe21, kvm,
Paolo Bonzini, Andrew Morton
+Cc Andrew if he wants to take it though his tree.
On 12/28/21 15:42, Sean Christopherson wrote:
> Pass "end - 1" instead of "end" when walking the interval tree in
> hugetlb_vmdelete_list() to fix an inclusive vs. exclusive bug. The two
> callers that pass a non-zero "end" treat it as exclusive, whereas the
> interval tree iterator expects an inclusive "last". E.g. punching a hole
> in a file that precisely matches the size of a single hugepage, with a
> vma starting right on the boundary, will result in unmap_hugepage_range()
> being called twice, with the second call having start==end.
>
> The off-by-one error doesn't cause functional problems as
> __unmap_hugepage_range() turns into a massive nop due to short-circuiting
> its for-loop on "address < end". But, the mmu_notifier invocations to
> invalid_range_{start,end}() are passed a bogus zero-sized range, which
> may be unexpected behavior for secondary MMUs.
>
> The bug was exposed by commit ed922739c919 ("KVM: Use interval tree to do
> fast hva lookup in memslots"), currently queued in the KVM tree for 5.17,
> which added a WARN to detect ranges with start==end.
>
> Reported-by: syzbot+4e697fe80a31aa7efe21@syzkaller.appspotmail.com
> Fixes: 1bfad99ab425 ("hugetlbfs: hugetlb_vmtruncate_list() needs to take a range to delete")
> Cc: kvm@vger.kernel.org
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Thanks Sean!
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
>
> Not sure if this should go to stable@. It's mostly harmless, and likely
> nothing more than a minor performance blip when it's not harmless.
I am also unsure about the need to send to stable. It is possible automation
will pick it up and make that decision for us.
--
Mike Kravetz
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hugetlbfs: Fix off-by-one error in hugetlb_vmdelete_list()
2021-12-29 3:52 ` Mike Kravetz
@ 2021-12-29 23:29 ` Andrew Morton
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2021-12-29 23:29 UTC (permalink / raw)
To: Mike Kravetz
Cc: Sean Christopherson, linux-mm, linux-kernel,
syzbot+4e697fe80a31aa7efe21, kvm, Paolo Bonzini
On Tue, 28 Dec 2021 19:52:37 -0800 Mike Kravetz <mike.kravetz@oracle.com> wrote:
> +Cc Andrew if he wants to take it though his tree.
Sure.
> >
> > Not sure if this should go to stable@. It's mostly harmless, and likely
> > nothing more than a minor performance blip when it's not harmless.
>
> I am also unsure about the need to send to stable. It is possible automation
> will pick it up and make that decision for us.
Automation shouldn't do that for mm/ patches because we asked. But fs/
material might sneak through. But it does appear that -stable
won't need this.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-12-29 23:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-28 23:42 [PATCH] hugetlbfs: Fix off-by-one error in hugetlb_vmdelete_list() Sean Christopherson
2021-12-29 3:52 ` Mike Kravetz
2021-12-29 23:29 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).