Changeset View
Changeset View
Standalone View
Standalone View
share/man/man9/copy.9
| Show All 26 Lines | |||||||||||
| .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||||||||||
| .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||||||||||
| .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||||||||||
| .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||||||||||
| .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||||||||
| .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||||||||
| .\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||||||||
| .\" | .\" | ||||||||||
| .Dd May 11, 2020 | .Dd June 29, 2026 | ||||||||||
| .Dt COPY 9 | .Dt COPY 9 | ||||||||||
| .Os | .Os | ||||||||||
| .Sh NAME | .Sh NAME | ||||||||||
| .Nm copy , | .Nm copy , | ||||||||||
| .Nm copyin , | .Nm copyin , | ||||||||||
| .Nm copyin_nofault , | .Nm copyin_nofault , | ||||||||||
| .Nm copyinptr , | |||||||||||
| .Nm copyinptr_nofault , | |||||||||||
| .Nm copyout , | .Nm copyout , | ||||||||||
| .Nm copyout_nofault , | .Nm copyout_nofault , | ||||||||||
| .Nm copyoutptr , | |||||||||||
| .Nm copyoutptr_nofault , | |||||||||||
| .Nm copystr , | .Nm copystr , | ||||||||||
| .Nm copyinstr | .Nm copyinstr | ||||||||||
| .Nd heterogeneous address space copy functions | .Nd heterogeneous address space copy functions | ||||||||||
| .Sh SYNOPSIS | .Sh SYNOPSIS | ||||||||||
| .In sys/types.h | .In sys/types.h | ||||||||||
| .In sys/systm.h | .In sys/systm.h | ||||||||||
| .Ft int | .Ft int | ||||||||||
| .Fn copyin "const void *uaddr" "void *kaddr" "size_t len" | .Fn copyin "const void *uaddr" "void *kaddr" "size_t len" | ||||||||||
| .Ft int | .Ft int | ||||||||||
| .Fn copyin_nofault "const void *uaddr" "void *kaddr" "size_t len" | .Fn copyin_nofault "const void *uaddr" "void *kaddr" "size_t len" | ||||||||||
| .Ft int | .Ft int | ||||||||||
| .Fn copyinptr "const void *uaddr" "void *kaddr" "size_t len" | |||||||||||
| .Ft int | |||||||||||
| .Fn copyinptr_nofault "const void *uaddr" "void *kaddr" "size_t len" | |||||||||||
| .Ft int | |||||||||||
| .Fn copyout "const void *kaddr" "void *uaddr" "size_t len" | .Fn copyout "const void *kaddr" "void *uaddr" "size_t len" | ||||||||||
| .Ft int | .Ft int | ||||||||||
| .Fn copyout_nofault "const void *kaddr" "void *uaddr" "size_t len" | .Fn copyout_nofault "const void *kaddr" "void *uaddr" "size_t len" | ||||||||||
| .Ft int | |||||||||||
| .Fn copyoutptr "const void *kaddr" "void *uaddr" "size_t len" | |||||||||||
| .Ft int | |||||||||||
| .Fn copyoutptr_nofault "const void *kaddr" "void *uaddr" "size_t len" | |||||||||||
| .Ft int __deprecated | .Ft int __deprecated | ||||||||||
| .Fn copystr "const void *kfaddr" "void *kdaddr" "size_t len" "size_t *done" | .Fn copystr "const void *kfaddr" "void *kdaddr" "size_t len" "size_t *done" | ||||||||||
| .Ft int | .Ft int | ||||||||||
| .Fn copyinstr "const void *uaddr" "void *kaddr" "size_t len" "size_t *done" | .Fn copyinstr "const void *uaddr" "void *kaddr" "size_t len" "size_t *done" | ||||||||||
| .Sh DESCRIPTION | .Sh DESCRIPTION | ||||||||||
| The | The | ||||||||||
| .Nm | .Nm | ||||||||||
| functions are designed to copy contiguous data from one address space | functions are designed to copy contiguous data from one address space | ||||||||||
| Show All 10 Lines | |||||||||||
| .Fn copyin | .Fn copyin | ||||||||||
| and | and | ||||||||||
| .Fn copyin_nofault | .Fn copyin_nofault | ||||||||||
| functions copy | functions copy | ||||||||||
| .Fa len | .Fa len | ||||||||||
| bytes of data from the user-space address | bytes of data from the user-space address | ||||||||||
| .Fa uaddr | .Fa uaddr | ||||||||||
| to the kernel-space address | to the kernel-space address | ||||||||||
| .Fa kaddr . | .Fa kaddr | ||||||||||
| without preserving the provenance of pointers in the copied object | |||||||||||
| .Pq see Xr memory_model 7 for further information . | |||||||||||
| The | |||||||||||
| .Fn copyinptr | |||||||||||
| and | |||||||||||
| .Fn copyinptr_nofault | |||||||||||
markj: You might clarify here that you're talking about user pointers. It's always a bug to copy out… | |||||||||||
Done Inline Actions
I've mentioned they are pointers to user-space, though the current implementations don't know the difference. @alfredo.mazzinghi_cl.cam.ac.uk does have patches to use the local-global mechanism to prevent kernel pointer from leaking to userspace so documenting this intent does seem like the right thing to do. brooks: > You might clarify here that you're talking about user pointers. It's always a bug to copy out… | |||||||||||
Done Inline Actions
markj: | |||||||||||
| functions do the same, | |||||||||||
| but preserves the provenance of copied pointers to user-space. | |||||||||||
| .Pp | .Pp | ||||||||||
| The | The | ||||||||||
| .Fn copyout | .Fn copyout | ||||||||||
| and | and | ||||||||||
| .Fn copyout_nofault | .Fn copyout_nofault | ||||||||||
| functions copy | functions copy | ||||||||||
| .Fa len | .Fa len | ||||||||||
| bytes of data from the kernel-space address | bytes of data from the kernel-space address | ||||||||||
| .Fa kaddr | .Fa kaddr | ||||||||||
| to the user-space address | to the user-space address | ||||||||||
| .Fa uaddr . | .Fa uaddr | ||||||||||
| without preserving the provenance of pointers in the copied object. | |||||||||||
Done Inline Actions
markj: | |||||||||||
| The | |||||||||||
| .Fn copyoutptr | |||||||||||
| and | |||||||||||
| .Fn copyoutptr_nofault | |||||||||||
| functions do the same, | |||||||||||
| but preserves the provenance of copied pointers to user-space. | |||||||||||
| .Pp | .Pp | ||||||||||
| The | The | ||||||||||
| .Fn copyin_nofault | .Fn copyin_nofault , | ||||||||||
| .Fn copyinptr_nofault , | |||||||||||
| .Fn copyout_nofault , | |||||||||||
| and | and | ||||||||||
| .Fn copyout_nofault | .Fn copyoutptr_nofault | ||||||||||
| functions require that the kernel-space and user-space data be | functions require that the kernel-space and user-space data be | ||||||||||
| accessible without incurring a page fault. | accessible without incurring a page fault. | ||||||||||
| The source and destination addresses must be physically mapped for | The source and destination addresses must be physically mapped for | ||||||||||
| read and write access, respectively, and neither the source nor | read and write access, respectively, and neither the source nor | ||||||||||
| destination addresses may be pageable. | destination addresses may be pageable. | ||||||||||
| .Pp | |||||||||||
| The | |||||||||||
| .Fn copyinptr , | |||||||||||
| .Fn copyinptr_nofault , | |||||||||||
| .Fn copyoutptr , | |||||||||||
| and | |||||||||||
| .Fn copyoutptr_nofault | |||||||||||
| functions must be used when copying data which may contain pointers, | |||||||||||
| but they should only be used when necessary to limit the number of | |||||||||||
| code paths that could leak pointers between address spaces. | |||||||||||
| .Pp | .Pp | ||||||||||
| The | The | ||||||||||
| .Fn copystr | .Fn copystr | ||||||||||
| function copies a NUL-terminated string, at most | function copies a NUL-terminated string, at most | ||||||||||
| .Fa len | .Fa len | ||||||||||
| bytes long, from kernel-space address | bytes long, from kernel-space address | ||||||||||
| .Fa kfaddr | .Fa kfaddr | ||||||||||
| to kernel-space address | to kernel-space address | ||||||||||
| ▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines | |||||||||||
You might clarify here that you're talking about user pointers. It's always a bug to copy out kernel capabilities.