From patchwork Wed Dec 14 09:11:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 87994 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp90662qgi; Wed, 14 Dec 2016 01:12:21 -0800 (PST) X-Received: by 10.98.103.201 with SMTP id t70mr105484808pfj.99.1481706741222; Wed, 14 Dec 2016 01:12:21 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z66si51885024pfk.207.2016.12.14.01.12.20; Wed, 14 Dec 2016 01:12:21 -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; dkim=pass header.i=@linaro.org; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755273AbcLNJMR (ORCPT + 25 others); Wed, 14 Dec 2016 04:12:17 -0500 Received: from mail-qk0-f169.google.com ([209.85.220.169]:34327 "EHLO mail-qk0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755018AbcLNJMP (ORCPT ); Wed, 14 Dec 2016 04:12:15 -0500 Received: by mail-qk0-f169.google.com with SMTP id q130so12675339qke.1 for ; Wed, 14 Dec 2016 01:12:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W+zt4/pcK6b65B+UnQA+8yTimLG3ZoT0v+lKVS20/3o=; b=SBVo8M1dhy/Y7YyML4fVo+Bcl8un0WX1AsQkgEeiIFeCG0y80daQgpzPrckTsfJR2L 4139af0CHriZfy0szb/fxQa041+xEL0k/BDFmD6a6sDIcgziV8FmP40U+asV7QiwdUAr u04dW0OnHIjeE6kWoEOIP7IgNRxnMqtQ3msP4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=W+zt4/pcK6b65B+UnQA+8yTimLG3ZoT0v+lKVS20/3o=; b=LEViqJWa97D2lZt3/iAb7Bcl055P4/86FBVlKSzVY+q4pNEw/qOALqjKhvVQ+0FYQE eFtOemcKd5Flpb3APPvAPdFzX3qk9V7X1SlsLeBwAstmb+DCfMfB5gI1+aG8/pwEFGIf hSu7Jkk1rUHrYFV5MJH3nIPU/9Sg4Z6IInE4Z2UvP7pZLKC00liNobKpvsRL55gGefdM pFYq/K+Xy48h6bvtjigqTCwaxKMggEAnQ5KULEWx7qO7JxLxA83KFNLSpZwXitNFFWEL NWVOog5bnz5RatNjFMtvhf8CxoB6Ba7vJBtepDNwqfGDIhJlRCuuCetEqDtpyvY9+gX6 STNg== X-Gm-Message-State: AKaTC0273KXsLrIxyXv6GxxI7lszywGN61Bhd251S0sPSmIez7rnZFxcVPtL60++vmcsg8Bp X-Received: by 10.28.228.5 with SMTP id b5mr5941488wmh.129.1481706734784; Wed, 14 Dec 2016 01:12:14 -0800 (PST) Received: from localhost.localdomain ([160.169.200.55]) by smtp.gmail.com with ESMTPSA id pd2sm66125652wjb.31.2016.12.14.01.12.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Dec 2016 01:12:14 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: catalin.marinas@arm.com, akpm@linux-foundation.org, hanjun.guo@linaro.org, xieyisheng1@huawei.com, rrichter@cavium.com, james.morse@arm.com, Ard Biesheuvel Subject: [PATCH 1/2] mm: don't dereference struct page fields of invalid pages Date: Wed, 14 Dec 2016 09:11:46 +0000 Message-Id: <1481706707-6211-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481706707-6211-1-git-send-email-ard.biesheuvel@linaro.org> References: <1481706707-6211-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Ard Biesheuvel --- mm/page_alloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.7.4 Acked-by: Will Deacon diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f64e7bcb43b7..4e298e31fa86 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1864,14 +1864,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;