Introduce lttng_copy_from_user_check_nofault
[lttng-modules.git] / probes / lttng-probe-user.h
index e03e4b012d948076165c4d4aceac55caf4a1f09e..3251f7c673f0dcc42dfdb0b73f655c4c767879f7 100644 (file)
@@ -1,30 +1,40 @@
-#ifndef _LTTNG_PROBE_USER_H
-#define _LTTNG_PROBE_USER_H
-
-/*
+/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
+ *
  * lttng-probe-user.h
  *
  * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; only
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#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.023412 seconds and 4 git commands to generate.