Re: [PATCH v3 1/4] rust: uaccess: add userspace pointers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 18, 2024 at 7:59 PM Boqun Feng <boqun.feng@xxxxxxxxx> wrote:
>
> On Mon, Mar 11, 2024 at 10:47:13AM +0000, Alice Ryhl wrote:
> > +
> > +    /// Reads raw data from the user slice into a raw kernel buffer.
> > +    ///
> > +    /// Fails with `EFAULT` if the read encounters a page fault.
> > +    ///
> > +    /// # Safety
> > +    ///
> > +    /// The `out` pointer must be valid for writing `len` bytes.
> > +    pub unsafe fn read_raw(&mut self, out: *mut u8, len: usize) -> Result {
>
> I don't think we want to promote the pub usage of this unsafe function,
> right? We can provide a safe version:
>
>         pub fn read_slice(&mut self, to: &[u8]) -> Result
>
> and all users can just use the safe version (with the help of
> slice::from_raw_parts_mut() if necessary).

Personally, I think having the function be unsafe is plenty discouragement.

Also, this method would need an &mut [u8], which opens the can of
worms related to uninitialized memory. The _raw version of this method
is strictly more powerful.

I don't think I actually use it directly in Binder, so I can make it
private if you think that's important. It needs to be pub(crate),
though, since it is used in `Page`.

Alice





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux