aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorAndrey Ryabinin <a.ryabinin@samsung.com>2015-02-13 17:39:56 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-14 00:21:41 -0500
commit393f203f5fd54421fddb1e2a263f64d3876eeadb (patch)
treee78e96b38ecd36eec62325cc2cc21e8d79397bc1 /mm
parent3f15801cdc2379ca4bf507f48bffd788f9e508ae (diff)
x86_64: kasan: add interceptors for memset/memmove/memcpy functions
Recently instrumentation of builtin functions calls was removed from GCC 5.0. To check the memory accessed by such functions, userspace asan always uses interceptors for them. So now we should do this as well. This patch declares memset/memmove/memcpy as weak symbols. In mm/kasan/kasan.c we have our own implementation of those functions which checks memory before accessing it. Default memset/memmove/memcpy now now always have aliases with '__' prefix. For files that built without kasan instrumentation (e.g. mm/slub.c) original mem* replaced (via #define) with prefixed variants, cause we don't want to check memory accesses there. Signed-off-by: Andrey Ryabinin <a.ryabinin@samsung.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Konstantin Serebryany <kcc@google.com> Cc: Dmitry Chernenkov <dmitryc@google.com> Signed-off-by: Andrey Konovalov <adech.fo@gmail.com> Cc: Yuri Gribov <tetra2005@gmail.com> Cc: Konstantin Khlebnikov <koct9i@gmail.com> Cc: Sasha Levin <sasha.levin@oracle.com> Cc: Christoph Lameter <cl@linux.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/kasan/kasan.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
index dc83f070edb6..799c52b9826c 100644
--- a/mm/kasan/kasan.c
+++ b/mm/kasan/kasan.c
@@ -255,6 +255,35 @@ static __always_inline void check_memory_region(unsigned long addr,
255 kasan_report(addr, size, write, _RET_IP_); 255 kasan_report(addr, size, write, _RET_IP_);
256} 256}
257 257
258void __asan_loadN(unsigned long addr, size_t size);
259void __asan_storeN(unsigned long addr, size_t size);
260
261#undef memset
262void *memset(void *addr, int c, size_t len)
263{
264 __asan_storeN((unsigned long)addr, len);
265
266 return __memset(addr, c, len);
267}
268
269#undef memmove
270void *memmove(void *dest, const void *src, size_t len)
271{
272 __asan_loadN((unsigned long)src, len);
273 __asan_storeN((unsigned long)dest, len);
274
275 return __memmove(dest, src, len);
276}
277
278#undef memcpy
279void *memcpy(void *dest, const void *src, size_t len)
280{
281 __asan_loadN((unsigned long)src, len);
282 __asan_storeN((unsigned long)dest, len);
283
284 return __memcpy(dest, src, len);
285}
286
258void kasan_alloc_pages(struct page *page, unsigned int order) 287void kasan_alloc_pages(struct page *page, unsigned int order)
259{ 288{
260 if (likely(!PageHighMem(page))) 289 if (likely(!PageHighMem(page)))