linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Steven Price <steven.price@arm.com>
To: Qian Cai <cai@lca.pw>, Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	x86@kernel.org, Jan Beulich <jbeulich@suse.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 1/2] x86: mm: ptdump: Calculate effective permissions correctly
Date: Tue, 26 May 2020 11:41:41 +0100	[thread overview]
Message-ID: <430c8ab4-e7cd-6933-dde6-087fac6db872@arm.com> (raw)
In-Reply-To: <20200522180741.GB1337@Qians-MacBook-Air.local>

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


  parent reply	other threads:[~2020-05-26 10:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 15:23 [PATCH 0/2] Fix W+X debug feature on x86 Steven Price
2020-05-21 15:23 ` [PATCH 1/2] x86: mm: ptdump: Calculate effective permissions correctly Steven Price
     [not found]   ` <20200522180741.GB1337@Qians-MacBook-Air.local>
2020-05-26 10:41     ` Steven Price [this message]
2020-05-27 15:15   ` Jan Beulich
2020-05-27 15:55     ` Steven Price
2020-05-21 15:23 ` [PATCH 2/2] mm: ptdump: Expand type of 'val' in note_page() Steven Price
2020-05-21 19:08 ` [PATCH 0/2] Fix W+X debug feature on x86 Andrew Morton
2020-05-22 12:50   ` Steven Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=430c8ab4-e7cd-6933-dde6-087fac6db872@arm.com \
    --to=steven.price@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=cai@lca.pw \
    --cc=dave.hansen@linux.intel.com \
    --cc=jbeulich@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).