Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1351722imu; Wed, 9 Jan 2019 16:52:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN452vn7Tb/kTYx915ub3q8hVD0Wqpunct/Mh6DYf+gkJpx19DP7GMuJQiPPP2DvXufeL1jV X-Received: by 2002:a63:f30d:: with SMTP id l13mr7437613pgh.399.1547081562640; Wed, 09 Jan 2019 16:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547081562; cv=none; d=google.com; s=arc-20160816; b=vR+4A2NLtI7Gx8NfdQze+GvN4uzrH//TmlNmnA8GJ/3DjNakaT/26r1+VIfR2Dyhu+ NnVSxMYqRsxxjg0hTGWF0YuAEXwzzpogN/XoROUng6G3r1uD/BUDXnR63xLs5fw1zIfX ab1scmctyud7d+LAPfyMlaKmC7Qq8SSfEdIsm96Ob4F63L7P09GvaZV/aFt3bwmX82mh 3YZEIXY7z4i54sWJXzsa3s+9hWpI9QnUDpLaoVOkzSwtITibnbfPiZxZlqmpY4U34E8+ mKMysXkmJtFTbn7RpqamZJicaqSgbMMMwVq1cGgsxb9CWZloYDfQdIiBq36wJVd/8xIT e2aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=XU4fDVNQLwOeW6Kd+i8auPS35fJzTSM4XTcBQ5ssOmI=; b=MDG49AMgYS/5cZIZQG6uYLl39ZjdWC6KgxBjKwiI0QD7dT6yyTxqfmObqPMSUdTjOy RiZKVbhcfchP8THyww9UrV4Hv19xX2IpYXxuNRB7X1LCVWy+pvOpWO+lko6QYgEUMSR0 JHUrGgJ+0+2O+GJxf5HF6KMXdUeN9Vy6BHwbRP9GPkGp5GArMjYwa1ka2ZGPzdfLMPUU YnGIaW4/3e2dlo5XgIn78wnJKBjHoqkSpZOnXLfFCYLDIgMwOVR63AJRtParkqYlHJDM ywIQlTqFGK0yKO0svxWkfVbYnQNl3Y1XDETRfWM72bUUTQHqJ/2x1cK0h33ojZ+JPzcb 79rA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si9570113pfe.52.2019.01.09.16.52.27; Wed, 09 Jan 2019 16:52:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726818AbfAJAvX (ORCPT + 99 others); Wed, 9 Jan 2019 19:51:23 -0500 Received: from mga18.intel.com ([134.134.136.126]:29409 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726458AbfAJAvW (ORCPT ); Wed, 9 Jan 2019 19:51:22 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2019 16:51:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,459,1539673200"; d="scan'208";a="108696460" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.154]) by orsmga008.jf.intel.com with ESMTP; 09 Jan 2019 16:51:22 -0800 From: Sean Christopherson To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, leozinho29_eu@hotmail.com, Mike Galbraith , Adam Borowski , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jan Kara , Matthew Wilcox , Ross Zwisler , Dan Williams , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Michal Hocko , Felix Kuehling , Ralph Campbell , John Hubbard , Andrew Morton , Linus Torvalds Subject: [PATCH] mm/mmu_notifier: mm/rmap.c: Fix a mmu_notifier range bug in try_to_unmap_one Date: Wed, 9 Jan 2019 16:51:17 -0800 Message-Id: <20190110005117.18282-1-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The conversion to use a structure for mmu_notifier_invalidate_range_*() unintentionally changed the usage in try_to_unmap_one() to init the 'struct mmu_notifier_range' with vma->vm_start instead of @address, i.e. it invalidates the wrong address range. Revert to the correct address range. Manifests as KVM use-after-free WARNINGs and subsequent "BUG: Bad page state in process X" errors when reclaiming from a KVM guest due to KVM removing the wrong pages from its own mappings. Reported-by: leozinho29_eu@hotmail.com Reported-by: Mike Galbraith Reported-by: Adam Borowski Cc: Jérôme Glisse Cc: Christian König Cc: Jan Kara Cc: Matthew Wilcox Cc: Ross Zwisler Cc: Dan Williams Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Michal Hocko Cc: Felix Kuehling Cc: Ralph Campbell Cc: John Hubbard Cc: Andrew Morton Cc: Linus Torvalds Fixes: ac46d4f3c432 ("mm/mmu_notifier: use structure for invalidate_range_start/end calls v2") Signed-off-by: Sean Christopherson --- FWIW, I looked through all other calls to mmu_notifier_range_init() in the patch and didn't spot any other unintentional functional changes. mm/rmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 68a1a5b869a5..0454ecc29537 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1371,8 +1371,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, * Note that the page can not be free in this function as call of * try_to_unmap() must hold a reference on the page. */ - mmu_notifier_range_init(&range, vma->vm_mm, vma->vm_start, - min(vma->vm_end, vma->vm_start + + mmu_notifier_range_init(&range, vma->vm_mm, address, + min(vma->vm_end, address + (PAGE_SIZE << compound_order(page)))); if (PageHuge(page)) { /* -- 2.19.2