Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2502440imm; Mon, 24 Sep 2018 05:33:46 -0700 (PDT) X-Google-Smtp-Source: ACcGV62XyvT3hjrp2ZtSutRgm81eOeNeFHlyZkRK7MkORmeb6S2hCPHF1gaY/weXMknQDLBd6oAz X-Received: by 2002:a17:902:7488:: with SMTP id h8-v6mr10497048pll.16.1537792426460; Mon, 24 Sep 2018 05:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792426; cv=none; d=google.com; s=arc-20160816; b=Zz0L0cTdqXfSLn7A33spf0nunKKgZU6yCOIMDKi7Dhsl7d6TcVviYCGVNcXoTcaPIc 7WfXQkLRFI0tlFD9PgqyUsN3Lo+2DsaOEl40+COASNetFpFz3sYOKNXiJkErklIV1OV5 OKtyUn9nTKl8wj9tmSpWKLXl1PlqJfbROEYvYQlWL+5DDwCUYTMWHoAxs3WlDeSZP1gl wRgwvkkYulZAJpXR0DBfF5JEOfuOTs3k1gNYvVg1P6WuGUwfLUYyVVvvdnl3+8Ks+7a0 9qstPWsFHYk7kwA1ZDE0mIEpH5o5r+ASTycndrLBuklX6bJkLpJYBd5K3Hsk7ov0L/OF UY4g== 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=H0gFULXWWRNeHsGu79zwzoAtvOfcnVWv6kZeIJM55VA=; b=GzP41C874d1wap+lc5F03CRc4k+ANRswAHdUNGGkeIKB0OpctjkkrBDj8yTB83MsVO C4WNDi8bAnRfNyhqF8FcyGTP2EgB0gNhZ1sQiUVDXdj6J6IbnG8akmc91YBqUvBRnl6v JugtXrZlSRuSdmZ6bSSHZw4sHegUkdC6Pfztq+GXQC1Wq/GwoqyrYkOxBSsL20c82SN/ sX/YrSxzGB2jHrI1DJ0XbPiyHj771gdpYJ7KGwqHlXGPAMSUdk2UPkRDn+oe4lWXhGbZ Q0dL/k+PxfUxJBq9tvwWF4sMVOIctp1tJ6NECo+MWygvc4O1L91KQdWZzQ9wBwJO8Jf/ kLAQ== 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 w9-v6si36365060pfg.234.2018.09.24.05.33.31; Mon, 24 Sep 2018 05:33:46 -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 S2388180AbeIXSe1 (ORCPT + 99 others); Mon, 24 Sep 2018 14:34:27 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58194 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387409AbeIXSe0 (ORCPT ); Mon, 24 Sep 2018 14:34:26 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D15501098; Mon, 24 Sep 2018 12:32:30 +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 094/235] x86/pti: Check the return value of pti_user_pagetable_walk_p4d() Date: Mon, 24 Sep 2018 13:51:20 +0200 Message-Id: <20180924113114.607363781@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 b2b7d986a89b6c94b1331a909de1217214fb08c1 ] pti_user_pagetable_walk_p4d() can return NULL, so the return value should be checked to prevent a NULL pointer dereference. Add the check and a warning when the P4D 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-1-git-send-email-jiang.biao2@zte.com.cn Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/pti.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -177,7 +177,7 @@ static p4d_t *pti_user_pagetable_walk_p4 if (pgd_none(*pgd)) { unsigned long new_p4d_page = __get_free_page(gfp); - if (!new_p4d_page) + if (WARN_ON_ONCE(!new_p4d_page)) return NULL; set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(new_p4d_page))); @@ -196,9 +196,13 @@ static p4d_t *pti_user_pagetable_walk_p4 static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address) { gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO); - p4d_t *p4d = pti_user_pagetable_walk_p4d(address); + p4d_t *p4d; pud_t *pud; + p4d = pti_user_pagetable_walk_p4d(address); + if (!p4d) + return NULL; + BUILD_BUG_ON(p4d_large(*p4d) != 0); if (p4d_none(*p4d)) { unsigned long new_pud_page = __get_free_page(gfp); @@ -355,6 +359,9 @@ static void __init pti_clone_p4d(unsigne pgd_t *kernel_pgd; user_p4d = pti_user_pagetable_walk_p4d(addr); + if (!user_p4d) + return; + kernel_pgd = pgd_offset_k(addr); kernel_p4d = p4d_offset(kernel_pgd, addr); *user_p4d = *kernel_p4d;