From: Mathieu Desnoyers Date: Mon, 5 Sep 2022 21:55:37 +0000 (-0400) Subject: Introduce lttng_copy_from_user_check_nofault X-Git-Tag: v2.13.6~14 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d169b253f6d6fe6f37aa7cb81f0e8b211b8468b4;p=lttng-modules.git Introduce lttng_copy_from_user_check_nofault 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 Change-Id: I482adb5f619944285703425e278a70c601ce99b3 --- diff --git a/include/lttng/probe-user.h b/include/lttng/probe-user.h index 6b7f38dc..40b91461 100644 --- a/include/lttng/probe-user.h +++ b/include/lttng/probe-user.h @@ -8,10 +8,33 @@ #ifndef _LTTNG_PROBE_USER_H #define _LTTNG_PROBE_USER_H +#include + /* * 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 */ diff --git a/include/ringbuffer/backend.h b/include/ringbuffer/backend.h index c6e613c1..6a901618 100644 --- a/include/ringbuffer/backend.h +++ b/include/ringbuffer/backend.h @@ -22,6 +22,7 @@ #include #include #include +#include /* Internal helpers */ #include @@ -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 */