@@ -9,9 +9,6 @@ use alloc::vec::Vec;
9
9
use core:: mem:: { size_of, MaybeUninit } ;
10
10
11
11
extern "C" {
12
- fn rust_helper_access_ok ( addr : * const c_types:: c_void , len : c_types:: c_ulong )
13
- -> c_types:: c_int ;
14
-
15
12
fn rust_helper_copy_from_user (
16
13
to : * mut c_types:: c_void ,
17
14
from : * const c_types:: c_void ,
@@ -69,42 +66,27 @@ unsafe impl ReadableFromBytes for isize {}
69
66
/// obtaining multiple readers on a given [`UserSlicePtr`], and the readers
70
67
/// only permitting forward reads.
71
68
///
72
- /// Constructing a [`UserSlicePtr`] only checks that the range is in valid
73
- /// userspace memory, and does not depend on the current process (and
74
- /// can safely be constructed inside a kernel thread with no current
75
- /// userspace process). Reads and writes wrap the kernel APIs
76
- /// `copy_from_user` and `copy_to_user`, and check the memory map of the
77
- /// current process .
69
+ /// Constructing a [`UserSlicePtr`] performs no checks on the provided
70
+ /// address and length, it can safely be constructed inside a kernel thread
71
+ /// with no current userspace process. Reads and writes wrap the kernel APIs
72
+ /// `copy_from_user` and `copy_to_user`, which check the memory map of the
73
+ /// current process and enforce that the address range is within the user
74
+ /// range (no additional calls to `access_ok` are needed) .
78
75
///
79
76
/// [`std::io`]: https://doc.rust-lang.org/std/io/index.html
80
77
pub struct UserSlicePtr ( * mut c_types:: c_void , usize ) ;
81
78
82
79
impl UserSlicePtr {
83
80
/// Constructs a user slice from a raw pointer and a length in bytes.
84
81
///
85
- /// Checks that the provided range is within the legal area for
86
- /// userspace memory, using `access_ok` (e.g., on i386, the range
87
- /// must be within the first 3 GiB), but does not check that
88
- /// the actual pages are mapped in the current process with
89
- /// appropriate permissions. Those checks are handled in the read
90
- /// and write methods.
91
- ///
92
82
/// # Safety
93
83
///
94
- /// This is `unsafe` because if it is called within `set_fs(KERNEL_DS)`
95
- /// context then `access_ok` will not do anything. As a result the only
96
- /// place you can safely use this is with a `__user` pointer that was
97
- /// provided by the kernel.
98
- ///
99
- /// Callers must also be careful to avoid time-of-check-time-of-use
84
+ /// Callers must be careful to avoid time-of-check-time-of-use
100
85
/// (TOCTOU) issues. The simplest way is to create a single instance of
101
86
/// [`UserSlicePtr`] per user memory block as it reads each byte at
102
87
/// most once.
103
- pub unsafe fn new ( ptr : * mut c_types:: c_void , length : usize ) -> KernelResult < UserSlicePtr > {
104
- if rust_helper_access_ok ( ptr, length as c_types:: c_ulong ) == 0 {
105
- return Err ( error:: Error :: EFAULT ) ;
106
- }
107
- Ok ( UserSlicePtr ( ptr, length) )
88
+ pub unsafe fn new ( ptr : * mut c_types:: c_void , length : usize ) -> Self {
89
+ UserSlicePtr ( ptr, length)
108
90
}
109
91
110
92
/// Reads the entirety of the user slice.
0 commit comments