Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2467203imm; Thu, 19 Jul 2018 22:11:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcxgPvfqabSf9uDFh3D3maV2LKs3FrwP6to6o51IJOm8HvQFnHqIImeZztS2gtK6U3qrSCX X-Received: by 2002:a17:902:bb90:: with SMTP id m16-v6mr670731pls.50.1532063498608; Thu, 19 Jul 2018 22:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532063498; cv=none; d=google.com; s=arc-20160816; b=D5j5zD3fqX/58eFdu0lxn96O8+AUl96dsxwgzDmRTcfXJRUUCzZ5QezJ2gV/loAC7V Ep6+tlBVe/g/kIoW1gg1/Qx78cjodaaDg5Y2z9RgT90MGXOAOLvZ1pPxoJk5mO4J8yS5 cMQmQiy9sOtjisX07K8hhQrHGijapBcENctAut/JrxWcH8vuLGkKc3aGbChJuRwCsRrK LV9jS7wH8irMIb4ioX7xIyN5bSsQB6zqCM+BmpSZfp0WbHJAV2jd6HgAXKtksXwcG5pd Du3pyjrmD2LCd9SZhfIJAlv9Lvqc+/Cf0FjcayM3ZX3TZD71F4Ns8dLaTKSv/oXIeZmN WCGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=IJLjW72KPUqbyGOhjwctdiQJV3z5WeTkd+cHLXjgRhI=; b=PACEJJxjfWPadJo8U/GTHTj2272XD8JarZJwW2abVbdYu1WT1jxPFINM6tRhywyGuK LAkYbH8rQ/N8vgBtNuTxxjHYnc2CK832+b+qI+5adu3zwso4TuNkt4fnCTSdC7RNws4f 3S+QxgMWy8N1o4HQFamHSIV6+m71aSl+/AW/yzu2LT5WRpPpwq2WZtqz+IY17llRlZqk lo253SzHYr7TGYIinoPdlnNpmBEp21VSM9gkPXJBcHjRldcnAi2e6BVA0iWU4OeYHjBP G1GUk5PrMZmhZlRJyVf+rYT53TEYeLIFlusfce6V/7BSYjCWtkwvfuwPMg/idpMWzLAk ovqw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m14-v6si992234pgc.368.2018.07.19.22.11.24; Thu, 19 Jul 2018 22:11:38 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727338AbeGTF4u (ORCPT + 99 others); Fri, 20 Jul 2018 01:56:50 -0400 Received: from terminus.zytor.com ([198.137.202.136]:43709 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726415AbeGTF4u (ORCPT ); Fri, 20 Jul 2018 01:56:50 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6K5ALAj2538379 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Jul 2018 22:10:21 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6K5ALV52538376; Thu, 19 Jul 2018 22:10:21 -0700 Date: Thu, 19 Jul 2018 22:10:21 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Jiang Biao Message-ID: Cc: mingo@kernel.org, hpa@zytor.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, jiang.biao2@zte.com.cn Reply-To: linux-kernel@vger.kernel.org, jiang.biao2@zte.com.cn, hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de In-Reply-To: <1532045192-49622-2-git-send-email-jiang.biao2@zte.com.cn> References: <1532045192-49622-2-git-send-email-jiang.biao2@zte.com.cn> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/pti: Check the return value of pti_user_pagetable_walk_pmd() Git-Commit-ID: 8c934e01a7ce685d98e970880f5941d79272c654 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 8c934e01a7ce685d98e970880f5941d79272c654 Gitweb: https://git.kernel.org/tip/8c934e01a7ce685d98e970880f5941d79272c654 Author: Jiang Biao AuthorDate: Fri, 20 Jul 2018 08:06:32 +0800 Committer: Thomas Gleixner CommitDate: Fri, 20 Jul 2018 07:07:39 +0200 x86/pti: Check the return value of pti_user_pagetable_walk_pmd() pti_user_pagetable_walk_pmd() can return NULL, so the return value should be checked to prevent a NULL pointer dereference. Add the check and a warning when the PMD allocation fails. Signed-off-by: Jiang Biao Signed-off-by: Thomas Gleixner Cc: dave.hansen@linux.intel.com Cc: luto@kernel.org Cc: hpa@zytor.com Cc: albcamus@gmail.com Cc: zhong.weidong@zte.com.cn Link: https://lkml.kernel.org/r/1532045192-49622-2-git-send-email-jiang.biao2@zte.com.cn --- arch/x86/mm/pti.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 001ee6b0619e..bcf35dac1920 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -205,7 +205,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address) BUILD_BUG_ON(p4d_large(*p4d) != 0); if (p4d_none(*p4d)) { unsigned long new_pud_page = __get_free_page(gfp); - if (!new_pud_page) + if (WARN_ON_ONCE(!new_pud_page)) return NULL; set_p4d(p4d, __p4d(_KERNPG_TABLE | __pa(new_pud_page))); @@ -219,7 +219,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address) } if (pud_none(*pud)) { unsigned long new_pmd_page = __get_free_page(gfp); - if (!new_pmd_page) + if (WARN_ON_ONCE(!new_pmd_page)) return NULL; set_pud(pud, __pud(_KERNPG_TABLE | __pa(new_pmd_page))); @@ -241,9 +241,13 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address) static __init pte_t *pti_user_pagetable_walk_pte(unsigned long address) { gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO); - pmd_t *pmd = pti_user_pagetable_walk_pmd(address); + pmd_t *pmd; pte_t *pte; + pmd = pti_user_pagetable_walk_pmd(address); + if (!pmd) + return NULL; + /* We can't do anything sensible if we hit a large mapping. */ if (pmd_large(*pmd)) { WARN_ON(1);