Re: RFC v2: post-init-read-only protection for data allocated dynamically

From: Dave Hansen
Date: Thu May 04 2017 - 13:25:11 EST


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?

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.