Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp4266464pxb; Tue, 19 Apr 2022 22:25:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyk9BKqEHkycW2iT+0g4/j9SK9VMt7Sxzhc2lClEUJ3PUt6Yg9+aM2k6wIhjg4I7WyY1Crf X-Received: by 2002:a17:907:33cc:b0:6e8:81ca:f9e8 with SMTP id zk12-20020a17090733cc00b006e881caf9e8mr16959514ejb.51.1650432335745; Tue, 19 Apr 2022 22:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650432335; cv=none; d=google.com; s=arc-20160816; b=nO79X3Tz4FDo05DevVB1cgffJTPuhIh8YkA/YyQleQlPXshXuO1JWRbo19hHWz++r+ gySFfjiApYTlzotxpj9Jb1D1uTFmTd7gU1n8Jbl69gdo8dPvbig8dinu3cWcKnJjVx0O TeEyWl0Mw5PtStB8hggWdVH7rpasPu+e/+hzmib0ULmGoTz0rvOGLsqegefXxGt4r3+C BO1lE4FZV/DGJz1/XMBJ/XM0nBIZ8syDrNx0WPpMfB+6dO0bT58eyJm18QQ5N2qG722b tBqDOLhyK9c87lHMawaC/wmE/t2m1IXEqu/UeX15pcQ0qz86HZHc03SfDQUD8vGhSRNG Om6A== 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=Zjlbu50LNFZW8Sr8c9nkxmOWdDxGtVgPOF3Z7HmaFDQ=; b=cbZKsaLdRahhn0rZXVAyBMrpImqgeJ7Apxi84z+7ciEnFnADLs6oViu7CDcwWxlAHl iP3Xb1jDY+GBtesK4NsZfxoBTsBF+asWoDuTUwIXKPkxVTLEOYaXd/rS5TbTexhqf51o fW0qgVcXc3RQMxMp+2QTa420jrTjjKN/k7Xs0dtNZCUpcAv58a8Pn5CYk91Fbnf3YgnU ujmHoI7P9j/qPRaKcpjo8N0diRj6aqHL0fqLT32hiB3BwrHGJIU3QahIE/beEUqHfG8a 4Wdjb8nBLaVxagqZGRi26W41LlqjV3l8Rf1tapzQXW8ffh2r7ewFCjBuiOzNM4k2Yjly Lgxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="K/5QC7AP"; 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 o9-20020a056402438900b0041d650cda3asi772301edc.577.2022.04.19.22.25.11; Tue, 19 Apr 2022 22:25:35 -0700 (PDT) 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="K/5QC7AP"; 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 S1344383AbiDRO1O (ORCPT + 99 others); Mon, 18 Apr 2022 10:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343696AbiDROOh (ORCPT ); Mon, 18 Apr 2022 10:14:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 316E838DA2; Mon, 18 Apr 2022 06:12:17 -0700 (PDT) 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 5E38260F60; Mon, 18 Apr 2022 13:12:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 550F4C385A1; Mon, 18 Apr 2022 13:12:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650287535; bh=49IbyB3bAEiPpl+zV8Vgv4uDTQUw3e1IaC/4rdGXXM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K/5QC7AP8eoFzMcy6CDcbAIIJ9JFmkGHiyO92YXRhxUWqIg9zjxLtaGuhMbPrwKA0 IGA4Ae1LGeFLCw46FMk4FXYwrbvgNcCgvbQuhdffwcTCqbAETpburpJadzv7DgD7Wy 8hw06zo2UTAs9iBiQjrdIQRObbO5OcbF38YFoGD4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+6bde52d89cfdf9f61425@syzkaller.appspotmail.com, Paolo Bonzini , Sean Christopherson , Andrew Morton , Linus Torvalds Subject: [PATCH 4.9 192/218] mmmremap.c: avoid pointless invalidate_range_start/end on mremap(old_size=0) Date: Mon, 18 Apr 2022 14:14:18 +0200 Message-Id: <20220418121206.854829492@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121158.636999985@linuxfoundation.org> References: <20220418121158.636999985@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.7 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: Paolo Bonzini commit 01e67e04c28170c47700c2c226d732bbfedb1ad0 upstream. If an mremap() syscall with old_size=0 ends up in move_page_tables(), it will call invalidate_range_start()/invalidate_range_end() unnecessarily, i.e. with an empty range. This causes a WARN in KVM's mmu_notifier. In the past, empty ranges have been diagnosed to be off-by-one bugs, hence the WARNing. Given the low (so far) number of unique reports, the benefits of detecting more buggy callers seem to outweigh the cost of having to fix cases such as this one, where userspace is doing something silly. In this particular case, an early return from move_page_tables() is enough to fix the issue. Link: https://lkml.kernel.org/r/20220329173155.172439-1-pbonzini@redhat.com Reported-by: syzbot+6bde52d89cfdf9f61425@syzkaller.appspotmail.com Signed-off-by: Paolo Bonzini Cc: Sean Christopherson Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/mremap.c | 3 +++ 1 file changed, 3 insertions(+) --- a/mm/mremap.c +++ b/mm/mremap.c @@ -192,6 +192,9 @@ unsigned long move_page_tables(struct vm unsigned long mmun_start; /* For mmu_notifiers */ unsigned long mmun_end; /* For mmu_notifiers */ + if (!len) + return 0; + old_end = old_addr + len; flush_cache_range(vma, old_addr, old_end);