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>
Tue, 6 Sep 2022 22:14:03 +0000 (18:14 -0400)
This code will be re-used by the event notification capture code, so
move it out of the ring buffer.

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

include/lttng/probe-user.h
include/ringbuffer/backend.h

index 6b7f38dc98afdea2fa006fee0f8504c25c8c5e24..40b91461838f7675fbb0dacf0f1d0b147e58d10c 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 */
index c6e613c1d991101b80b332f5500eb58984080449..6a90161839c76903f28bb4c5a5e4eede152dfc2c 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <wrapper/uaccess.h>
+#include <lttng/probe-user.h>
 
 /* Internal helpers */
 #include <ringbuffer/backend_internal.h>
@@ -580,14 +581,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 */
This page took 0.027701 seconds and 4 git commands to generate.