Skip to content
Permalink
Browse files
instrumented.h: add KMSAN support
To avoid false positives, KMSAN needs to unpoison the data copied from
the userspace. To detect infoleaks - check the memory buffer passed to
copy_to_user().

Signed-off-by: Alexander Potapenko <glider@google.com>
  • Loading branch information
ramosian-glider authored and intel-lab-lkp committed Dec 14, 2021
1 parent 59055f3 commit 9faa0d15bc0e13d7f3d4737ac4b8b9f7d33bc641
Showing 1 changed file with 4 additions and 1 deletion.
@@ -2,14 +2,15 @@

/*
* This header provides generic wrappers for memory access instrumentation that
* the compiler cannot emit for: KASAN, KCSAN.
* the compiler cannot emit for: KASAN, KCSAN, KMSAN.
*/
#ifndef _LINUX_INSTRUMENTED_H
#define _LINUX_INSTRUMENTED_H

#include <linux/compiler.h>
#include <linux/kasan-checks.h>
#include <linux/kcsan-checks.h>
#include <linux/kmsan-checks.h>
#include <linux/types.h>

/**
@@ -117,6 +118,7 @@ instrument_copy_to_user(void __user *to, const void *from, unsigned long n)
{
kasan_check_read(from, n);
kcsan_check_read(from, n);
kmsan_copy_to_user(to, from, n, 0);
}

/**
@@ -151,6 +153,7 @@ static __always_inline void
instrument_copy_from_user_after(const void *to, const void __user *from,
unsigned long n, unsigned long left)
{
kmsan_unpoison_memory(to, n - left);
}

#endif /* _LINUX_INSTRUMENTED_H */

0 comments on commit 9faa0d1

Please sign in to comment.