Skip to contentSkip to conversation

x86/pti: check the return value ofpti_user_pagetable_walk_p4d

PATCH Thomas Gleixner 1 participant 1 message Jul 17, 2018 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 23 lines · On Tue, 17 Jul 2018, [email protected] wrote:
Quoted 20 lines · Jiang Biao

arch/x86/mm/pti.c static p4d_t *pti_user_pagetable_walk_p4d(unsigned long address) · line 201

Quoted 13 lines
arch/x86/mm/pti.c +3 -1
index 4d418e7..be9e5bc 100644
@@ -195,8 +195,10 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long address)
 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);
     pud_t *pud;
+    p4d_t *p4d = pti_user_pagetable_walk_p4d(address);
+    if (WARN_ON(!p4d))
+        return NULL;

First of all, I don't think we need the (new) warning here. pti_user_pagetable_walk_p4d() only returns NULL if you try it on a userspace _address_ or the page allocation fails. It already warns on the address case.

Quoted 3 lines

If you think the allocation path needs a warning, please do it as close as possible to the _source_ of the warning (the failed allocation), not in the caller.

Quoted 9 lines

Hi,
Just taking pti_clone_pmds() as reference, which add warning for NULL *target_pmd*. The warning does not really matter, I will remove the *WARN_ON* here and add a warning close to the failed allocation. Furthermore do you think we need to check _NULL_ return value?
to avoid NULL pointer dereference when the return value is used later, such as,
p4d_large(*p4d) //p4d is return value of pti_user_pagetable_walk_p4d *user_p4d = *kernel_p4d;//user_p4d is return value of pti_user_pagetable_walk_p4d

The Null pointer check makes sense.

Thanks,

tglx