Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752898AbbDFLgR (ORCPT ); Mon, 6 Apr 2015 07:36:17 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:62758 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751829AbbDFLgM (ORCPT ); Mon, 6 Apr 2015 07:36:12 -0400 X-AuditID: cbfec7f5-b7f1e6d00000617c-dc-55226efc3f2c Message-id: <55226FA7.30505@samsung.com> Date: Mon, 06 Apr 2015 14:36:07 +0300 From: Andrey Ryabinin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-version: 1.0 To: Andrew Morton Cc: David Rientjes , Dave Kleikamp , Christoph Hellwig , Sebastian Ott , Mikulas Patocka , Catalin Marinas , LKML , linux-mm@kvack.org, jfs-discussion@lists.sourceforge.net, Dmitry Chernenkov , Dmitry Vyukov , Alexander Potapenko Subject: Re: [PATCH] mm, mempool: kasan: poison mempool elements References: <1428072467-21668-1-git-send-email-a.ryabinin@samsung.com> <20150403150719.b2197f71260fee25434e49fc@linux-foundation.org> In-reply-to: <20150403150719.b2197f71260fee25434e49fc@linux-foundation.org> Content-type: text/plain; charset=windows-1252 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGLMWRmVeSWpSXmKPExsVy+t/xa7p/8pRCDV6/UrWYs34Nm8X7ZT2M FgsnxVpMeNjGbtH+cS+zxcrVR5ksLn5sZbK4vGsOm8W9Nf9ZLSZ2XGWyaFuykcniVNdhRovb d34wO/B6rJm3htFj56y77B4LNpV6bFrVyeax6dMkdo8TM36zeDw4tJnFY/eCz0weu282sHm8 33eVzePzJrkA7igum5TUnMyy1CJ9uwSujKU/dzEXvBSo2Haij7mB8Q5vFyMHh4SAicSrtUJd jJxAppjEhXvr2boYuTiEBJYyShxt/wHlNDNJPP6/mwmkildAQ+J03wwwm0VAVWLmjFfMIDab gJ7Ev1nb2UCGigpESNy+zAlRLijxY/I9FhBbREBXYtXzXcwgM5kFTjBLLDl7H6xXWMBBoqP7 CjPEsnZGiZ6pi9hAEpwC3hLPTp1jBxnKDLTg/kUtkDCzgLzE5jVvmScwCsxCsmMWQtUsJFUL GJlXMYqmliYXFCel5xrpFSfmFpfmpesl5+duYoTE1dcdjEuPWR1iFOBgVOLh/fBYMVSINbGs uDL3EKMEB7OSCO9hYFQK8aYkVlalFuXHF5XmpBYfYmTi4JRqYLymPPnmu+UL5MNuGdTsMLs5 +eH56Vda2H3WdnCt8mZQjxQOEJpaqrJ37tf8mOg53CEzePntP6atufs8Wd70ziRV9tJNOyTT /8b6BLyY91Ei+VBqmR5v4VXxlpWuJR0HZs/zeqPOyy+Wdcvi90XnFzteqVd8q9P9c1YsSPp+ wLpvpg+erXv4KEWJpTgj0VCLuag4EQBbT68giQIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2356 Lines: 47 On 04/04/2015 01:07 AM, Andrew Morton wrote: > On Fri, 03 Apr 2015 17:47:47 +0300 Andrey Ryabinin 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. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/