Re: RFC v2: post-init-read-only protection for data allocated dynamically
From: Igor Stoppa
Date: Fri May 05 2017 - 08:09:41 EST
On 04/05/17 20:24, Dave Hansen wrote:
> On 05/04/2017 07:01 AM, Michal Hocko wrote:
>> Just to make my proposal more clear. I suggest the following workflow
>>
>> cache = kmem_cache_create(foo, object_size, ..., SLAB_SEAL);
>>
>> obj = kmem_cache_alloc(cache, gfp_mask);
>> init_obj(obj)
>> [more allocations]
>> kmem_cache_seal(cache);
>>
>> All slab pages belonging to the cache would get write protection. All
>> new allocations from this cache would go to new slab pages. Later
>> kmem_cache_seal will write protect only those new pages.
>
> Igor, what sizes of objects are you after here, mostly?
Theoretically, anything, since I have not really looked in details into
all the various subsystems, however, taking a more pragmatical approach
and referring to SE Linux and LSM Hooks, which were my initial target,
For SE Linux, I'm taking as example the policy db [1]:
The sizes are mostly small-ish: from 4-6 bytes to 16-32, overall.
There are some exceptions: the main policydb structure is way larger,
but it's not supposed to be instantiated repeatedly.
For LSM Hooks, the sublists in that hydra which goes under the name of
struct security_hook_heads, which are of type struct security_hook_list,
so a handful of bytes for the generic element [2].
> I ask because slub, at least, doesn't work at all for objects
>> PAGE_SIZE. It just punts those to the page allocator. But, you
> _could_ still use vmalloc() for those.
I would be surprised to find many objects that are larger than PAGE_SIZE
and qqualify for post-init-read-only protection, even if the page size
was only 4kB.
>From that perspective, I'm more concerned about avoiding taking a lot of
pages and leaving them mostly unused.
[1] security/selinux/ss/policydb.h
[2] include/linux/lsm_hooks.h