Thread (14 messages) 14 messages, 2 authors, 2024-08-06

Re: [PATCH v5 0/9] Improve the copy of task comm

From: Yafang Shao <hidden>
Date: 2024-08-06 03:51:17
Also in: bpf, dri-devel, linux-fsdevel, linux-mm, linux-trace-kernel, netdev, selinux

On Tue, Aug 6, 2024 at 11:10 AM Linus Torvalds
[off-list ref] wrote:
On Mon, 5 Aug 2024 at 20:01, Yafang Shao [off-list ref] wrote:
quoted
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).
Will do it.
Thanks for your explanation.

-- 
Regards
Yafang
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help