[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALOAHbAki4sRrSZ6RY6Kp+nYSJ8-Ximray+wLP+e3N4GvUDWnw@mail.gmail.com>
Date: Thu, 30 Sep 2021 20:54:10 +0800
From: Yafang Shao <laoar.shao@...il.com>
To: Kees Cook <keescook@...omium.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Petr Mladek <pmladek@...e.com>,
Peter Zijlstra <peterz@...radead.org>,
Valentin Schneider <valentin.schneider@....com>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
qiang.zhang@...driver.com, robdclark@...omium.org,
Al Viro <viro@...iv.linux.org.uk>, christian@...uner.io,
Dietmar Eggemann <dietmar.eggemann@....com>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 5/5] kernel/kthread: show a warning if kthread's comm is
still trucated
On Thu, Sep 30, 2021 at 2:20 AM Kees Cook <keescook@...omium.org> wrote:
>
> On Wed, Sep 29, 2021 at 11:50:36AM +0000, Yafang Shao wrote:
> > Show a warning if the ktrhead's comm is still trucated. Below is the
> > result of my test case -
> >
> > __kthread_create_on_node:410: comm of pid 14 is truncated from "I-am-a-kthread-with-long-name" to "I-am-a-kthread-with-lon"
> >
> > Signed-off-by: Yafang Shao <laoar.shao@...il.com>
>
> I like this check as a reasonable way to make kthread authors aware of
> the TASK_COMM_LEN limitation.
>
Thanks for the review.
> > ---
> > kernel/kthread.c | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/kthread.c b/kernel/kthread.c
> > index 6def951c605a..aa093f1f423a 100644
> > --- a/kernel/kthread.c
> > +++ b/kernel/kthread.c
> > @@ -404,7 +404,11 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
> > * task is already visible to other tasks, so updating
> > * COMM must be protected.
> > */
> > - vsnprintf(name, sizeof(name), namefmt, args);
> > + if (vsnprintf(name, KTHREAD_COMM_LEN, namefmt, args) >=
> > + KTHREAD_COMM_LEN)
> > + pr_warn("%s:%d: comm of pid %d is truncated from \"%s\" to \"%s\"\n",
> > + __func__, __LINE__, task->pid, namefmt, name);
> > +
> > set_task_comm(task, name);
> > /*
> > * root may have changed our (kthreadd's) priority or CPU mask.
> > --
> > 2.17.1
> >
>
> --
> Kees Cook
--
Thanks
Yafang
Powered by blists - more mailing lists