Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2502485imm; Mon, 24 Sep 2018 05:33:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV60/ow5KFGZCZhiDi+k71m//FkUOWE/a83+Nw2gAh1jvmz8uGO83PiIwIcJoVPMWy0N4bvDO X-Received: by 2002:a63:dd09:: with SMTP id t9-v6mr9108358pgg.370.1537792428175; Mon, 24 Sep 2018 05:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792428; cv=none; d=google.com; s=arc-20160816; b=cSS8KggOmCmEPftdTJIi8C4x6LWx37OugVAnAlqD3KDtDKgoAZb9v/X0Bn72CPkGyv +thnHPVK64rlA/pgtU+wK+N+3cK/ASM+p+Kkadionp7i0Effvc//fZrT7BqSFPm73b8S H9D/ZHpBUI+Z0SZf5P2iiExxuKd6ypSOjj0I9kJgPk3voynYLVwgsICnn5RWBJO2p4P2 vy0YGSM8WJ1UpFAvs2Jx8+HJ44ggS3+htUKoOUOUN48ApTo5+T+/E7VhdwRNenbHOa22 sXeWl/AI7UqrpnYjv5DSR+6gBOxfOjudQc1v2on/GYEYPHO/IvbjbTG3qzoSTLsKCPY9 S+Nw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=LBnRE7SZ/XkFmN0m+Yr6OK1yGpGbEk+SuzwpQfTPf74=; b=COHZHL6DN0UuSZBDbqvnwohs3NAff+LUxpNK56UgQ/YX5GmSlLKgeB7MdeG6lmM7QM B2yAf9DZVclQW6r5AUfIe1RtK69DPHtGkrtUKYXLaUazNZiQTeHSngmtHrF6voTVhsGK SjHbSpotfOqAWUklWrxmu+phtZt6HgEyk5VaS82vDEBOe2144dp8CPRryToqS6dIQwub zTx5emc/atbfB6Jj3EyhkzA1sVZoHqBLbtGcLbDv3/ZL3rp8b+LOCC2h+03/N1keLjKX yMBxA4qt0DwqItXwBz161HE8zUebfDD3FXHMfRMroNn+PMRzXetSdL1Chao9achuL7Y8 bcEQ== 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 24-v6si36470996pft.235.2018.09.24.05.33.32; Mon, 24 Sep 2018 05:33:48 -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 S2388190AbeIXSeb (ORCPT + 99 others); Mon, 24 Sep 2018 14:34:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58212 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729844AbeIXSea (ORCPT ); Mon, 24 Sep 2018 14:34:30 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 01D221018; Mon, 24 Sep 2018 12:32:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiang Biao , Thomas Gleixner , dave.hansen@linux.intel.com, luto@kernel.org, hpa@zytor.com, albcamus@gmail.com, zhong.weidong@zte.com.cn, Sasha Levin Subject: [PATCH 4.18 095/235] x86/pti: Check the return value of pti_user_pagetable_walk_pmd() Date: Mon, 24 Sep 2018 13:51:21 +0200 Message-Id: <20180924113114.774100032@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiang Biao [ Upstream commit 8c934e01a7ce685d98e970880f5941d79272c654 ] 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 Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/pti.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -206,7 +206,7 @@ static pmd_t *pti_user_pagetable_walk_pm 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))); @@ -220,7 +220,7 @@ static pmd_t *pti_user_pagetable_walk_pm } 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))); @@ -242,9 +242,13 @@ static pmd_t *pti_user_pagetable_walk_pm 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);