All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Russell King - ARM Linux <linux@armlinux.org.uk>
Cc: Phil Elwell <phil@raspberrypi.org>,
	Matthias Reichl <hias@horus.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Eric Anholt <eric@anholt.net>,
	Stefan Wahren <stefan.wahren@i2se.com>,
	linux-rpi-kernel@lists.infradead.org,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] Arm: mm: ftrace: Only set text back to ro after kernel has been marked ro
Date: Tue, 5 Dec 2017 11:35:59 -0800	[thread overview]
Message-ID: <CAGXu5jJb0PCSuC4DuOkh5-901iVLcmmPpn1G7UBq3-r9DaeMvw@mail.gmail.com> (raw)
In-Reply-To: <20171205133601.GX10595@n2100.armlinux.org.uk>

On Tue, Dec 5, 2017 at 5:36 AM, Russell King - ARM Linux
<linux@armlinux.org.uk> wrote:
> On Tue, Dec 05, 2017 at 01:30:11PM +0000, Phil Elwell wrote:
>> This was my initial explanation:
>>
>> 1. Data which is marked __ro_after_init is initially writeable.
>>
>> 2. The ro_perms data covers kernel text, read-only data and __ro_after_init data.
>>
>> 3. set_kernel_text_rw marks everything in ro_perms as writeable.
>>
>> 4. set_kernel_text_ro marks everything in ro_perms as read-only, including the __ro_after_init data.
>>
>> 5. Using the function tracing code involves code modification, resulting in calls to
>>    __ftrace_modify_code and set_kernel_text_ro.
>>
>> 6. Therefore if function tracing is enabled before kernel_init has completed then the __ro_after_init
>>    data is made read-only prematurely.
>
> My question still stands, but let me rephrase.  Do we need
> set_kernel_text_*() to touch the read-only data?

We don't _need_ to, but they're all contiguous, so the ro_perms array
used by set_kernel_text_*() is actually only a single entry:

static struct section_perm ro_perms[] = {
        /* Make kernel code and rodata RX (set RO). */
        {
                .name   = "text/rodata RO",
                .start  = (unsigned long)_stext,
                .end    = (unsigned long)__init_begin,
...


-Kees

-- 
Kees Cook
Pixel Security

WARNING: multiple messages have this Message-ID (diff)
From: keescook@chromium.org (Kees Cook)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] Arm: mm: ftrace: Only set text back to ro after kernel has been marked ro
Date: Tue, 5 Dec 2017 11:35:59 -0800	[thread overview]
Message-ID: <CAGXu5jJb0PCSuC4DuOkh5-901iVLcmmPpn1G7UBq3-r9DaeMvw@mail.gmail.com> (raw)
In-Reply-To: <20171205133601.GX10595@n2100.armlinux.org.uk>

On Tue, Dec 5, 2017 at 5:36 AM, Russell King - ARM Linux
<linux@armlinux.org.uk> wrote:
> On Tue, Dec 05, 2017 at 01:30:11PM +0000, Phil Elwell wrote:
>> This was my initial explanation:
>>
>> 1. Data which is marked __ro_after_init is initially writeable.
>>
>> 2. The ro_perms data covers kernel text, read-only data and __ro_after_init data.
>>
>> 3. set_kernel_text_rw marks everything in ro_perms as writeable.
>>
>> 4. set_kernel_text_ro marks everything in ro_perms as read-only, including the __ro_after_init data.
>>
>> 5. Using the function tracing code involves code modification, resulting in calls to
>>    __ftrace_modify_code and set_kernel_text_ro.
>>
>> 6. Therefore if function tracing is enabled before kernel_init has completed then the __ro_after_init
>>    data is made read-only prematurely.
>
> My question still stands, but let me rephrase.  Do we need
> set_kernel_text_*() to touch the read-only data?

We don't _need_ to, but they're all contiguous, so the ro_perms array
used by set_kernel_text_*() is actually only a single entry:

static struct section_perm ro_perms[] = {
        /* Make kernel code and rodata RX (set RO). */
        {
                .name   = "text/rodata RO",
                .start  = (unsigned long)_stext,
                .end    = (unsigned long)__init_begin,
...


-Kees

-- 
Kees Cook
Pixel Security

  reply	other threads:[~2017-12-05 19:36 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 17:58 [PATCH] Arm: mm: ftrace: Only set text back to ro after kernel has been marked ro Steven Rostedt
2017-08-23 17:58 ` Steven Rostedt
2017-08-23 18:20 ` Matthias Reichl
2017-08-23 18:20   ` Matthias Reichl
2017-08-23 18:48 ` Kees Cook
2017-08-23 18:48   ` Kees Cook
2017-08-23 19:03   ` Steven Rostedt
2017-08-23 19:03     ` Steven Rostedt
2017-12-05 11:47     ` Matthias Reichl
2017-12-05 11:47       ` Matthias Reichl
2017-12-05 13:14       ` Russell King - ARM Linux
2017-12-05 13:14         ` Russell King - ARM Linux
2017-12-05 13:23         ` Matthias Reichl
2017-12-05 13:23           ` Matthias Reichl
2017-12-05 13:30           ` Phil Elwell
2017-12-05 13:30             ` Phil Elwell
2017-12-05 13:36             ` Russell King - ARM Linux
2017-12-05 13:36               ` Russell King - ARM Linux
2017-12-05 19:35               ` Kees Cook [this message]
2017-12-05 19:35                 ` Kees Cook
2017-12-05 20:09                 ` Russell King - ARM Linux
2017-12-05 20:09                   ` Russell King - ARM Linux
2017-12-05 20:14                   ` Kees Cook
2017-12-05 20:14                     ` Kees Cook
2018-06-29 14:47                     ` Matthias Reichl
2018-06-29 14:47                       ` Matthias Reichl
2018-06-29 15:16                       ` Steven Rostedt
2018-06-29 15:16                         ` Steven Rostedt
2018-06-29 17:29                         ` Matthias Reichl
2018-06-29 17:29                           ` Matthias Reichl

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=CAGXu5jJb0PCSuC4DuOkh5-901iVLcmmPpn1G7UBq3-r9DaeMvw@mail.gmail.com \
    --to=keescook@chromium.org \
    --cc=eric@anholt.net \
    --cc=hias@horus.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=phil@raspberrypi.org \
    --cc=rostedt@goodmis.org \
    --cc=stefan.wahren@i2se.com \
    /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.