Re: [PATCH v6 7/8] ARM: mm: allow non-text sections to be non-executable

From: Kees Cook
Date: Fri Sep 26 2014 - 13:07:51 EST


On Fri, Sep 26, 2014 at 9:59 AM, Russell King - ARM Linux
<linux@xxxxxxxxxxxxxxxx> wrote:
> On Fri, Sep 26, 2014 at 09:43:12AM -0700, Kees Cook wrote:
>> On Fri, Sep 26, 2014 at 4:42 AM, Russell King - ARM Linux
>> <linux@xxxxxxxxxxxxxxxx> wrote:
>> > On Thu, Sep 18, 2014 at 12:19:08PM -0700, Kees Cook wrote:
>> >> @@ -1373,13 +1373,24 @@ static void __init map_lowmem(void)
>> >> if (start >= end)
>> >> break;
>> >>
>> >> - if (end < kernel_x_start || start >= kernel_x_end) {
>> >> + if (end < kernel_x_start) {
>> >> map.pfn = __phys_to_pfn(start);
>> >> map.virtual = __phys_to_virt(start);
>> >> map.length = end - start;
>> >> map.type = MT_MEMORY_RWX;
>> >>
>> >> create_mapping(&map);
>> >> + } else if (start >= kernel_x_end) {
>> >> + map.pfn = __phys_to_pfn(start);
>> >> + map.virtual = __phys_to_virt(start);
>> >> + map.length = end - start;
>> >> +#ifdef CONFIG_ARM_KERNMEM_PERMS
>> >> + map.type = MT_MEMORY_RW;
>> >> +#else
>> >> + map.type = MT_MEMORY_RWX;
>> >> +#endif
>> >> +
>> >> + create_mapping(&map);
>> >
>> >
>> > I'm looking at this, and wondering two things. Firstly, why isn't it
>> > MT_MEMORY_RW in the first place. Secondly, why do you need to make
>> > this depend on CONFIG_ARM_KERNMEM_PERMS at all?
>> >
>> > I think the first is an oversight by me (and is a case which never came
>> > up in my testing, because most of my platforms don't have segmented
>> > memory layouts.)
>> >
>> > The second I think is not necessary - the memory region being considered
>> > is not part of the kernel at all, and so should not be executable in any
>> > shape or form.
>>
>> I'm happy to change this. My original intent was to make layout for
>> builds without CONFIG_ARM_KERNMEM_PERMS identical to what was there
>> before, so I took this step to make sure.
>>
>> I will drop the #ifdef and respin. Does the rest look ok? Shall I send
>> a pull request?
>
> I think all you need to is change that MT_MEMORY_RWX to be MT_MEMORY_RW.

Okay, I'll make that change.

> However, I think I would also like to see the kernel text being read-only
> as soon as possible - so maybe we should also have MT_MEMORY_RX, and
> have map_lowmem() use this for the kernel text when we want this level
> of protection?

Well, even if that's done we still need all the fixmap stuff happening
too since so many things like to change the kernel memory. :)

I'd like to start with this series, and then we can improve on it
going forward. This one seems to work and has been tested by a lot of
folks so far, so I'd hate to scrap a major portion and start over. I'd
like to get this landed, and then tweak it as needed. Does that sound
workable?

-Kees

--
Kees Cook
Chrome OS Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/