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: <87ikok3or8.fsf@kernel.org>
Date: Fri, 07 Mar 2025 15:21:31 +0100
From: Andreas Hindborg <a.hindborg@...nel.org>
To: "Benno Lossin" <benno.lossin@...ton.me>
Cc: "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>,  "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 07/13] rust: hrtimer: implement
 `UnsafeHrTimerPointer` for `Pin<&T>`

"Benno Lossin" <benno.lossin@...ton.me> writes:

> On Fri Mar 7, 2025 at 2:37 PM CET, Andreas Hindborg wrote:
>> "Benno Lossin" <benno.lossin@...ton.me> writes:
>>> On Fri Mar 7, 2025 at 11:11 AM CET, Andreas Hindborg wrote:
>>>> +impl<'a, T> RawHrTimerCallback for Pin<&'a T>
>>>> +where
>>>> +    T: HasHrTimer<T>,
>>>> +    T: HrTimerCallback<Pointer<'a> = Self>,
>>>> +{
>>>> +    type CallbackTarget<'b> = Self;
>>>> +
>>>> +    unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrtimer_restart {
>>>> +        // `HrTimer` is `repr(C)`
>>>> +        let timer_ptr = ptr as *mut HrTimer<T>;
>>>> +
>>>> +        // SAFETY: By the safety requirement of this function, `timer_ptr`
>>>> +        // points to a `HrTimer<T>` contained in an `T`.
>>>> +        let receiver_ptr = unsafe { T::timer_container_of(timer_ptr) };
>>>> +
>>>> +        // SAFETY: By the safety requirement of this function, `timer_ptr`
>>>> +        // points to a `HrTimer<T>` contained in an `T`.
>>>
>>> This justification seems wrong it talks about `HrTimer<T>`, but here we
>>> have a `*const T`... Also see [1] (I am mainly interested in your
>>> justification for the lifetime).
>>>
>>> [1]: https://doc.rust-lang.org/std/ptr/index.html#pointer-to-reference-conversion
>>
>> How is this:
>>
>>         // SAFETY:
>>         //  - By the safety requirement of this function, `timer_ptr`
>>         //    points to a `HrTimer<T>` contained in an `T`.
>>         //  - The `PinHrTimerHandle` associated with this timer is guaranteed to
>>         //    be alive until this method returns. As the handle borrows from
>>         //    `T`, `T` is also guaranteed to be alive for the duration of this
>>         //    function.
>
> Sounds good, if you can also explain (probably somewhere else, as every
> `RawHrTimerCallback` implementer will rely on this) why the handle lives
> for the duration of the callback.

It is in the safety requirement for the `HrTimerHandle` trait already.
Should I reference it here?


Best regards,
Andreas Hindborg




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ