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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251208154307.0737cc2d.gary@garyguo.net>
Date: Mon, 8 Dec 2025 15:43:07 +0000
From: Gary Guo <gary@...yguo.net>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Oleg Nesterov <oleg@...hat.com>, Christian Brauner
 <christian@...uner.io>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor
 <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, "
 Björn Roy Baron" <bjorn3_gh@...tonmail.com>, Benno Lossin
 <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>, Trevor Gross
 <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>, Panagiotis
 Foliadis <pfoliadis@...teo.net>, Shankari Anand
 <shankari.ak0208@...il.com>, FUJITA Tomonori <fujita.tomonori@...il.com>,
 Alexey Gladkov <legion@...nel.org>, rust-for-linux@...r.kernel.org,
 linux-kernel@...r.kernel.org
Subject: Re: rust: wrong SAFETY comments in group_leader() and pid() +
 questions

On Fri, 5 Dec 2025 18:17:09 +0000
Alice Ryhl <aliceryhl@...gle.com> wrote:

> On Fri, Dec 05, 2025 at 06:21:46PM +0100, Oleg Nesterov wrote:
> > On 12/05, Alice Ryhl wrote:  
> > >
> > > pub fn group_leader(&self) -> &Task {
> > >     // SAFETY: The lifetime of the returned task reference is tied to
> > >     // the lifetime of `self`, and given that a task has a reference to
> > >     // its group leader, we know it must be valid for the lifetime of
> > >     // the returned task reference.
> > >     unsafe { &*bindings::task_group_leader(self.as_ptr()).cast::<Task>() }
> > > }  
> > 
> > Thanks again Alice, but the comment still looks misleading to me...
> > OK, quite possibly this is because I don't understand what does the
> > "lifetime of the returned task reference" actually mean in the rust code.
> > Does it mean "lifetime of task_struct" of "lifetime of the process/thread" ?  
> 
> To start with, it's likely that this comment is not the right choice
> for this function, given our discussion. Most likely group_leader()
> needs to be moved to `impl CurrentTask {}` and the safety comment needs
> to explain why being the current task ensures that the returned &Task
> lives for long enough. I just took the safety comment from the code we
> have today.

This indeed sounds like the right approach to take.

If `Task::pid` or `Task::group_leader` just gives the pid or group
leader at the time of invocation and doesn't have any stability
guarantee, then the user of the functions will likely be misusing these
functions.

It's better to just have them on `CurrentTask` for now. When an user
arises that need to retrieve them for another task, then we can come
back and think about a proper solution taking the scenario into account.

Best,
Gary

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ