Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1793044pxp; Mon, 7 Mar 2022 02:27:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJynC8VQGYLQlSdHfd9swhJFFkiCt+XWLa+tWWMXbUfNT0eeD+l9saQxh7Yvh+Ms305H30Bw X-Received: by 2002:a63:1803:0:b0:37e:d39e:949c with SMTP id y3-20020a631803000000b0037ed39e949cmr9225647pgl.100.1646648845174; Mon, 07 Mar 2022 02:27:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646648845; cv=none; d=google.com; s=arc-20160816; b=0ONlCq5K1E+3pIuJFCK6nPrtd+MC70zNPx5F1ZfbyCLKa4tYdc9CNlyDD9NXWLohoq uGorwHvmPxugstFscsZZJgPyumGrH1QoE2vbvQEor1p1jj38a2+ezMP16K5+b1SYuEOd JpRRTpung6KkNr71df8XgTFUkYUFvU+vcss0CWIo/D7CUbbEVvqr84i3Fz+miO+hJu/t R8rCtW2Fy37WYbuO+h+7hiZ0jkEk5oegjrRYzWYMxzZMoh+/36G1z59hUjnlMmEO6nZ6 sSUYNq7V0Y5JHDhMXk84Z6A2/RX33Bi16Y4K7QlF48/UR0/weyAD8n9TXdNDeCaQ6yYT r4yQ== 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=aXJWFfKDwRUJPuwvsZGB4hUudDqnPhC+CEYa09Ncjsw=; b=I8RM6b3FKUl636lZ8oNPVIlDO7Wp5yLI+xy5G8f/bFeaT9jvJ5IbrObgh8glJgY/Xq bZO44YC7Lg56/7Os6F0lSq0GeqhxCP5YAsNtQzkdDRtDUT7xOBrzBdeEFF0teus1TSGP 4CrS1O66Mp5l7L1Mscq+fLfNdwRmvAcUYnB6JOUUk2zN2k1LKbHcWDqsMHt50eUROtnq j59Q4qdq9UuNMZowWp2fQVZ6bL84/tCZg7+sSUeDOpbRUbnwDu7EvpcV+GxDAlhYVkIj i1ILd+HxIjihHd7qfHzKkN8n0TWHlbzcnAzdSS7MarRXW+p2PXjJwVKqhJ9Bv1boMRzJ pebg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Pbyft/bX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mh17-20020a17090b4ad100b001bd14e030c7si461643pjb.159.2022.03.07.02.26.47; Mon, 07 Mar 2022 02:27:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Pbyft/bX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239140AbiCGKDH (ORCPT + 99 others); Mon, 7 Mar 2022 05:03:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241044AbiCGJlr (ORCPT ); Mon, 7 Mar 2022 04:41:47 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E51D6D872; Mon, 7 Mar 2022 01:39:33 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2794860F63; Mon, 7 Mar 2022 09:39:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36D08C340E9; Mon, 7 Mar 2022 09:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646645972; bh=i6eWzl/jBwIItkoI0ahapdrJ09185ZksOOhX4gEGG0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pbyft/bXq93m406sNkEG+jwu9ljZiF+BHbqUrrwuARIGVvph7bkwi36B0uzcwCAdS OgQjWtiqB//gkCYgZ52no1651Z+Prw3ADsgMJ9ML06MvhH2fEBboYoFxz4kay1vzSS vaK8E3rmUI1JGhFuSySKdkIvfGh8akjpC64uIflE= 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.15 095/262] hugetlbfs: fix off-by-one error in hugetlb_vmdelete_list() Date: Mon, 7 Mar 2022 10:17:19 +0100 Message-Id: <20220307091705.155232526@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091702.378509770@linuxfoundation.org> References: <20220307091702.378509770@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index cdfb1ae78a3f8..54c4e0b0dda4a 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