Skip to contentSkip to conversation

Patch "rust: task: restrict Task::group_leader() to current" has been added to the 6.18-stable tree

DISCUSSION Alice Ryhl 3 participants 4 messages Mar 23 1 message not in the archive Stable branch

lore
Share & tools
lore

Alice Ryhl

author
#1 lore raw
In reply to a message not in the archive
Quoted 58 lines · Sasha Levin

This is a note to let you know that I've just added the patch titled

rust: task: restrict Task::group_leader() to current

to the 6.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
rust-task-restrict-task-group_leader-to-current.patch
and it can be found in the queue-6.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

commit afd4cb72fea7e256c378bc90efc19e140da35e00

Author: Alice Ryhl <[email protected]>
Date:   Wed Jan 7 08:28:46 2026 +0000

rust: task: restrict Task::group_leader() to current

[ Upstream commit 105ddfb2d2b3acec7a7d9695463df48733d91e6c ]

The Task::group_leader() method currently allows you to access the group_leader() of any task, for example one you hold a refcount to. But this is not safe in general since the group leader could change when a task exits. See for example commit a15f37a40145c ("kernel/sys.c: fix the racy usage of task_lock(tsk->group_leader) in sys_prlimit64() paths").

All existing users of Task::group_leader() call this method on current, which is guaranteed running, so there's not an actual issue in Rust code today. But to prevent code in the future from making this mistake, restrict Task::group_leader() so that it can only be called on current.

There are some other cases where accessing task->group_leader is okay. For example it can be safe if you hold tasklist_lock or rcu_read_lock(). However, only supporting current->group_leader is sufficient for all in-tree Rust users of group_leader right now. Safe Rust functionality for accessing it under rcu or while holding tasklist_lock may be added in the future if required by any future Rust module.

This patch is a bugfix in that it prevents users of this API from writing incorrect code. It doesn't change behavior of correct code.

Fixes 313c4281bc9d ("rust: add basic `Task`")
Cc Andreas Hindborg <[email protected]>
Cc Benno Lossin <[email protected]>
Cc "Björn Roy Baron" <[email protected]>
Cc Björn Roy Baron <[email protected]>
Cc Christian Brauner <[email protected]>
Quoted 8 lines
Cc Danilo Krummrich <[email protected]>
Cc FUJITA Tomonori <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Panagiotis Foliadis <[email protected]>
Cc Shankari Anand <[email protected]>
Cc Trevor Gross <[email protected]>

I noticed that this was backported to 6.18, but not to 6.12. Is that because the first user of this function was merged in 6.18, or is there some other reason?

Alice

#2 lore raw
Quoted 4 lines · Alice Ryhl

I noticed that this was backported to 6.18, but not to 6.12. Is that because the first user of this function was merged in 6.18, or is there some other reason?

If it was meant to be backported, then the commit should have Cc:
[email protected].

Perhaps it was picked for 6.18 (and 6.19) because it applied cleanly.

Cheers,
Miguel

#3 lore raw
Quoted 10 lines · Miguel Ojeda
Quoted 4 lines · Alice Ryhl

I noticed that this was backported to 6.18, but not to 6.12. Is that because the first user of this function was merged in 6.18, or is there some other reason?

If it was meant to be backported, then the commit should have Cc:
[email protected].

Perhaps it was picked for 6.18 (and 6.19) because it applied cleanly.

That is correct, we take "Fixes:" only commits as a "best effort" type of thing. This doesn't apply cleanly to 6.12.y so it was not applied there, nor was there a FAILED email sent as it wasn't asked directly to be applied by the developer/maintainer.

hope this helps explain,

greg k-h

author
#4 lore raw
Quoted 11 lines · Greg KH
Quoted 9 lines · Miguel Ojeda
Quoted 4 lines · Alice Ryhl

I noticed that this was backported to 6.18, but not to 6.12. Is that because the first user of this function was merged in 6.18, or is there some other reason?

If it was meant to be backported, then the commit should have Cc:
[email protected].

Quoted 8 lines
Quoted 1 line

Perhaps it was picked for 6.18 (and 6.19) because it applied cleanly.

That is correct, we take "Fixes:" only commits as a "best effort" type of thing. This doesn't apply cleanly to 6.12.y so it was not applied there, nor was there a FAILED email sent as it wasn't asked directly to be applied by the developer/maintainer.

hope this helps explain,

ah, ok, that makes sense, thanks!

Alice