Add KASAN instrumentation for kcopy and copystr.
This commit is contained in:
parent
9a12fddfce
commit
50a5f274ac
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: subr_asan.c,v 1.7 2019/04/11 17:43:45 maxv Exp $ */
|
/* $NetBSD: subr_asan.c,v 1.8 2019/05/04 10:07:10 maxv Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 The NetBSD Foundation, Inc.
|
* Copyright (c) 2018 The NetBSD Foundation, Inc.
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.7 2019/04/11 17:43:45 maxv Exp $");
|
__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.8 2019/05/04 10:07:10 maxv Exp $");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/device.h>
|
#include <sys/device.h>
|
||||||
@ -479,17 +479,38 @@ kasan_strlen(const char *str)
|
|||||||
return (s - str);
|
return (s - str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef kcopy
|
||||||
|
#undef copystr
|
||||||
#undef copyinstr
|
#undef copyinstr
|
||||||
#undef copyoutstr
|
#undef copyoutstr
|
||||||
#undef copyin
|
#undef copyin
|
||||||
|
|
||||||
|
int kasan_kcopy(const void *, void *, size_t);
|
||||||
|
int kasan_copystr(const void *, void *, size_t, size_t *);
|
||||||
int kasan_copyinstr(const void *, void *, size_t, size_t *);
|
int kasan_copyinstr(const void *, void *, size_t, size_t *);
|
||||||
int kasan_copyoutstr(const void *, void *, size_t, size_t *);
|
int kasan_copyoutstr(const void *, void *, size_t, size_t *);
|
||||||
int kasan_copyin(const void *, void *, size_t);
|
int kasan_copyin(const void *, void *, size_t);
|
||||||
|
int kcopy(const void *, void *, size_t);
|
||||||
|
int copystr(const void *, void *, size_t, size_t *);
|
||||||
int copyinstr(const void *, void *, size_t, size_t *);
|
int copyinstr(const void *, void *, size_t, size_t *);
|
||||||
int copyoutstr(const void *, void *, size_t, size_t *);
|
int copyoutstr(const void *, void *, size_t, size_t *);
|
||||||
int copyin(const void *, void *, size_t);
|
int copyin(const void *, void *, size_t);
|
||||||
|
|
||||||
|
int
|
||||||
|
kasan_kcopy(const void *src, void *dst, size_t len)
|
||||||
|
{
|
||||||
|
kasan_shadow_check((unsigned long)src, len, false, __RET_ADDR);
|
||||||
|
kasan_shadow_check((unsigned long)dst, len, true, __RET_ADDR);
|
||||||
|
return kcopy(src, dst, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
kasan_copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done)
|
||||||
|
{
|
||||||
|
kasan_shadow_check((unsigned long)kdaddr, len, true, __RET_ADDR);
|
||||||
|
return copystr(kfaddr, kdaddr, len, done);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
kasan_copyin(const void *uaddr, void *kaddr, size_t len)
|
kasan_copyin(const void *uaddr, void *kaddr, size_t len)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: systm.h,v 1.283 2019/04/11 17:43:45 maxv Exp $ */
|
/* $NetBSD: systm.h,v 1.284 2019/05/04 10:07:11 maxv Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1982, 1988, 1991, 1993
|
* Copyright (c) 1982, 1988, 1991, 1993
|
||||||
@ -260,7 +260,12 @@ int format_bytes(char *, size_t, uint64_t);
|
|||||||
|
|
||||||
void tablefull(const char *, const char *);
|
void tablefull(const char *, const char *);
|
||||||
|
|
||||||
|
#if defined(_KERNEL) && defined(KASAN)
|
||||||
|
int kasan_kcopy(const void *, void *, size_t);
|
||||||
|
#define kcopy kasan_kcopy
|
||||||
|
#else
|
||||||
int kcopy(const void *, void *, size_t);
|
int kcopy(const void *, void *, size_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
#define bcopy(src, dst, len) memcpy((dst), (src), (len))
|
#define bcopy(src, dst, len) memcpy((dst), (src), (len))
|
||||||
@ -268,15 +273,17 @@ int kcopy(const void *, void *, size_t);
|
|||||||
#define bcmp(a, b, len) memcmp((a), (b), (len))
|
#define bcmp(a, b, len) memcmp((a), (b), (len))
|
||||||
#endif /* KERNEL */
|
#endif /* KERNEL */
|
||||||
|
|
||||||
int copystr(const void *, void *, size_t, size_t *);
|
|
||||||
#if defined(_KERNEL) && defined(KASAN)
|
#if defined(_KERNEL) && defined(KASAN)
|
||||||
|
int kasan_copystr(const void *, void *, size_t, size_t *);
|
||||||
int kasan_copyinstr(const void *, void *, size_t, size_t *);
|
int kasan_copyinstr(const void *, void *, size_t, size_t *);
|
||||||
int kasan_copyoutstr(const void *, void *, size_t, size_t *);
|
int kasan_copyoutstr(const void *, void *, size_t, size_t *);
|
||||||
int kasan_copyin(const void *, void *, size_t);
|
int kasan_copyin(const void *, void *, size_t);
|
||||||
|
#define copystr kasan_copystr
|
||||||
#define copyinstr kasan_copyinstr
|
#define copyinstr kasan_copyinstr
|
||||||
#define copyoutstr kasan_copyoutstr
|
#define copyoutstr kasan_copyoutstr
|
||||||
#define copyin kasan_copyin
|
#define copyin kasan_copyin
|
||||||
#else
|
#else
|
||||||
|
int copystr(const void *, void *, size_t, size_t *);
|
||||||
int copyinstr(const void *, void *, size_t, size_t *);
|
int copyinstr(const void *, void *, size_t, size_t *);
|
||||||
int copyoutstr(const void *, void *, size_t, size_t *);
|
int copyoutstr(const void *, void *, size_t, size_t *);
|
||||||
int copyin(const void *, void *, size_t);
|
int copyin(const void *, void *, size_t);
|
||||||
|
Loading…
Reference in New Issue
Block a user