On 04/04/2015 01:07 AM, Andrew Morton wrote: > On Fri, 03 Apr 2015 17:47:47 +0300 Andrey Ryabinin <a.ryabi...@samsung.com> > wrote: > >> Mempools keep allocated objects in reserved for situations >> when ordinary allocation may not be possible to satisfy. >> These objects shouldn't be accessed before they leave >> the pool. >> This patch poison elements when get into the pool >> and unpoison when they leave it. This will let KASan >> to detect use-after-free of mempool's elements. >> >> ... >> >> +static void kasan_poison_element(mempool_t *pool, void *element) >> +{ >> + if (pool->alloc == mempool_alloc_slab) >> + kasan_slab_free(pool->pool_data, element); >> + if (pool->alloc == mempool_kmalloc) >> + kasan_kfree(element); >> + if (pool->alloc == mempool_alloc_pages) >> + kasan_free_pages(element, (unsigned long)pool->pool_data); >> +} > > We recently discovered that mempool pages (from alloc_pages, not slab) > can be in highmem. But kasan apepars to handle highmem pages (by > baling out) so we should be OK with that. > > Can kasan be taught to use kmap_atomic() or is it more complicated than > that? It probably isn't worthwhile - highmem pages don'[t get used by the > kernel much and most bugs will be found using 64-bit testing anyway. >
kasan could only tell whether it's ok to use some virtual address or not. So it can't be used for catching use after free of highmem page. If highmem page was kmapped at some address than it's ok to dereference that address. However, kasan can be used to unpoison/poison kmapped/kunmapped addresses to find use-after-kunmap bugs. AFAIK kunmap has some sort of lazy unmap logic and kunmaped page might be still accessible for some time. Another idea - poison lowmem pages if they were allocated with __GFP_HIGHMEM, unpoison them only on kmap, and poison back on kunmap. Generally such pages shouldn't be accessed without mapping them first. However it might be some false-positives. User could check if page is in lowmem and don't use kmap in that case. It probably isn't worthwhile as well - 32bit testing will find these bugs without kasan. ------------------------------------------------------------------------------ BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF _______________________________________________ Jfs-discussion mailing list Jfs-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jfs-discussion