[PATCH 4/5] iov_iter: Use generic instrumented.h

From: Marco Elver
Date: Mon Jan 20 2020 - 09:19:55 EST


This replaces the kasan instrumentation with generic instrumentation,
implicitly adding KCSAN instrumentation support.

For KASAN no functional change is intended.

Suggested-by: Arnd Bergmann <arnd@xxxxxxxx>
Signed-off-by: Marco Elver <elver@xxxxxxxxxx>
---
lib/iov_iter.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index fb29c02c6a3c..f06f6f1dd686 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -8,6 +8,7 @@
#include <linux/splice.h>
#include <net/checksum.h>
#include <linux/scatterlist.h>
+#include <linux/instrumented.h>

#define PIPE_PARANOIA /* for now */

@@ -137,20 +138,26 @@

static int copyout(void __user *to, const void *from, size_t n)
{
+ size_t res = n;
+
if (access_ok(to, n)) {
- kasan_check_read(from, n);
- n = raw_copy_to_user(to, from, n);
+ instrument_copy_to_user_pre(from, n);
+ res = raw_copy_to_user(to, from, n);
+ instrument_copy_to_user_post(from, n, res);
}
- return n;
+ return res;
}

static int copyin(void *to, const void __user *from, size_t n)
{
+ size_t res = n;
+
if (access_ok(from, n)) {
- kasan_check_write(to, n);
- n = raw_copy_from_user(to, from, n);
+ instrument_copy_from_user_pre(to, n);
+ res = raw_copy_from_user(to, from, n);
+ instrument_copy_from_user_post(to, n, res);
}
- return n;
+ return res;
}

static size_t copy_page_to_iter_iovec(struct page *page, size_t offset, size_t bytes,
@@ -638,11 +645,14 @@ EXPORT_SYMBOL(_copy_to_iter);
#ifdef CONFIG_ARCH_HAS_UACCESS_MCSAFE
static int copyout_mcsafe(void __user *to, const void *from, size_t n)
{
+ size_t res = n;
+
if (access_ok(to, n)) {
- kasan_check_read(from, n);
- n = copy_to_user_mcsafe((__force void *) to, from, n);
+ instrument_copy_to_user_pre(from, n);
+ res = copy_to_user_mcsafe((__force void *) to, from, n);
+ instrument_copy_to_user_post(from, n, res);
}
- return n;
+ return res;
}

static unsigned long memcpy_mcsafe_to_page(struct page *page, size_t offset,
--
2.25.0.341.g760bfbb309-goog