lkml.org 
[lkml]   [2019]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patches in this message
/
From
SubjectRe: [GIT pull] x86/pti for 5.4-rc1
Date


> On Sep 17, 2019, at 4:35 PM, Linus Torvalds <torvalds@linux-foundation.org> wrote:
>
> On Tue, Sep 17, 2019 at 4:29 PM Song Liu <songliubraving@fb.com> wrote:
>>
>> How about we just do:
>>
>> diff --git i/arch/x86/mm/pti.c w/arch/x86/mm/pti.c
>> index b196524759ec..0437f65250db 100644
>> --- i/arch/x86/mm/pti.c
>> +++ w/arch/x86/mm/pti.c
>> @@ -341,6 +341,7 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
>> }
>>
>> if (pmd_large(*pmd) || level == PTI_CLONE_PMD) {
>> + WARN_ON_ONCE(addr & ~PMD_MASK);
>> target_pmd = pti_user_pagetable_walk_pmd(addr);
>> if (WARN_ON(!target_pmd))
>> return;
>>
>> So it is a "warn and continue" check just for unaligned PMD address.
>
> The problem there is that the "continue" part can be wrong.
>
> Admittedly it requires a pretty crazy setup: you first hit a
> pmd_large() entry, but the *next* pmd is regular, so you start doing
> the per-page cloning.
>
> And that per-page cloning will be wrong, because it will start in the
> middle of the next pmd, because addr wasn't aligned, and the previous
> pmd-only clone did
>
> addr += PMD_SIZE;
>
> to go to the next case.
>
> See?

I see. This is tricky.

Maybe we should skip clone of the first unaligned large pmd?

diff --git i/arch/x86/mm/pti.c w/arch/x86/mm/pti.c
index 7f2140414440..1dfa69f8196b 100644
--- i/arch/x86/mm/pti.c
+++ w/arch/x86/mm/pti.c
@@ -343,6 +343,11 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
}

if (pmd_large(*pmd) || level == PTI_CLONE_PMD) {
+ if (WARN_ON_ONCE(addr & ~PMD_MASK)) {
+ addr = round_up(addr, PMD_SIZE);
+ continue;
+ }
+
target_pmd = pti_user_pagetable_walk_pmd(addr);
if (WARN_ON(!target_pmd))
return;
Or we can round_down the addr and copy the whole PMD properly:

diff --git i/arch/x86/mm/pti.c w/arch/x86/mm/pti.c
index 7f2140414440..bee9881f2e85 100644
--- i/arch/x86/mm/pti.c
+++ w/arch/x86/mm/pti.c
@@ -343,6 +343,9 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
}

if (pmd_large(*pmd) || level == PTI_CLONE_PMD) {
+ if (WARN_ON_ONCE(addr & ~PMD_MASK))
+ addr &= PMD_MASK;
+
target_pmd = pti_user_pagetable_walk_pmd(addr);
if (WARN_ON(!target_pmd))
return;
I think the latter is better, but I am not sure.

Thanks,
Song

\
 
 \ /
  Last update: 2019-09-18 12:42    [W:0.062 / U:0.292 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site