From: David Laight <david.laight.linux@gmail.com>
To: "André Almeida" <andrealmeid@igalia.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Steven Rostedt <rostedt@goodmis.org>,
Christian Brauner <brauner@kernel.org>,
Kees Cook <kees@kernel.org>, Shuah Khan <shuah@kernel.org>,
willy@infradead.org, mathieu.desnoyers@efficios.com,
Linus Torvalds <torvalds@linux-foundation.org>,
akpm@linux-foundation.org, Yafang Shao <laoar.shao@gmail.com>,
andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com,
Petr Mladek <pmladek@suse.com>,
linux-kernel@vger.kernel.org, kernel-dev@igalia.com,
linux-mm@kvack.org, linux-api@vger.kernel.org
Subject: Re: [PATCH v3 3/7] treewide: Replace memcpy(..., current->comm) with copy_task_comm()
Date: Fri, 12 Jun 2026 19:53:30 +0100 [thread overview]
Message-ID: <20260612195330.1653d041@pumpkin> (raw)
In-Reply-To: <20260612-tonyk-long_name-v3-3-7989b66e8a99@igalia.com>
On Fri, 12 Jun 2026 13:20:16 -0300
André Almeida <andrealmeid@igalia.com> wrote:
> In order to increase the size of current->comm[] and to avoid breaking any
> existing code, replace memcpy() with copy_task_comm(). This new function
> makes sure that the copy is NUL terminated. This is crucial given that the
> source buffer might be larger than the destination buffer and could
> truncate the NUL character out of it.
Aren't you re-inventing get_task_comm() that the previous patch removed?
...
> +/*
> + * Copy task name to a buffer. Final result is always a NUL-terminated string.
> + */
> +#define copy_task_comm(dst, tsk, len) \
> +{ \
> + const char *_src = (tsk)->comm; \
> + size_t _dst_len = len + __must_be_array(dst),
If you are using __must_be_array() then why not use sizeof to get the _dst_len?
> + _src_len = sizeof(_src); \
Isn't sizeof(_src) just the size of a pointer?
You need to use sizeof (tsk)->comm
> + char *_dst = dst; \
> + \
> + if (_dst_len <= _src_len) { \
> + memcpy(_dst, _src, _dst_len); \
> + dst[_dst_len - 1] = '\0'; \
If the lengths are equal you don't need to write the '\0'.
(and they should really both be compile time constants.)
> + } else { \
> + strscpy_pad(_dst, _src, _dst_len); \
> + } \
If you do the memcpy() the bytes after the first '\0' aren't guaranteed to
be '\0' - then can be random (usually part of an old version of the task name).
So I'm not sure the strscpy_pad() path is needed.
The most you might want to do is memset() the extra bytes.
But are there ever any????
There will be code that copies the task->comm to a short buffer, but are
there any places where it actually gets copied to a longer one - if so why?
David
next prev parent reply other threads:[~2026-06-12 18:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 16:20 [PATCH v3 0/7] sched: Add support for long task name André Almeida
2026-06-12 16:20 ` [PATCH v3 1/7] sched: Update get_task_comm() comment André Almeida
2026-06-12 16:20 ` [PATCH v3 2/7] treewide: Get rid of get_task_comm() André Almeida
2026-06-12 16:20 ` [PATCH v3 3/7] treewide: Replace memcpy(..., current->comm) with copy_task_comm() André Almeida
2026-06-12 18:53 ` David Laight [this message]
2026-06-12 16:20 ` [PATCH v3 4/7] lib/string_kunit: Add test for copy_task_comm() André Almeida
2026-06-12 16:20 ` [PATCH v3 5/7] sched: Extend task command name with TASK_COMM_EXT_LEN André Almeida
2026-06-12 16:20 ` [PATCH v3 6/7] prctl: Add support for long user thread names André Almeida
2026-06-12 16:20 ` [PATCH v3 7/7] selftests: prctl: Add test for long " André Almeida
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260612195330.1653d041@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrealmeid@igalia.com \
--cc=andrii.nakryiko@gmail.com \
--cc=arnaldo.melo@gmail.com \
--cc=brauner@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kernel-dev@igalia.com \
--cc=laoar.shao@gmail.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vincent.guittot@linaro.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox