All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nadav Amit <namit@vmware.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux-MM <linux-mm@kvack.org>,
	"kernel-team@fb.com" <kernel-team@fb.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Dave Hansen <dave.hansen@intel.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Daniel Bristot de Oliveira <bristot@redhat.com>
Subject: Re: [PATCH] x86/mm: Do not split_large_page() for set_kernel_text_rw()
Date: Mon, 26 Aug 2019 15:41:24 +0000	[thread overview]
Message-ID: <31AB5512-F083-4DC3-BA73-D5D65CBC410A@vmware.com> (raw)
In-Reply-To: <20190826073308.6e82589d@gandalf.local.home>

> On Aug 26, 2019, at 4:33 AM, Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> On Fri, 23 Aug 2019 11:36:37 +0200
> Peter Zijlstra <peterz@infradead.org> wrote:
> 
>> On Thu, Aug 22, 2019 at 10:23:35PM -0700, Song Liu wrote:
>>> As 4k pages check was removed from cpa [1], set_kernel_text_rw() leads to
>>> split_large_page() for all kernel text pages. This means a single kprobe
>>> will put all kernel text in 4k pages:
>>> 
>>>  root@ ~# grep ffff81000000- /sys/kernel/debug/page_tables/kernel
>>>  0xffffffff81000000-0xffffffff82400000     20M  ro    PSE      x  pmd
>>> 
>>>  root@ ~# echo ONE_KPROBE >> /sys/kernel/debug/tracing/kprobe_events
>>>  root@ ~# echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable
>>> 
>>>  root@ ~# grep ffff81000000- /sys/kernel/debug/page_tables/kernel
>>>  0xffffffff81000000-0xffffffff82400000     20M  ro             x  pte
>>> 
>>> To fix this issue, introduce CPA_FLIP_TEXT_RW to bypass "Text RO" check
>>> in static_protections().
>>> 
>>> Two helper functions set_text_rw() and set_text_ro() are added to flip
>>> _PAGE_RW bit for kernel text.
>>> 
>>> [1] commit 585948f4f695 ("x86/mm/cpa: Avoid the 4k pages check completely")  
>> 
>> ARGH; so this is because ftrace flips the whole kernel range to RW and
>> back for giggles? I'm thinking _that_ is a bug, it's a clear W^X
>> violation.
> 
> Since ftrace did this way before text_poke existed and way before
> anybody cared (back in 2007), it's not really a bug.
> 
> Anyway, I believe Nadav has some patches that converts ftrace to use
> the shadow page modification trick somewhere.

For the record - here is my previous patch:
https://lkml.org/lkml/2018/12/5/211


  parent reply	other threads:[~2019-08-26 15:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-23  5:23 [PATCH] x86/mm: Do not split_large_page() for set_kernel_text_rw() Song Liu
2019-08-23  9:36 ` Peter Zijlstra
2019-08-26  4:40   ` Song Liu
2019-08-26  9:23     ` Peter Zijlstra
2019-08-26 15:08       ` Song Liu
2019-08-26 20:50         ` Song Liu
2019-08-26 11:33   ` Steven Rostedt
2019-08-26 12:44     ` Peter Zijlstra
2019-08-26 15:41     ` Nadav Amit [this message]
2019-08-26 15:56       ` Peter Zijlstra
2019-08-26 15:56       ` Steven Rostedt
2019-08-26 16:09         ` Nadav Amit

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=31AB5512-F083-4DC3-BA73-D5D65CBC410A@vmware.com \
    --to=namit@vmware.com \
    --cc=bristot@redhat.com \
    --cc=dave.hansen@intel.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@amacapital.net \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.