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]
Date:   Wed, 27 Oct 2021 22:10:49 +0200
From:   Petr Mladek <pmladek@...e.com>
To:     Kees Cook <keescook@...omium.org>
Cc:     Yafang Shao <laoar.shao@...il.com>, akpm@...ux-foundation.org,
        rostedt@...dmis.org, mathieu.desnoyers@...icios.com,
        arnaldo.melo@...il.com, peterz@...radead.org,
        viro@...iv.linux.org.uk, valentin.schneider@....com,
        qiang.zhang@...driver.com, robdclark@...omium.org,
        christian@...uner.io, dietmar.eggemann@....com, mingo@...hat.com,
        juri.lelli@...hat.com, vincent.guittot@...aro.org,
        davem@...emloft.net, kuba@...nel.org, ast@...nel.org,
        daniel@...earbox.net, andrii@...nel.org, kafai@...com,
        songliubraving@...com, yhs@...com, john.fastabend@...il.com,
        kpsingh@...nel.org, dennis.dalessandro@...nelisnetworks.com,
        mike.marciniszyn@...nelisnetworks.com, dledford@...hat.com,
        jgg@...pe.ca, linux-rdma@...r.kernel.org, netdev@...r.kernel.org,
        bpf@...r.kernel.org, linux-perf-users@...r.kernel.org,
        linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, oliver.sang@...el.com, lkp@...el.com,
        Andrii Nakryiko <andrii.nakryiko@...il.com>
Subject: Re: [PATCH v6 12/12] kernel/kthread: show a warning if kthread's
 comm is truncated

On Mon 2021-10-25 14:35:42, Kees Cook wrote:
> On Mon, Oct 25, 2021 at 08:33:15AM +0000, Yafang Shao wrote:
> > Show a warning if task comm is truncated. Below is the result
> > of my test case:
> > 
> > truncated kthread comm:I-am-a-kthread-with-lon, pid:14 by 6 characters
> > 
> > Suggested-by: Petr Mladek <pmladek@...e.com>
> > Signed-off-by: Yafang Shao <laoar.shao@...il.com>
> > Reviewed-by: Kees Cook <keescook@...omium.org>
> > Cc: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
> > Cc: Arnaldo Carvalho de Melo <arnaldo.melo@...il.com>
> > Cc: Andrii Nakryiko <andrii.nakryiko@...il.com>
> > Cc: Peter Zijlstra <peterz@...radead.org>
> > Cc: Steven Rostedt <rostedt@...dmis.org>
> > Cc: Al Viro <viro@...iv.linux.org.uk>
> > Cc: Kees Cook <keescook@...omium.org>
> > Cc: Petr Mladek <pmladek@...e.com>
> > ---
> >  kernel/kthread.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/kthread.c b/kernel/kthread.c
> > index 5b37a8567168..46b924c92078 100644
> > --- a/kernel/kthread.c
> > +++ b/kernel/kthread.c
> > @@ -399,12 +399,17 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
> >  	if (!IS_ERR(task)) {
> >  		static const struct sched_param param = { .sched_priority = 0 };
> >  		char name[TASK_COMM_LEN];
> > +		int len;
> >  
> >  		/*
> >  		 * task is already visible to other tasks, so updating
> >  		 * COMM must be protected.
> >  		 */
> > -		vsnprintf(name, sizeof(name), namefmt, args);
> > +		len = vsnprintf(name, sizeof(name), namefmt, args);
> > +		if (len >= TASK_COMM_LEN) {
> 
> And since this failure case is slow-path, we could improve the warning
> as other had kind of suggested earlier with something like this instead:
> 
> 			char *full_comm;
> 
> 			full_comm = kvasprintf(GFP_KERNEL, namefmt, args);

You need to use va_copy()/va_end() if you want to use the same va_args
twice.

For example, see how kvasprintf() is implemented. It calls
vsnprintf() twice and it uses va_copy()/va_end() around the the first call.

kvasprintf() could also return NULL if there is not enough memory.

> 			pr_warn("truncated kthread comm '%s' to '%s' (pid:%d)\n",
> 				full_comm, name);

BTW: Is this message printed during normal boot? I did not tried the
patchset myself.

We should add this warning only if there is a good solution how to
avoid the truncated names. And we should me sure that the most common
kthreads/workqueues do not trigger it. It would be ugly to print many
warnings during boot if people could not get rid of them easily.

> 			kfree(full_comm);
> 		}
> >  		set_task_comm(task, name);
> >  		/*
> >  		 * root may have changed our (kthreadd's) priority or CPU mask.

Best Regards,
Petr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ