From nobody Sun Jun 21 10:09:36 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5F84C433F5 for ; Tue, 29 Mar 2022 17:32:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240203AbiC2Rdx (ORCPT ); Tue, 29 Mar 2022 13:33:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236824AbiC2Rdv (ORCPT ); Tue, 29 Mar 2022 13:33:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 58E4E19317D for ; Tue, 29 Mar 2022 10:32:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648575126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DoTRqQDJbdqwPWMurSzwBFSAKdvVaPy59umte0ZT9sw=; b=MvdYUWbZzutG6bdVYYgcsCVZkgFSP15jAKn+EIJWGgkjvIpATJO3Z/dD/wvfnuwFqiVW3H 1GBkdxG2K5f35sZB7rewkFXZahpZHLY+ppQHFtWu7pwx4rKKgMYgXPFX4JQo5fimHEoD2J Pu92/gKOWhHkfnx1yjpLK2TqpIXvTs4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-wM6pXmknNyezFYRp8c2AZw-1; Tue, 29 Mar 2022 13:32:03 -0400 X-MC-Unique: wM6pXmknNyezFYRp8c2AZw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 10F218F11D5; Tue, 29 Mar 2022 17:32:02 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B422AC0809D; Tue, 29 Mar 2022 17:31:57 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, syzbot+6bde52d89cfdf9f61425@syzkaller.appspotmail.com, linux-mm@kvack.org, akpm@linux-foundation.org, stable@vger.kernel.org Subject: [PATCH] mm: avoid pointless invalidate_range_start/end on mremap(old_size=0) Date: Tue, 29 Mar 2022 13:31:55 -0400 Message-Id: <20220329173155.172439-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If an mremap() syscall with old_size=3D0 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. Reported-by: syzbot+6bde52d89cfdf9f61425@syzkaller.appspotmail.com Cc: linux-mm@kvack.org Cc: akpm@linux-foundation.org Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini --- mm/mremap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/mremap.c b/mm/mremap.c index 002eec83e91e..0e175aef536e 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -486,6 +486,9 @@ unsigned long move_page_tables(struct vm_area_struct *v= ma, pmd_t *old_pmd, *new_pmd; pud_t *old_pud, *new_pud; =20 + if (!len) + return 0; + old_end =3D old_addr + len; flush_cache_range(vma, old_addr, old_end); =20 --=20 2.31.1