From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: 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 AUTOSEL 4.18 85/88] x86/pti: Check the return value of pti_user_pagetable_walk_p4d() Date: Fri, 7 Sep 2018 00:36:51 +0000 Message-ID: <20180907003547.57567-85-alexander.levin@microsoft.com> References: <20180907003547.57567-1-alexander.levin@microsoft.com> In-Reply-To: <20180907003547.57567-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: 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.bia= o2@zte.com.cn Signed-off-by: Sasha Levin --- arch/x86/mm/pti.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 946455e9cfef..51abd8292b6d 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -177,7 +177,7 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long= address) =20 if (pgd_none(*pgd)) { unsigned long new_p4d_page =3D __get_free_page(gfp); - if (!new_p4d_page) + if (WARN_ON_ONCE(!new_p4d_page)) return NULL; =20 set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(new_p4d_page))); @@ -196,9 +196,13 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned lon= g address) static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address) { gfp_t gfp =3D (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO); - p4d_t *p4d =3D pti_user_pagetable_walk_p4d(address); + p4d_t *p4d; pud_t *pud; =20 + p4d =3D pti_user_pagetable_walk_p4d(address); + if (!p4d) + return NULL; + BUILD_BUG_ON(p4d_large(*p4d) !=3D 0); if (p4d_none(*p4d)) { unsigned long new_pud_page =3D __get_free_page(gfp); @@ -355,6 +359,9 @@ static void __init pti_clone_p4d(unsigned long addr) pgd_t *kernel_pgd; =20 user_p4d =3D pti_user_pagetable_walk_p4d(addr); + if (!user_p4d) + return; + kernel_pgd =3D pgd_offset_k(addr); kernel_p4d =3D p4d_offset(kernel_pgd, addr); *user_p4d =3D *kernel_p4d; --=20 2.17.1