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]
Message-ID: <YVXVBXSZ1m4ScvbX@alley>
Date:   Thu, 30 Sep 2021 17:17:25 +0200
From:   Petr Mladek <pmladek@...e.com>
To:     Yafang Shao <laoar.shao@...il.com>
Cc:     akpm@...ux-foundation.org, peterz@...radead.org,
        valentin.schneider@....com, keescook@...omium.org,
        mathieu.desnoyers@...icios.com, qiang.zhang@...driver.com,
        robdclark@...omium.org, viro@...iv.linux.org.uk,
        christian@...uner.io, dietmar.eggemann@....com,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 5/5] kernel/kthread: show a warning if kthread's comm is
 still trucated

On Wed 2021-09-29 11:50:36, 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>
> ---
>  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);

The warning makes sense. But the use of "namefmt" looks wrong. It is
format and not the name. Also __func__ and __LINE__ is overkill. It will
be always the same.

I would do something like:

		len = vsnprintf(name, sizeof(name), namefmt, args);
		if (len >= KTHREAD_COMM_LEN) {
			pr_warn("truncated kthread comm:%s, pid:%d by %d characters\n",
				name, task->pid, len - KTHREAD_COMM_LEN + 1);
		}

Best Regards,
Petr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ