[PATCH v5 0/9] Improve the copy of task comm
Linus Torvalds
torvalds at linux-foundation.org
Tue Aug 6 03:09:51 UTC 2024
On Mon, 5 Aug 2024 at 20:01, Yafang Shao <laoar.shao at gmail.com> wrote:
>
> One concern about removing the BUILD_BUG_ON() is that if we extend
> TASK_COMM_LEN to a larger size, such as 24, the caller with a
> hardcoded 16-byte buffer may overflow.
No, not at all. Because get_task_comm() - and the replacements - would
never use TASK_COMM_LEN.
They'd use the size of the *destination*. That's what the code already does:
#define get_task_comm(buf, tsk) ({ \
...
__get_task_comm(buf, sizeof(buf), tsk); \
note how it uses "sizeof(buf)".
Now, it might be a good idea to also verify that 'buf' is an actual
array, and that this code doesn't do some silly "sizeof(ptr)" thing.
We do have a helper for that, so we could do something like
#define get_task_comm(buf, tsk) \
strscpy_pad(buf, __must_be_array(buf)+sizeof(buf), (tsk)->comm)
as a helper macro for this all.
(Although I'm not convinced we generally want the "_pad()" version,
but whatever).
Linus
More information about the dri-devel
mailing list