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: <D8A1Z043VPGR.2OBGSBH1ALUL6@proton.me>
Date: Fri, 07 Mar 2025 13:03:06 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Andreas Hindborg <a.hindborg@...nel.org>, Miguel Ojeda <ojeda@...nel.org>, Anna-Maria Behnsen <anna-maria@...utronix.de>, Frederic Weisbecker <frederic@...nel.org>, Thomas Gleixner <tglx@...utronix.de>, Danilo Krummrich <dakr@...nel.org>
Cc: Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, Lyude Paul <lyude@...hat.com>, Guangbo Cui <2407018371@...com>, Dirk Behme <dirk.behme@...il.com>, Daniel Almeida <daniel.almeida@...labora.com>, Tamir Duberstein <tamird@...il.com>, Markus Elfring <Markus.Elfring@....de>, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v10 03/13] rust: hrtimer: implement `HrTimerPointer` for `Arc`

On Fri Mar 7, 2025 at 11:11 AM CET, Andreas Hindborg wrote:
> +impl<T> HrTimerPointer for Arc<T>
> +where
> +    T: 'static,
> +    T: Send + Sync,
> +    T: HasHrTimer<T>,
> +    T: for<'a> HrTimerCallback<Pointer<'a> = Self>,
> +    Arc<T>: for<'a> RawHrTimerCallback<CallbackTarget<'a> = ArcBorrow<'a, T>>,

I don't understand why you need this bound here.

> +{
> +    type TimerHandle = ArcHrTimerHandle<T>;
> +
> +    fn start(self, expires: Ktime) -> ArcHrTimerHandle<T> {
> +        // SAFETY:
> +        //  - We keep `self` alive by wrapping it in a handle below.
> +        //  - Since we generate the pointer passed to `start` from a valid
> +        //    reference, it is a valid pointer.
> +        unsafe { T::start(Arc::as_ptr(&self), expires) };
> +        ArcHrTimerHandle { inner: self }
> +    }
> +}
> +
> +impl<T> RawHrTimerCallback for Arc<T>
> +where
> +    T: 'static,
> +    T: HasHrTimer<T>,
> +    T: for<'a> HrTimerCallback<Pointer<'a> = Self>,
> +{
> +    type CallbackTarget<'a> = ArcBorrow<'a, T>;
> +
> +    unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrtimer_restart {
> +        // `HrTimer` is `repr(C)`
> +        let timer_ptr = ptr.cast::<super::HrTimer<T>>();
> +
> +        // SAFETY: By C API contract `ptr` is the pointer we passed when
> +        // queuing the timer, so it is a `HrTimer<T>` embedded in a `T`.
> +        let data_ptr = unsafe { T::timer_container_of(timer_ptr) };
> +
> +        // SAFETY: `data_ptr` points to the `T` that was used to queue the
> +        // timer. This `T` is contained in an `Arc`.

You're not justifying all safety requirements of `ArcBorrow::from_raw`.

---
Cheers,
Benno

> +        let receiver = unsafe { ArcBorrow::from_raw(data_ptr) };
> +
> +        T::run(receiver);
> +
> +        bindings::hrtimer_restart_HRTIMER_NORESTART
> +    }
> +}
>
> --
> 2.47.0



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ