1 From 0039dbe9891cfdf2c0d04691f83c2f342993dfd7 Mon Sep 17 00:00:00 2001
2 From: Michael Jeanson <mjeanson@efficios.com>
3 Date: Wed, 9 Jan 2019 14:59:15 -0500
4 Subject: [PATCH 5/9] Fix: Remove 'type' argument from access_ok() function
9 commit 96d4f267e40f9509e8a66e2b39e8b95655617693
10 Author: Linus Torvalds <torvalds@linux-foundation.org>
11 Date: Thu Jan 3 18:57:57 2019 -0800
13 Remove 'type' argument from access_ok() function
15 Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
16 of the user address range verification function since we got rid of the
17 old racy i386-only code to walk page tables by hand.
19 It existed because the original 80386 would not honor the write protect
20 bit when in kernel mode, so you had to do COW by hand before doing any
21 user access. But we haven't supported that in a long time, and these
22 days the 'type' argument is a purely historical artifact.
24 A discussion about extending 'user_access_begin()' to do the range
25 checking resulted this patch, because there is no way we're going to
26 move the old VERIFY_xyz interface to that model. And it's best done at
27 the end of the merge window when I've done most of my merges, so let's
28 just get this done once and for all.
30 This patch was mostly done with a sed-script, with manual fix-ups for
31 the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
33 There were a couple of notable cases:
35 - csky still had the old "verify_area()" name as an alias.
37 - the iter_iov code had magical hardcoded knowledge of the actual
38 values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
41 - microblaze used the type argument for a debug printout
43 but other than those oddities this should be a total no-op patch.
45 I tried to fix up all architectures, did fairly extensive grepping for
46 access_ok() uses, and the changes are trivial, but I may have missed
47 something. Any missed conversion should be trivially fixable, though.
49 Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
50 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
52 Upstream-Status: backport https://github.com/lttng/lttng-modules/commit/0039dbe9891cfdf2c0d04691f83c2f342993dfd7
54 Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
56 lib/ringbuffer/backend.h | 8 ++++----
57 lib/ringbuffer/ring_buffer_iterator.c | 3 ++-
58 lttng-filter-interpreter.c | 4 ++--
59 probes/lttng-probe-user.c | 3 ++-
60 wrapper/uaccess.h | 28 +++++++++++++++++++++++++++
61 5 files changed, 38 insertions(+), 8 deletions(-)
62 create mode 100644 wrapper/uaccess.h
64 diff --git a/lib/ringbuffer/backend.h b/lib/ringbuffer/backend.h
65 index 0b75de8..3f8c108 100644
66 --- a/lib/ringbuffer/backend.h
67 +++ b/lib/ringbuffer/backend.h
69 #include <linux/list.h>
72 -#include <linux/uaccess.h>
73 +#include <wrapper/uaccess.h>
75 /* Internal helpers */
76 #include <wrapper/ringbuffer/backend_internal.h>
77 @@ -302,7 +302,7 @@ void lib_ring_buffer_copy_from_user_inatomic(const struct lib_ring_buffer_config
81 - if (unlikely(!access_ok(VERIFY_READ, src, len)))
82 + if (unlikely(!lttng_access_ok(VERIFY_READ, src, len)))
85 if (likely(pagecpy == len)) {
86 @@ -372,7 +372,7 @@ void lib_ring_buffer_strcpy_from_user_inatomic(const struct lib_ring_buffer_conf
90 - if (unlikely(!access_ok(VERIFY_READ, src, len)))
91 + if (unlikely(!lttng_access_ok(VERIFY_READ, src, len)))
94 if (likely(pagecpy == len)) {
95 @@ -462,7 +462,7 @@ unsigned long lib_ring_buffer_copy_from_user_check_nofault(void *dest,
99 - if (!access_ok(VERIFY_READ, src, len))
100 + if (!lttng_access_ok(VERIFY_READ, src, len))
104 diff --git a/lib/ringbuffer/ring_buffer_iterator.c b/lib/ringbuffer/ring_buffer_iterator.c
105 index 61eaa5b..9645946 100644
106 --- a/lib/ringbuffer/ring_buffer_iterator.c
107 +++ b/lib/ringbuffer/ring_buffer_iterator.c
110 #include <wrapper/ringbuffer/iterator.h>
111 #include <wrapper/file.h>
112 +#include <wrapper/uaccess.h>
113 #include <linux/jiffies.h>
114 #include <linux/delay.h>
115 #include <linux/module.h>
116 @@ -621,7 +622,7 @@ ssize_t channel_ring_buffer_file_read(struct file *filp,
120 - if (!access_ok(VERIFY_WRITE, user_buf, count))
121 + if (!lttng_access_ok(VERIFY_WRITE, user_buf, count))
124 /* Finish copy of previous record */
125 diff --git a/lttng-filter-interpreter.c b/lttng-filter-interpreter.c
126 index e131462..bee2918 100644
127 --- a/lttng-filter-interpreter.c
128 +++ b/lttng-filter-interpreter.c
133 -#include <linux/uaccess.h>
134 +#include <wrapper/uaccess.h>
135 #include <wrapper/frame.h>
136 #include <wrapper/types.h>
138 @@ -46,7 +46,7 @@ char get_char(struct estack_entry *reg, size_t offset)
141 /* Handle invalid access as end of string. */
142 - if (unlikely(!access_ok(VERIFY_READ,
143 + if (unlikely(!lttng_access_ok(VERIFY_READ,
144 reg->u.s.user_str + offset,
147 diff --git a/probes/lttng-probe-user.c b/probes/lttng-probe-user.c
148 index 099a66b..ed566dd 100644
149 --- a/probes/lttng-probe-user.c
150 +++ b/probes/lttng-probe-user.c
153 #include <linux/uaccess.h>
154 #include <linux/module.h>
155 +#include <wrapper/uaccess.h>
156 #include <probes/lttng-probe-user.h>
159 @@ -43,7 +44,7 @@ long lttng_strlen_user_inatomic(const char *addr)
163 - if (unlikely(!access_ok(VERIFY_READ,
164 + if (unlikely(!lttng_access_ok(VERIFY_READ,
165 (__force const char __user *) addr,
168 diff --git a/wrapper/uaccess.h b/wrapper/uaccess.h
170 index 0000000..c56427c
172 +++ b/wrapper/uaccess.h
174 +/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
176 + * wrapper/uaccess.h
178 + * wrapper around linux/uaccess.h.
180 + * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
183 +#ifndef _LTTNG_WRAPPER_UACCESS_H
184 +#define _LTTNG_WRAPPER_UACCESS_H
186 +#include <linux/uaccess.h>
187 +#include <lttng-kernel-version.h>
189 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0))
191 +#define VERIFY_READ 0
192 +#define VERIFY_WRITE 1
193 +#define lttng_access_ok(type, addr, size) access_ok(addr, size)
195 +#else /* LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0) */
197 +#define lttng_access_ok(type, addr, size) access_ok(type, addr, size)
199 +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0) */
201 +#endif /* _LTTNG_WRAPPER_UACCESS_H */