From: Petr Mladek <pmladek@suse.com>
To: Bhupesh <bhupesh@igalia.com>
Cc: akpm@linux-foundation.org, kernel-dev@igalia.com,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, oliver.sang@intel.com, lkp@intel.com,
laoar.shao@gmail.com, rostedt@goodmis.org,
mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com,
alexei.starovoitov@gmail.com, andrii.nakryiko@gmail.com,
mirq-linux@rere.qmqm.pl, peterz@infradead.org,
willy@infradead.org, david@redhat.com, viro@zeniv.linux.org.uk,
keescook@chromium.org, ebiederm@xmission.com, brauner@kernel.org,
jack@suse.cz, mingo@redhat.com, juri.lelli@redhat.com,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com
Subject: Re: [PATCH v3 2/3] treewide: Switch memcpy() users of 'task->comm' to a more safer implementation
Date: Wed, 7 May 2025 14:29:46 +0200 [thread overview]
Message-ID: <aBtSK5dFmtFXUaOE@pathway.suse.cz> (raw)
In-Reply-To: <20250507110444.963779-3-bhupesh@igalia.com>
On Wed 2025-05-07 16:34:43, Bhupesh wrote:
> As Linus mentioned in [1], currently we have several memcpy() use-cases
> which use 'current->comm' to copy the task name over to local copies.
> For an example:
>
> ...
> char comm[TASK_COMM_LEN];
> memcpy(comm, current->comm, TASK_COMM_LEN);
> ...
>
> These should be modified so that we can later implement approaches
> to handle the task->comm's 16-byte length limitation (TASK_COMM_LEN)
> is a more modular way (follow-up patches do the same):
>
> ...
> char comm[TASK_COMM_LEN];
> memcpy(comm, current->comm, TASK_COMM_LEN);
> comm[TASK_COMM_LEN - 1] = 0;
> ...
>
> The relevant 'memcpy()' users were identified using the following search
> pattern:
> $ git grep 'memcpy.*->comm\>'
>
> [1]. https://lore.kernel.org/all/CAHk-=wjAmmHUg6vho1KjzQi2=psR30+CogFd4aXrThr2gsiS4g@mail.gmail.com/
>
> --- a/include/linux/coredump.h
> +++ b/include/linux/coredump.h
> @@ -53,7 +53,8 @@ extern void do_coredump(const kernel_siginfo_t *siginfo);
> do { \
> char comm[TASK_COMM_LEN]; \
> /* This will always be NUL terminated. */ \
> - memcpy(comm, current->comm, sizeof(comm)); \
> + memcpy(comm, current->comm, TASK_COMM_LEN); \
> + comm[TASK_COMM_LEN] = '\0'; \
I would expect that we replace this with a helper function/macro
which would do the right thing.
Why is get_task_comm() not used here, please?
> printk_ratelimited(Level "coredump: %d(%*pE): " Format "\n", \
Also the name seems to be used for printing a debug information.
I would expect that we could use the bigger buffer here and print
the "full" name. Is this planed, please?
> task_tgid_vnr(current), (int)strlen(comm), comm, ##__VA_ARGS__); \
> } while (0) \
> diff --git a/include/trace/events/block.h b/include/trace/events/block.h
> index bd0ea07338eb..94a941ac2034 100644
> --- a/include/trace/events/block.h
> +++ b/include/trace/events/block.h
> @@ -214,6 +214,7 @@ DECLARE_EVENT_CLASS(block_rq,
> blk_fill_rwbs(__entry->rwbs, rq->cmd_flags);
> __get_str(cmd)[0] = '\0';
> memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
> + __entry->comm[TASK_COMM_LEN - 1] = '\0';
Same for all other callers.
That said, I am not sure if the larger buffer is save in all situations.
> ),
Best Regards,
Petr
next prev parent reply other threads:[~2025-05-07 12:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 11:04 [PATCH v3 0/3] Add support for long task name Bhupesh
2025-05-07 11:04 ` [PATCH v3 1/3] exec: Remove obsolete comments Bhupesh
2025-05-07 11:04 ` [PATCH v3 2/3] treewide: Switch memcpy() users of 'task->comm' to a more safer implementation Bhupesh
2025-05-07 12:29 ` Petr Mladek [this message]
2025-05-08 8:17 ` Bhupesh Sharma
2025-05-08 8:22 ` Bhupesh Sharma
2025-05-08 14:02 ` Steven Rostedt
2025-05-08 12:21 ` kernel test robot
2025-05-07 11:04 ` [PATCH v3 3/3] exec: Add support for 64 byte 'tsk->real_comm' Bhupesh
2025-05-07 12:54 ` Petr Mladek
2025-05-07 17:23 ` Steven Rostedt
2025-05-08 8:08 ` Bhupesh Sharma
2025-05-08 13:58 ` Steven Rostedt
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=aBtSK5dFmtFXUaOE@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=arnaldo.melo@gmail.com \
--cc=bhupesh@igalia.com \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=david@redhat.com \
--cc=ebiederm@xmission.com \
--cc=jack@suse.cz \
--cc=juri.lelli@redhat.com \
--cc=keescook@chromium.org \
--cc=kernel-dev@igalia.com \
--cc=laoar.shao@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=lkp@intel.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mirq-linux@rere.qmqm.pl \
--cc=oliver.sang@intel.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=viro@zeniv.linux.org.uk \
--cc=vschneid@redhat.com \
--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