Module uaccess

Module uaccess 

Source
Expand description

The uaccess module provides abstractions for interacting with user-space memory in a kernel context.

This module defines several types of user-space pointers that allow the kernel to access user-space data with various access modes, such as read-only, write-only, or read-write.

The types provided by this module include:

  • UserPtrRO: A one-time, read-only pointer to a user-space object of type T. It allows the kernel to read from user-space but does not permit writing to the data.
  • UserPtrWO: A one-time, write-only pointer to a user-space object of type T. It allows the kernel to write data to user-space but does not permit reading from it.
  • UserU8SliceRO: A one-time, read-only pointer to a slice of u8 in user-space. This type allows the kernel to read byte slices from user-space.
  • UserU8SliceWO: A one-time, write-only pointer to a slice of u8 in user-space. This type allows the kernel to write byte slices to user-space.
  • UserCString: A utility to handle C-style null-terminated strings from user-space. It provides methods for reading and converting the string into a String in the kernel.

These types use unsafe code to access memory directly. The user-space addresses must be valid and within bounds to prevent undefined behavior or security vulnerabilities. To ensure the memory safety, these types use Task::access_ok before accessing user-space memory. This function verifies that the provided memory range is valid and accessible, preventing potential security vulnerabilities and undefined behavior. If the memory is not accessible, the operation will fail gracefully instead of causing undefined behavior.

Structsยง

UserCString
A pointer to a null-terminated C-style string in user-space.
UserPtrRO
A one-time, read-only pointer to a user-space object of type T.
UserPtrWO
A one-time, write-only pointer to a user-space object of type T.
UserU8SliceRO
A one-time, read-only pointer to a slice of u8 in user-space.
UserU8SliceWO
A one-time, write-only pointer to a slice of u8 in user-space.