Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1413401 > unrolled thread

Adding module support for __ro_after_init

Started byKees Cook <keescook@google.com>
First post2016-06-03 20:50 +0200
Last post2016-06-07 18:00 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  Adding module support for __ro_after_init Kees Cook <keescook@google.com> - 2016-06-03 20:50 +0200
    Re: Adding module support for __ro_after_init Rusty Russell <rusty@rustcorp.com.au> - 2016-06-05 07:20 +0200
      Re: Adding module support for __ro_after_init Jessica Yu <jeyu@redhat.com> - 2016-06-07 08:50 +0200
        Re: Adding module support for __ro_after_init Kees Cook <keescook@google.com> - 2016-06-07 18:00 +0200

#1413401 — Adding module support for __ro_after_init

FromKees Cook <keescook@google.com>
Date2016-06-03 20:50 +0200
SubjectAdding module support for __ro_after_init
Message-ID<rG2kq-6QU-33@gated-at.bofh.it>
Hi Rusty,

I'd love to get your thoughts on the best way to support
__ro_after_init markings for modules. Are the r/o markings done after
module __init runs? If so, this should make things easy, and then we
just need to move .data..ro_after_init into .rodata at link time. If
not, then we'd need to explicitly make this section read-only after
_init.

Thanks!

-Kees

-- 
Kees Cook
Chrome OS & Brillo Security

[toc] | [next] | [standalone]


#1413921

FromRusty Russell <rusty@rustcorp.com.au>
Date2016-06-05 07:20 +0200
Message-ID<rGyDD-2CX-5@gated-at.bofh.it>
In reply to#1413401
Kees Cook <keescook@google.com> writes:
> Hi Rusty,
>
> I'd love to get your thoughts on the best way to support
> __ro_after_init markings for modules. Are the r/o markings done after
> module __init runs? If so, this should make things easy, and then we
> just need to move .data..ro_after_init into .rodata at link time. If
> not, then we'd need to explicitly make this section read-only after
> _init.

As you might expect, the sections are made read-only before anything
runs.  We'll need to do the latter, which means it needs to be
page-aligned.  (Well we could put it in the same page as .rodata, and
just not protect that fully until after init).

Jessica might have more thoughts...
Rusty.

[toc] | [prev] | [next] | [standalone]


#1415751

FromJessica Yu <jeyu@redhat.com>
Date2016-06-07 08:50 +0200
Message-ID<rHiZP-7Do-1@gated-at.bofh.it>
In reply to#1413921
+++ Rusty Russell [05/06/16 14:39 +0930]:
>Kees Cook <keescook@google.com> writes:
>> Hi Rusty,
>>
>> I'd love to get your thoughts on the best way to support
>> __ro_after_init markings for modules. Are the r/o markings done after
>> module __init runs? If so, this should make things easy, and then we
>> just need to move .data..ro_after_init into .rodata at link time. If
>> not, then we'd need to explicitly make this section read-only after
>> _init.
>
>As you might expect, the sections are made read-only before anything
>runs.  We'll need to do the latter, which means it needs to be
>page-aligned.  (Well we could put it in the same page as .rodata, and
>just not protect that fully until after init).

Hi Rusty, Kees, :-)

Right, RO protection is enabled in load_module() before module __init gets to
run. So I guess there are two ways to go about this: either (1) keep
__ro_after_init with the rest of rodata and toggle RO protection after __init
runs, but I think we'd probably want to keep this protection before anything
executes. Or (2) modify layout_sections() in the module loader to place
.data..ro_after_init data in its own set of page(s) so that we can toggle RO
on/off independently of the other module sections, and set them to RO only
after module init runs.
So perhaps the modified module memory layout might look like..
   [text] [rodata] [ro after init] [writable data]

I don't think (2) should be hard to implement in the module loader (well,
at first glance :-), maybe I'm missing something), but I could go ahead and
give a patch a shot.

Jessica

[toc] | [prev] | [next] | [standalone]


#1416344

FromKees Cook <keescook@google.com>
Date2016-06-07 18:00 +0200
Message-ID<rHrA6-4yQ-27@gated-at.bofh.it>
In reply to#1415751
On Mon, Jun 6, 2016 at 11:42 PM, Jessica Yu <jeyu@redhat.com> wrote:
> +++ Rusty Russell [05/06/16 14:39 +0930]:
>>
>> Kees Cook <keescook@google.com> writes:
>>>
>>> Hi Rusty,
>>>
>>> I'd love to get your thoughts on the best way to support
>>> __ro_after_init markings for modules. Are the r/o markings done after
>>> module __init runs? If so, this should make things easy, and then we
>>> just need to move .data..ro_after_init into .rodata at link time. If
>>> not, then we'd need to explicitly make this section read-only after
>>> _init.
>>
>>
>> As you might expect, the sections are made read-only before anything
>> runs.  We'll need to do the latter, which means it needs to be
>> page-aligned.  (Well we could put it in the same page as .rodata, and
>> just not protect that fully until after init).
>
>
> Hi Rusty, Kees, :-)
>
> Right, RO protection is enabled in load_module() before module __init gets
> to
> run. So I guess there are two ways to go about this: either (1) keep
> __ro_after_init with the rest of rodata and toggle RO protection after
> __init
> runs, but I think we'd probably want to keep this protection before anything
> executes. Or (2) modify layout_sections() in the module loader to place
> .data..ro_after_init data in its own set of page(s) so that we can toggle RO
> on/off independently of the other module sections, and set them to RO only
> after module init runs.
> So perhaps the modified module memory layout might look like..
>   [text] [rodata] [ro after init] [writable data]
>
> I don't think (2) should be hard to implement in the module loader (well,
> at first glance :-), maybe I'm missing something), but I could go ahead and
> give a patch a shot.

I would agree that "2" sound best. I'm happy to help review and test
any patches. And after having looked at this myself, I'm curious to
see the solution since I couldn't figure out how the layout code
worked. :)

-Kees

-- 
Kees Cook
Chrome OS & Brillo Security

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web