[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <430c8ab4-e7cd-6933-dde6-087fac6db872@arm.com>
Date: Tue, 26 May 2020 11:41:41 +0100
From: Steven Price <steven.price@....com>
To: Qian Cai <cai@....pw>, Andrew Morton <akpm@...ux-foundation.org>
Cc: Andy Lutomirski <luto@...nel.org>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>, x86@...nel.org,
Jan Beulich <jbeulich@...e.com>, linux-kernel@...r.kernel.org,
linux-mm@...ck.org
Subject: Re: [PATCH 1/2] x86: mm: ptdump: Calculate effective permissions
correctly
On 22/05/2020 19:07, Qian Cai wrote:
> On Thu, May 21, 2020 at 04:23:07PM +0100, Steven Price wrote:
>> --- a/arch/x86/mm/dump_pagetables.c
>> +++ b/arch/x86/mm/dump_pagetables.c
>> @@ -249,10 +249,22 @@ static void note_wx(struct pg_state *st, unsigned long addr)
>> @@ -270,16 +282,10 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
>> struct seq_file *m = st->seq;
>>
>> new_prot = val & PTE_FLAGS_MASK;
>> + new_eff = st->prot_levels[level];
>
> This will trigger,
>
> .config (if ever matters):
> https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config
>
> [ 104.532621] UBSAN: array-index-out-of-bounds in arch/x86/mm/dump_pagetables.c:284:27
> [ 104.542620] index -1 is out of range for type 'pgprotval_t [5]'
Doh! In this case the result (new_eff) is never actually used: the -1 is
used just to flush the last proper entry out, so in this case val == 0
which means the following statement sets new_eff = 0. But obviously an
out-of-bounds access isn't great. Thanks for testing!
The following patch should fix it up by making the assignment
conditional on val != 0.
Andrew: Would you like me to resend, or can you squash in the below?
Steve
-----8<----
diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
index 17aa7ac94a34..ea9010113f69 100644
--- a/arch/x86/mm/dump_pagetables.c
+++ b/arch/x86/mm/dump_pagetables.c
@@ -282,10 +282,10 @@ static void note_page(struct ptdump_state *pt_st,
unsigned long addr, int level,
struct seq_file *m = st->seq;
new_prot = val & PTE_FLAGS_MASK;
- new_eff = st->prot_levels[level];
-
if (!val)
new_eff = 0;
+ else
+ new_eff = st->prot_levels[level];
/*
* If we have a "break" in the series, we need to flush the state that
Powered by blists - more mailing lists