From patchwork Sat Jul 15 01:26:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Levin, Alexander \(Sasha Levin\)" X-Patchwork-Id: 107838 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1644554qge; Fri, 14 Jul 2017 18:29:35 -0700 (PDT) X-Received: by 10.84.232.5 with SMTP id h5mr18631873plk.261.1500082175485; Fri, 14 Jul 2017 18:29:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500082175; cv=none; d=google.com; s=arc-20160816; b=r1aWUcNF3HFk3aHePdwvtbfZlsy8dZENVyi/ajPFA7TW7k29CmssuJ5kI3A/nkiwjg fm/MbaHaGZwiW11kMHtwnJTmqi9oaBxZ8j7PlQ8jLCzrzapMM9M8/om+pT6enSRzVfNq sC7U4Q6KxpXAel2rPN9D/ag787XoDIOT5/rV+q40KVm8qM9C8Q5YiqcYgzkky70CZabf mO85G1uZWujIXGBFTfOcQNqUmi/jxcOi1YJoZnWQe/JeSCTFdUPF9DAAmtJbz1V5yYaf ELsqqHzxgOQxo5c+C/26Mq0XGA1t2Wt1vStOsnlEYDHwbSz9JSmziM6cDEYBjkRDANQl DDZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:to:dkim-signature :dkim-signature:cc:from:dkim-signature:arc-authentication-results; bh=aaKln6pxwwsPO7T6+DcAzaGutOthOsjunDsJmoEIJBM=; b=MjsY1AXyWyV+lgJWDMOrqiJNS0d7eGaIAFPoM0dNtP6ilAiSGEy+5z+4AUqJUkXM4f +mP3XyCyh3Ted3+QgzPEby5gww+35op26EBQYYis1hXoUnGG2vSY+OeSw1TfXi3pr/bP YSBzKVrJsw8ep7m4gbqg85o13YjQWQaabTY86eVNgN8laTfthv6fEma0wccF/bqj8tnE XX6RmbMf6RPSF5cqP7pEVO3mwFcOEv0kTPq5SQQ2pMD6P/eXlDtCirnOMZKFnPddw9wN rDaay9oJAv/sMj33DoYmBbnNBlprMkNniSp1S3guUXO7qNbOiu5M1j1uYB7QOTQjPRKI mbaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@verizon.com header.b=TMnatgLp; dkim=fail header.i=@verizon.com header.b=vIpedP6Q; dkim=fail header.i=@verizon.com header.b=vIpedP6Q; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d23si7781072plj.559.2017.07.14.18.29.35; Fri, 14 Jul 2017 18:29:35 -0700 (PDT) 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; dkim=pass header.i=@verizon.com header.b=TMnatgLp; dkim=fail header.i=@verizon.com header.b=vIpedP6Q; dkim=fail header.i=@verizon.com header.b=vIpedP6Q; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752564AbdGOB3b (ORCPT + 25 others); Fri, 14 Jul 2017 21:29:31 -0400 Received: from omzsmtpe01.verizonbusiness.com ([199.249.25.210]:44101 "EHLO omzsmtpe01.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752222AbdGOB2F (ORCPT ); Fri, 14 Jul 2017 21:28:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1500082085; x=1531618085; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=J844v3HboFo3pYV5ZYibvF2OLJZgfjqFkJ/jIVAwVbs=; b=TMnatgLpBp0w50A64JyT7GwPO15rhOLJmrOt3zelQlfoxauWQmZBkV4a udcLMBObH9D2jsMP/NTkIKo/HjkuIGN1SDq0qifNQKRi4TlROJOP5VcNY sV6ijxygzOml1XgR9zfiFCl5SRAtEOuojPF75VHuniC7EeZ6a9Mmqylr8 8=; X-IronPort-Anti-Spam-Filtered: false Received: from unknown (HELO fldsmtpi03.verizon.com) ([166.68.71.145]) by omzsmtpe01.verizonbusiness.com with ESMTP; 15 Jul 2017 01:28:00 +0000 From: "Levin, Alexander (Sasha Levin)" Cc: Ard Biesheuvel , Catalin Marinas , Hanjun Guo , Yisheng Xie , Robert Richter , James Morse , Andrew Morton , "Linus Torvalds" , "Levin, Alexander (Sasha Levin)" Received: from rogue-10-255-192-101.rogue.vzwcorp.com (HELO atlantis.verizonwireless.com) ([10.255.192.101]) by fldsmtpi03.verizon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 Jul 2017 01:27:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1500082072; x=1531618072; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=J844v3HboFo3pYV5ZYibvF2OLJZgfjqFkJ/jIVAwVbs=; b=vIpedP6Q2g1CbI/P5a3MjO5rPjGs3xeU1iezKE/QyYiFO7m4l6EvC6gL cSj1hD5ucie5brBW4cFuW3PVxAk41cydT1CvbXPXuwLbBow9l8PcB+w+o WkeiiKzLuVwl+24Y2uT4EAr5eG3AHOgQiN7XP6lKC2vr0s68EGJRPANdY 8=; Received: from ranger.odc.vzwcorp.com (HELO mercury.verizonwireless.com) ([10.255.240.27]) by atlantis.verizonwireless.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Jul 2017 21:27:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1500082072; x=1531618072; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=J844v3HboFo3pYV5ZYibvF2OLJZgfjqFkJ/jIVAwVbs=; b=vIpedP6Q2g1CbI/P5a3MjO5rPjGs3xeU1iezKE/QyYiFO7m4l6EvC6gL cSj1hD5ucie5brBW4cFuW3PVxAk41cydT1CvbXPXuwLbBow9l8PcB+w+o WkeiiKzLuVwl+24Y2uT4EAr5eG3AHOgQiN7XP6lKC2vr0s68EGJRPANdY 8=; X-Host: ranger.odc.vzwcorp.com Received: from casac1exh003.uswin.ad.vzwcorp.com ([10.11.218.45]) by mercury.verizonwireless.com with ESMTP/TLS/AES128-SHA256; 15 Jul 2017 01:27:51 +0000 Received: from scwexch16apd.uswin.ad.vzwcorp.com (153.114.130.35) by CASAC1EXH003.uswin.ad.vzwcorp.com (10.11.218.45) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 14 Jul 2017 18:27:50 -0700 Received: from OMZP1LUMXCA12.uswin.ad.vzwcorp.com (144.8.22.187) by scwexch16apd.uswin.ad.vzwcorp.com (153.114.130.35) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Fri, 14 Jul 2017 18:27:50 -0700 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) by OMZP1LUMXCA12.uswin.ad.vzwcorp.com (144.8.22.187) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Fri, 14 Jul 2017 20:27:48 -0500 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) by OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) with mapi id 15.00.1263.000; Fri, 14 Jul 2017 20:27:49 -0500 To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH for v4.9 LTS 85/87] mm: don't dereference struct page fields of invalid pages Thread-Topic: [PATCH for v4.9 LTS 85/87] mm: don't dereference struct page fields of invalid pages Thread-Index: AQHS/QlhW4HcSQaRTUqgy2uhzBt1QQ== Date: Sat, 15 Jul 2017 01:26:27 +0000 Message-ID: <20170715012538.10101-85-alexander.levin@verizon.com> References: <20170715012538.10101-1-alexander.levin@verizon.com> In-Reply-To: <20170715012538.10101-1-alexander.levin@verizon.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.144.60.250] MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit f073bdc51771f5a5c7a8d1191bfc3ae371d44de7 ] The VM_BUG_ON() check in move_freepages() checks whether the node id of a page matches the node id of its zone. However, it does this before having checked whether the struct page pointer refers to a valid struct page to begin with. This is guaranteed in most cases, but may not be the case if CONFIG_HOLES_IN_ZONE=y. So reorder the VM_BUG_ON() with the pfn_valid_within() check. Link: http://lkml.kernel.org/r/1481706707-6211-2-git-send-email-ard.biesheuvel@linaro.org Signed-off-by: Ard Biesheuvel Acked-by: Will Deacon Cc: Catalin Marinas Cc: Hanjun Guo Cc: Yisheng Xie Cc: Robert Richter Cc: James Morse Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/page_alloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 56df8c24689d..85881bf01776 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1875,14 +1875,14 @@ int move_freepages(struct zone *zone, #endif for (page = start_page; page <= end_page;) { - /* Make sure we are not inadvertently changing nodes */ - VM_BUG_ON_PAGE(page_to_nid(page) != zone_to_nid(zone), page); - if (!pfn_valid_within(page_to_pfn(page))) { page++; continue; } + /* Make sure we are not inadvertently changing nodes */ + VM_BUG_ON_PAGE(page_to_nid(page) != zone_to_nid(zone), page); + if (!PageBuddy(page)) { page++; continue;