lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aJyCOstIjMuvzLwH@google.com>
Date: Wed, 13 Aug 2025 12:16:58 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Alexander Viro <viro@...iv.linux.org.uk>, 
	Arnd Bergmann <arnd@...db.de>, Miguel Ojeda <ojeda@...nel.org>, Boqun Feng <boqun.feng@...il.com>, 
	Gary Guo <gary@...yguo.net>, 
	"Björn Roy Baron" <bjorn3_gh@...tonmail.com>, Andreas Hindborg <a.hindborg@...nel.org>, 
	Trevor Gross <tmgross@...ch.edu>, Matthew Maurer <mmaurer@...gle.com>, Lee Jones <lee@...nel.org>, 
	linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org, 
	Benno Lossin <lossin@...nel.org>, Christian Brauner <brauner@...nel.org>
Subject: Re: [PATCH v4 3/4] rust: miscdevice: Provide additional abstractions
 for iov_iter and kiocb structures

On Wed, Aug 13, 2025 at 01:39:12PM +0200, Danilo Krummrich wrote:
> On Wed Aug 13, 2025 at 10:27 AM CEST, Alice Ryhl wrote:
> > +pub struct Kiocb<'a, T> {
> > +    inner: NonNull<bindings::kiocb>,
> > +    _phantom: PhantomData<&'a T>,
> > +}
> > +
> > +impl<'a, T: ForeignOwnable> Kiocb<'a, T> {
> > +    /// Create a `Kiocb` from a raw pointer.
> > +    ///
> > +    /// # Safety
> > +    ///
> > +    /// The pointer must reference a valid `struct kiocb` for the duration of `'a`. The private
> > +    /// data of the file must be `T`.
> > +    pub unsafe fn from_raw(kiocb: *mut bindings::kiocb) -> Self {
> > +        Self {
> > +            // SAFETY: If a pointer is valid it is not null.
> > +            inner: unsafe { NonNull::new_unchecked(kiocb) },
> > +            _phantom: PhantomData,
> > +        }
> > +    }
> > +
> > +    /// Access the underlying `struct kiocb` directly.
> > +    pub fn as_raw(&self) -> *mut bindings::kiocb {
> > +        self.inner.as_ptr()
> > +    }
> > +
> > +    /// Get the filesystem or driver specific data associated with the file.
> > +    pub fn file(&self) -> <T as ForeignOwnable>::Borrowed<'a> {
> > +        // SAFETY: We have shared access to this kiocb and hence the underlying file, so we can
> > +        // read the file's private data.
> > +        let private = unsafe { (*(*self.as_raw()).ki_filp).private_data };
> > +        // SAFETY: The kiocb has shared access to the private data.
> > +        unsafe { <T as ForeignOwnable>::borrow(private) }
> > +    }
> > +
> > +    /// Gets the current value of `ki_pos`.
> > +    pub fn ki_pos(&self) -> i64 {
> > +        // SAFETY: We have shared access to the kiocb, so we can read its `ki_pos` field.
> > +        unsafe { (*self.as_raw()).ki_pos }
> > +    }
> > +
> > +    /// Gets a mutable reference to the `ki_pos` field.
> > +    pub fn ki_pos_mut(&mut self) -> &mut i64 {
> > +        // SAFETY: We have exclusive access to the kiocb, so we can write to `ki_pos`.
> > +        unsafe { &mut (*self.as_raw()).ki_pos }
> > +    }
> > +}
> 
> I think this should be a separate commit.

I can split it.

Alice

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ