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: <Z_-IwF4hrPUqVqwN@google.com>
Date: Wed, 16 Apr 2025 10:38:56 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: gregkh@...uxfoundation.org, rafael@...nel.org, david.m.ertman@...el.com, 
	ira.weiny@...el.com, ojeda@...nel.org, alex.gaynor@...il.com, 
	boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com, 
	benno.lossin@...ton.me, a.hindborg@...nel.org, tmgross@...ch.edu, 
	airlied@...il.com, acourbot@...dia.com, jhubbard@...dia.com, 
	linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v4 4/5] rust: auxiliary: add auxiliary registration

On Tue, Apr 15, 2025 at 02:50:02PM +0200, Danilo Krummrich wrote:
> On Tue, Apr 15, 2025 at 12:11:16PM +0000, Alice Ryhl wrote:
> > On Mon, Apr 14, 2025 at 03:18:07PM +0200, Danilo Krummrich wrote:
> > > +impl Registration {
> > > +    /// Create and register a new auxiliary device.
> > > +    pub fn new(parent: &device::Device, name: &CStr, id: u32, modname: &CStr) -> Result<Self> {
> > > +        let boxed = KBox::new(Opaque::<bindings::auxiliary_device>::zeroed(), GFP_KERNEL)?;
> > > +        let adev = boxed.get();
> > > +
> > > +        // SAFETY: It's safe to set the fields of `struct auxiliary_device` on initialization.
> > > +        unsafe {
> > > +            (*adev).dev.parent = parent.as_raw();
> > > +            (*adev).dev.release = Some(Device::release);
> > > +            (*adev).name = name.as_char_ptr();
> > > +            (*adev).id = id;
> > > +        }
> > > +
> > > +        // SAFETY: `adev` is guaranteed to be a valid pointer to a `struct auxiliary_device`,
> > > +        // which has not been initialized yet.
> > > +        unsafe { bindings::auxiliary_device_init(adev) };
> > > +
> > > +        // Now that `adev` is initialized, leak the `Box`; the corresponding memory will be freed
> > > +        // by `Device::release` when the last reference to the `struct auxiliary_device` is dropped.
> > > +        let _ = KBox::into_raw(boxed);
> > > +
> > > +        // SAFETY:
> > > +        // - `adev` is guaranteed to be a valid pointer to a `struct auxiliary_device`, which has
> > > +        //   been initialialized,
> > > +        // - `modname.as_char_ptr()` is a NULL terminated string.
> > > +        let ret = unsafe { bindings::__auxiliary_device_add(adev, modname.as_char_ptr()) };
> > > +        if ret != 0 {
> > > +            // SAFETY: `adev` is guaranteed to be a valid pointer to a `struct auxiliary_device`,
> > > +            // which has been initialialized.
> > > +            unsafe { bindings::auxiliary_device_uninit(adev) };
> > 
> > Does this error-path actually free the box?
> 
> Yes, auxiliary_device_uninit() calls put_device() on the underlying struct
> device, hence the release() callback is called at this point, which frees the
> Box.

In that case:
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ