Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3725006pxb; Mon, 24 Jan 2022 16:24:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYuT5oFCyeFRW/rjya2cR+TK7Yfyn8ZTLFOA3poojOqbsdhg/LeEM05IGSv7+VeNBN07W2 X-Received: by 2002:a63:89c8:: with SMTP id v191mr13130195pgd.339.1643070266167; Mon, 24 Jan 2022 16:24:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643070266; cv=none; d=google.com; s=arc-20160816; b=uAP3GbO150+P9dZNr7YsKs6bds5epkZv1IXLF/m8owXzGhNSGHu4fa1UKWpHOj6nV0 kQcd/SJgW0K23xd4tQHiSxD5WFbL4QiDEelEou07Bno+EA7+82k8QEbubtmEhtvIKs7/ tBPX/7RI5du+3oK4tdpp6RHFTUt5ruENLKHU5CjAk2MlQYgHFyJgLOedSG4t9ZKiZYj7 pxthjpYijoxA/hBBKEPYXhU0tx41vRaMPFdKZEGXLF0ERiRwMfieXEDqKehapDkA0uWT 8cdSN1zEN2egsLofddapsLOgfQBsOJuI9VgCVoQcSzotVuB01AGfOlvU0Ip3JgbwkkcM kTBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wLGn4o80KLFoXpH/+G7Ds8ctylxMuQQTEHSK1hQYal8=; b=VA1qGT/sPehMxAEyvCNPQfT/wVMFCc9eH2gXMYclspFMGSfRtlDUxYdy+0+0elX0PW AOk6hqplpu6hKxhHsEkpgrH7l3O4sYlctLiAlftiRsgsXyhUyneGhREe7bTk8EW9JJHd Z9OBtvEKht5ifUkzFJ8BTNHwWezM4hXAyPwh1+yaRkXZvGhmQOiIUrDMZllg6r1QWYFc DvIU4qjUNKUGXySYcAWznGJ/J+zpZcbbCEObMlYQ/x7GAYk9m/XRQe0HtcbQHKrnzjrm KOLEXBvAYaLxbV3QI89jHxPkwif1gSnsoeF0RyK2sgyR6LEqWa8TZ1y4sC4LJebJN2zn CluA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VnHKxBOw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f13si2038273pgm.0.2022.01.24.16.24.14; Mon, 24 Jan 2022 16:24:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VnHKxBOw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2374876AbiAYAS2 (ORCPT + 99 others); Mon, 24 Jan 2022 19:18:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385856AbiAXXdz (ORCPT ); Mon, 24 Jan 2022 18:33:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A53AC07596B; Mon, 24 Jan 2022 13:35:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1906FB81057; Mon, 24 Jan 2022 21:35:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 504F2C340E4; Mon, 24 Jan 2022 21:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060133; bh=a0YiCG/23n5Ij4udWEzbiqQJ3Zz1ama6V6tpi+vrVtk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VnHKxBOwKipeZPKX+BQpw9s4r9SLt+UoIvpsOZlmyZsusLd23S6AjKYE9fIqMK62N R0AhqEmrMV1DZK464xFpinFeCT5fTh1XllVjGImlZefwqXgQBFT126GUaMKliyyLeX VYytnGcfT+7mDF7MDiHiepcs1ldIN29W4BFMOtmM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , syzbot+4e697fe80a31aa7efe21@syzkaller.appspotmail.com, Mike Kravetz , Paolo Bonzini , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.16 0833/1039] hugetlbfs: fix off-by-one error in hugetlb_vmdelete_list() Date: Mon, 24 Jan 2022 19:43:42 +0100 Message-Id: <20220124184153.284397402@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson [ Upstream commit d6aba4c8e20d4d2bf65d589953f6d891c178f3a3 ] 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. Link: https://lkml.kernel.org/r/20211228234257.1926057-1-seanjc@google.com Fixes: 1bfad99ab425 ("hugetlbfs: hugetlb_vmtruncate_list() needs to take a range to delete") Signed-off-by: Sean Christopherson Reported-by: syzbot+4e697fe80a31aa7efe21@syzkaller.appspotmail.com Reviewed-by: Mike Kravetz Cc: Paolo Bonzini Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/hugetlbfs/inode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -409,10 +409,11 @@ hugetlb_vmdelete_list(struct rb_root_cac 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;