From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by kanga.kvack.org (Postfix) with ESMTP id ABE9F6B0069 for ; Wed, 9 Jul 2014 07:36:48 -0400 (EDT) Received: by mail-pa0-f51.google.com with SMTP id hz1so9109492pad.38 for ; Wed, 09 Jul 2014 04:36:48 -0700 (PDT) Received: from mailout3.w1.samsung.com (mailout3.w1.samsung.com. [210.118.77.13]) by mx.google.com with ESMTPS id bj7si7234099pdb.410.2014.07.09.04.36.46 for (version=TLSv1 cipher=RC4-MD5 bits=128/128); Wed, 09 Jul 2014 04:36:46 -0700 (PDT) Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N8G00A150978060@mailout3.w1.samsung.com> for linux-mm@kvack.org; Wed, 09 Jul 2014 12:36:44 +0100 (BST) From: Andrey Ryabinin Subject: [RFC/PATCH RESEND -next 17/21] arm: add kasan hooks fort memcpy/memmove/memset functions Date: Wed, 09 Jul 2014 15:30:11 +0400 Message-id: <1404905415-9046-18-git-send-email-a.ryabinin@samsung.com> In-reply-to: <1404905415-9046-1-git-send-email-a.ryabinin@samsung.com> References: <1404905415-9046-1-git-send-email-a.ryabinin@samsung.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Konstantin Serebryany , Alexey Preobrazhensky , Andrey Konovalov , Yuri Gribov , Konstantin Khlebnikov , Sasha Levin , Michal Marek , Russell King , Thomas Gleixner , Ingo Molnar , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-kbuild@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, linux-mm@kvack.org, Andrey Ryabinin Since functions memset, memmove, memcpy are written in assembly, compiler can't instrument memory accesses inside them. This patch replaces these functions with our own instrumented functions (kasan_mem*) for CONFIG_KASAN = y In rare circumstances you may need to use the original functions, in such case put #undef KASAN_HOOKS before includes. Signed-off-by: Andrey Ryabinin --- arch/arm/include/asm/string.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arch/arm/include/asm/string.h b/arch/arm/include/asm/string.h index cf4f3aa..3cbe47f 100644 --- a/arch/arm/include/asm/string.h +++ b/arch/arm/include/asm/string.h @@ -38,4 +38,34 @@ extern void __memzero(void *ptr, __kernel_size_t n); (__p); \ }) + +#if defined(CONFIG_KASAN) && defined(KASAN_HOOKS) + +/* + * Since some of the following functions (memset, memmove, memcpy) + * are written in assembly, compiler can't instrument memory accesses + * inside them. + * + * To solve this issue we replace these functions with our own instrumented + * functions (kasan_mem*) + * + * In case if any of mem*() fucntions are written in C we use our instrumented + * functions for perfomance reasons. It's should be faster to check whole + * accessed memory range at once, then do a lot of checks at each memory access. + * + * In rare circumstances you may need to use the original functions, + * in such case #undef KASAN_HOOKS before includes. + */ +#undef memset + +void *kasan_memset(void *ptr, int val, size_t len); +void *kasan_memcpy(void *dst, const void *src, size_t len); +void *kasan_memmove(void *dst, const void *src, size_t len); + +#define memcpy(dst, src, len) kasan_memcpy((dst), (src), (len)) +#define memset(ptr, val, len) kasan_memset((ptr), (val), (len)) +#define memmove(dst, src, len) kasan_memmove((dst), (src), (len)) + +#endif /* CONFIG_KASAN && KASAN_HOOKS */ + #endif -- 1.8.5.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org