Re: [kernel-hardening] [PATCH 4/6] Protectable Memory
From: Matthew Wilcox
Date: Fri Jan 26 2018 - 00:36:04 EST
On Wed, Jan 24, 2018 at 08:10:53PM +0100, Jann Horn wrote:
> I'm not entirely convinced by the approach of marking small parts of
> kernel memory as readonly for hardening.
It depends how significant the data stored in there are. For example,
storing function pointers in read-only memory provides significant
hardening.
> You're allocating with vmalloc(), which, as far as I know, establishes
> a second mapping in the vmalloc area for pages that are already mapped
> as RW through the physmap. AFAICS, later, when you're trying to make
> pages readonly, you're only changing the protections on the second
> mapping in the vmalloc area, therefore leaving the memory writable
> through the physmap. Is that correct? If so, please either document
> the reasoning why this is okay or change it.
Yes, this is still vulnerable to attacks through the physmap. That's also
true for marking structs as const. We should probably fix that at some
point, but at least they're not vulnerable to heap overruns by small
amounts ... you have to be able to overrun some other array by terabytes.
It's worth having a discussion about whether we want the pmalloc API
or whether we want a slab-based API. We can have a separate discussion
about an API to remove pages from the physmap.