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.12.11~7 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6423140ffcb1c5b005199bb2fa34621361ad538d;p=lttng-modules.git Introduce lttng_copy_from_user_check_nofault This code will be re-used by the bytecode interpreter, so move it out of the ring buffer. Signed-off-by: Mathieu Desnoyers Change-Id: I482adb5f619944285703425e278a70c601ce99b3 --- diff --git a/lib/ringbuffer/backend.h b/lib/ringbuffer/backend.h index bfadd94b..46dcf1cc 100644 --- a/lib/ringbuffer/backend.h +++ b/lib/ringbuffer/backend.h @@ -22,6 +22,7 @@ #include #include #include +#include /* Internal helpers */ #include @@ -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 */ diff --git a/probes/lttng-probe-user.h b/probes/lttng-probe-user.h index 0939a185..3251f7c6 100644 --- a/probes/lttng-probe-user.h +++ b/probes/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 */