Introduce lttng_copy_from_user_check_nofault
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 5 Sep 2022 21:55:37 +0000 (17:55 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 29 Sep 2022 21:01:37 +0000 (17:01 -0400)
This code will be re-used by the bytecode interpreter, so move it out of
the ring buffer.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I482adb5f619944285703425e278a70c601ce99b3

lib/ringbuffer/backend.h
probes/lttng-probe-user.h

index bfadd94b99fbe40760e64a75a64dfb6b5fd1361d..46dcf1ccd9053443c4d00a743f5e1d19b2aa9ddb 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <wrapper/uaccess.h>
+#include <probes/lttng-probe-user.h>
 
 /* Internal helpers */
 #include <wrapper/ringbuffer/backend_internal.h>
@@ -440,14 +441,7 @@ unsigned long lib_ring_buffer_copy_from_user_check_nofault(void *dest,
                                                const void __user *src,
                                                unsigned long len)
 {
-       unsigned long ret;
-
-       if (!lttng_access_ok(VERIFY_READ, src, len))
-               return 1;
-       pagefault_disable();
-       ret = __copy_from_user_inatomic(dest, src, len);
-       pagefault_enable();
-       return ret;
+       return lttng_copy_from_user_check_nofault(dest, src, len);
 }
 
 #endif /* _LIB_RING_BUFFER_BACKEND_H */
index 0939a18535853d798abed3590d60a966deeafe3f..3251f7c673f0dcc42dfdb0b73f655c4c767879f7 100644 (file)
@@ -8,10 +8,33 @@
 #ifndef _LTTNG_PROBE_USER_H
 #define _LTTNG_PROBE_USER_H
 
+#include <wrapper/uaccess.h>
+
 /*
  * Calculate string length. Include final null terminating character if there is
  * one, or ends at first fault.
  */
 long lttng_strlen_user_inatomic(const char *addr);
 
+/*
+ * We use __copy_from_user_inatomic to copy userspace data after
+ * checking with access_ok() and disabling page faults.
+ *
+ * Return 0 if OK, nonzero on error.
+ */
+static inline
+unsigned long lttng_copy_from_user_check_nofault(void *dest,
+                                                const void __user *src,
+                                                unsigned long len)
+{
+       unsigned long ret;
+
+       if (!lttng_access_ok(VERIFY_READ, src, len))
+               return 1;
+       pagefault_disable();
+       ret = __copy_from_user_inatomic(dest, src, len);
+       pagefault_enable();
+       return ret;
+}
+
 #endif /* _LTTNG_PROBE_USER_H */
This page took 0.02701 seconds and 4 git commands to generate.