Re: [PATCH v2 3/3] kthread: Use 'task_struct->full_name' to store kthread's full name

From: Kees Cook
Date: Thu Apr 03 2025 - 12:24:40 EST


On Mon, Mar 31, 2025 at 05:48:20PM +0530, Bhupesh wrote:
> Commit 6986ce24fc00 ("kthread: dynamically allocate memory to store
> kthread's full name"), added 'full_name' in parallel to 'comm' for
> kthread names.
>
> Now that we have added 'full_name' added to 'task_struct' itself,
> drop the additional 'full_name' entry from 'struct kthread' and also
> its usage.
>
> Signed-off-by: Bhupesh <bhupesh@xxxxxxxxxx>

I'd like to see this patch be the first patch in the series. This show
the existing use for "full_name". (And as such it'll probably need bits
from patch 1.)

-Kees

> ---
> kernel/kthread.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index 5dc5b0d7238e..46fe19b7ef76 100644
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -66,8 +66,6 @@ struct kthread {
> #ifdef CONFIG_BLK_CGROUP
> struct cgroup_subsys_state *blkcg_css;
> #endif
> - /* To store the full name if task comm is truncated. */
> - char *full_name;
> struct task_struct *task;
> struct list_head hotplug_node;
> struct cpumask *preferred_affinity;
> @@ -108,12 +106,12 @@ void get_kthread_comm(char *buf, size_t buf_size, struct task_struct *tsk)
> {
> struct kthread *kthread = to_kthread(tsk);
>
> - if (!kthread || !kthread->full_name) {
> + if (!kthread || !tsk->full_name) {
> strscpy(buf, tsk->comm, buf_size);
> return;
> }
>
> - strscpy_pad(buf, kthread->full_name, buf_size);
> + strscpy_pad(buf, tsk->full_name, buf_size);
> }
>
> bool set_kthread_struct(struct task_struct *p)
> @@ -153,7 +151,6 @@ void free_kthread_struct(struct task_struct *k)
> WARN_ON_ONCE(kthread->blkcg_css);
> #endif
> k->worker_private = NULL;
> - kfree(kthread->full_name);
> kfree(kthread);
> }
>
> @@ -430,7 +427,7 @@ static int kthread(void *_create)
> kthread_exit(-EINTR);
> }
>
> - self->full_name = create->full_name;
> + self->task->full_name = create->full_name;
> self->threadfn = threadfn;
> self->data = data;
>
> --
> 2.38.1
>

--
Kees Cook