From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: jpoimboe@redhat.com, dvlasenk@redhat.com,
torvalds@linux-foundation.org, tglx@linutronix.de,
jgross@suse.com, peterz@infradead.org, bp@alien8.de,
mingo@kernel.org, brgerst@gmail.com, boris.ostrovsky@oracle.com,
jbeulich@suse.com, dvyukov@google.com, hpa@zytor.com,
glider@google.com, luto@kernel.org, linux-kernel@vger.kernel.org,
linux-tip-commits@vger.kernel.org
Subject: Re: [tip:x86/mm] x86/mm: Consider effective protection attributes in W+X check
Date: Mon, 26 Feb 2018 13:00:03 +0300 [thread overview]
Message-ID: <cd48304c-4317-6b5a-bde3-113645df8f81@virtuozzo.com> (raw)
In-Reply-To: <tip-672c0ae09b33a11d8f31fc61526632e96301164c@git.kernel.org>
On 02/26/2018 11:48 AM, tip-bot for Jan Beulich wrote:
> static void note_page(struct seq_file *m, struct pg_state *st,
> - pgprot_t new_prot, int level)
> + pgprot_t new_prot, pgprotval_t new_eff, int level)
> {
> - pgprotval_t prot, cur;
> + pgprotval_t prot, cur, eff;
> static const char units[] = "BKMGTPE";
>
> /*
> @@ -247,23 +248,24 @@ static void note_page(struct seq_file *m, struct pg_state *st,
> */
> prot = pgprot_val(new_prot);
> cur = pgprot_val(st->current_prot);
> + eff = st->effective_prot;
>
> if (!st->level) {
> /* First entry */
> st->current_prot = new_prot;
> + st->effective_prot = new_eff;
> st->level = level;
> st->marker = address_markers;
> st->lines = 0;
> pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n",
> st->marker->name);
> - } else if (prot != cur || level != st->level ||
> + } else if (prot != cur || new_eff != eff || level != st->level ||
> st->current_address >= st->marker[1].start_address) {
> const char *unit = units;
> unsigned long delta;
> int width = sizeof(unsigned long) * 2;
> - pgprotval_t pr = pgprot_val(st->current_prot);
>
> - if (st->check_wx && (pr & _PAGE_RW) && !(pr & _PAGE_NX)) {
> + if (st->check_wx && (eff & _PAGE_RW) && !(eff & _PAGE_NX)) {
> WARN_ONCE(1,
> "x86/mm: Found insecure W+X mapping at address %p/%pS\n",
> (void *)st->start_address,
> @@ -317,21 +319,30 @@ static void note_page(struct seq_file *m, struct pg_state *st,
>
> st->start_address = st->current_address;
> st->current_prot = new_prot;
> + st->effective_prot = new_eff;
> st->level = level;
> }
> }
>
> -static void walk_pte_level(struct seq_file *m, struct pg_state *st, pmd_t addr, unsigned long P)
> +static inline pgprotval_t effective_prot(pgprotval_t prot1, pgprotval_t prot2)
> +{
> + return (prot1 & prot2 & (_PAGE_USER | _PAGE_RW)) |
> + ((prot1 | prot2) & _PAGE_NX);
> +}
> +
> +static void walk_pte_level(struct seq_file *m, struct pg_state *st, pmd_t addr,
> + pgprotval_t eff_in, unsigned long P)
> {
> int i;
> pte_t *start;
> - pgprotval_t prot;
> + pgprotval_t prot, eff;
>
> start = (pte_t *)pmd_page_vaddr(addr);
> for (i = 0; i < PTRS_PER_PTE; i++) {
> prot = pte_flags(*start);
> + eff = effective_prot(eff_in, prot);
> st->current_address = normalize_addr(P + i * PTE_LEVEL_MULT);
> - note_page(m, st, __pgprot(prot), 5);
> + note_page(m, st, __pgprot(prot), eff, 5);
> start++;
> }
> }
> @@ -351,7 +362,7 @@ static inline bool kasan_page_table(struct seq_file *m, struct pg_state *st,
> (pgtable_l5_enabled && __pa(pt) == __pa(kasan_zero_p4d)) ||
> __pa(pt) == __pa(kasan_zero_pud)) {
> pgprotval_t prot = pte_flags(kasan_zero_pte[0]);
> - note_page(m, st, __pgprot(prot), 5);
> + note_page(m, st, __pgprot(prot), 0, 5);
Isn't this disables W+X check for kasan page table?
Methinks it should be 'prot' here.
next prev parent reply other threads:[~2018-02-26 9:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-21 14:34 [PATCH v2] x86: consider " Jan Beulich
2018-02-21 16:53 ` Ingo Molnar
2018-02-22 10:13 ` Jan Beulich
2018-02-23 7:49 ` Ingo Molnar
2018-02-23 7:57 ` Jan Beulich
2018-02-23 8:27 ` [PATCH v3] " Jan Beulich
2018-02-23 10:13 ` [tip:x86/mm] x86/mm: Consider " tip-bot for Jan Beulich
2018-02-26 8:48 ` tip-bot for Jan Beulich
2018-02-26 10:00 ` Andrey Ryabinin [this message]
2018-02-26 10:08 ` Jan Beulich
2018-02-26 10:47 ` Andrey Ryabinin
2018-02-26 10:54 ` Jan Beulich
2018-02-26 12:46 ` Andrey Ryabinin
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=cd48304c-4317-6b5a-bde3-113645df8f81@virtuozzo.com \
--to=aryabinin@virtuozzo.com \
--cc=boris.ostrovsky@oracle.com \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=dvlasenk@redhat.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=hpa@zytor.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®