On Thu, Aug 29, 2019 at 05:03:54PM +0530, Viresh Kumar wrote: > From: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx> > > commit 64f8ebaf115bcddc4aaa902f981c57ba6506bc42 upstream. > > Memory access coded in an assembly won't be seen by KASAN as a compiler > can instrument only C code. Add kasan_check_[read,write]() API which is > going to be used to check a certain memory range. > > Link: http://lkml.kernel.org/r/1462538722-1574-3-git-send-email-aryabinin@xxxxxxxxxxxxx > Signed-off-by: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx> > Acked-by: Alexander Potapenko <glider@xxxxxxxxxx> > Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx> > Cc: Ingo Molnar <mingo@xxxxxxx> > Cc: "H. Peter Anvin" <hpa@xxxxxxxxx> > Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> > Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> > Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> > [ v4.4: Fixed MAINTAINERS conflict and added whole kasan entry. Drop 4th > argument to check_memory_region(). ] > Signed-off-by: Viresh Kumar <viresh.kumar@xxxxxxxxxx> Reviewed-by: Mark Rutland <mark.rutland@xxxxxxx> [v4.4 backport] Mark. > --- > MAINTAINERS | 14 ++++++++++++++ > include/linux/kasan-checks.h | 12 ++++++++++++ > mm/kasan/kasan.c | 12 ++++++++++++ > 3 files changed, 38 insertions(+) > create mode 100644 include/linux/kasan-checks.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index f4d4a5544dc1..2a8826732967 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -5982,6 +5982,20 @@ S: Maintained > F: Documentation/hwmon/k8temp > F: drivers/hwmon/k8temp.c > > +KASAN > +M: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx> > +R: Alexander Potapenko <glider@xxxxxxxxxx> > +R: Dmitry Vyukov <dvyukov@xxxxxxxxxx> > +L: kasan-dev@xxxxxxxxxxxxxxxx > +S: Maintained > +F: arch/*/include/asm/kasan.h > +F: arch/*/mm/kasan_init* > +F: Documentation/kasan.txt > +F: include/linux/kasan*.h > +F: lib/test_kasan.c > +F: mm/kasan/ > +F: scripts/Makefile.kasan > + > KCONFIG > M: "Yann E. MORIN" <yann.morin.1998@xxxxxxx> > L: linux-kbuild@xxxxxxxxxxxxxxx > diff --git a/include/linux/kasan-checks.h b/include/linux/kasan-checks.h > new file mode 100644 > index 000000000000..b7f8aced7870 > --- /dev/null > +++ b/include/linux/kasan-checks.h > @@ -0,0 +1,12 @@ > +#ifndef _LINUX_KASAN_CHECKS_H > +#define _LINUX_KASAN_CHECKS_H > + > +#ifdef CONFIG_KASAN > +void kasan_check_read(const void *p, unsigned int size); > +void kasan_check_write(const void *p, unsigned int size); > +#else > +static inline void kasan_check_read(const void *p, unsigned int size) { } > +static inline void kasan_check_write(const void *p, unsigned int size) { } > +#endif > + > +#endif > diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c > index b7397b459960..1cdcab0c976a 100644 > --- a/mm/kasan/kasan.c > +++ b/mm/kasan/kasan.c > @@ -274,6 +274,18 @@ static __always_inline void check_memory_region(unsigned long addr, > void __asan_loadN(unsigned long addr, size_t size); > void __asan_storeN(unsigned long addr, size_t size); > > +void kasan_check_read(const void *p, unsigned int size) > +{ > + check_memory_region((unsigned long)p, size, false); > +} > +EXPORT_SYMBOL(kasan_check_read); > + > +void kasan_check_write(const void *p, unsigned int size) > +{ > + check_memory_region((unsigned long)p, size, true); > +} > +EXPORT_SYMBOL(kasan_check_write); > + > #undef memset > void *memset(void *addr, int c, size_t len) > { > -- > 2.21.0.rc0.269.g1a574e7a288b >