From: Yafang Shao <laoar.shao@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: akpm@linux-foundation.org, ebiederm@xmission.com,
alexei.starovoitov@gmail.com, rostedt@goodmis.org,
catalin.marinas@arm.com, penguin-kernel@i-love.sakura.ne.jp,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, audit@vger.kernel.org,
linux-security-module@vger.kernel.org, selinux@vger.kernel.org,
bpf@vger.kernel.org, netdev@vger.kernel.org,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5 0/9] Improve the copy of task comm
Date: Tue, 6 Aug 2024 11:50:40 +0800 [thread overview]
Message-ID: <CALOAHbDPToZDrsB2wSp6Ss5L0ksrCb1ufx3SZ1GWeqQ2jP7Daw@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=wgXYkMueFpxgSY_vfCzdcCnyoaPcjS8e0BXiRfgceRHfQ@mail.gmail.com>
On Tue, Aug 6, 2024 at 11:10 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> On Mon, 5 Aug 2024 at 20:01, Yafang Shao <laoar.shao@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).
>
Will do it.
Thanks for your explanation.
--
Regards
Yafang
prev parent reply other threads:[~2024-08-06 3:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-04 7:56 Yafang Shao
2024-08-04 7:56 ` [PATCH v5 1/9] fs/exec: Drop task_lock() inside __get_task_comm() Yafang Shao
2024-08-04 7:56 ` [PATCH v5 2/9] auditsc: Replace memcpy() with __get_task_comm() Yafang Shao
2024-08-04 7:56 ` [PATCH v5 3/9] security: " Yafang Shao
2024-08-04 7:56 ` [PATCH v5 4/9] bpftool: Ensure task comm is always NUL-terminated Yafang Shao
2024-08-04 7:56 ` [PATCH v5 5/9] mm/util: Fix possible race condition in kstrdup() Yafang Shao
2024-08-04 7:56 ` [PATCH v5 6/9] mm/util: Deduplicate code in {kstrdup,kstrndup,kmemdup_nul} Yafang Shao
2024-08-04 7:56 ` [PATCH v5 7/9] tracing: Replace strncpy() with __get_task_comm() Yafang Shao
2024-08-04 7:56 ` [PATCH v5 8/9] net: Replace strcpy() " Yafang Shao
2024-08-04 7:56 ` [PATCH v5 9/9] drm: " Yafang Shao
2024-08-05 21:28 ` [PATCH v5 0/9] Improve the copy of task comm Linus Torvalds
2024-08-06 3:00 ` Yafang Shao
2024-08-06 3:09 ` Linus Torvalds
2024-08-06 3:50 ` Yafang Shao [this message]
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=CALOAHbDPToZDrsB2wSp6Ss5L0ksrCb1ufx3SZ1GWeqQ2jP7Daw@mail.gmail.com \
--to=laoar.shao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--cc=audit@vger.kernel.org \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ebiederm@xmission.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=rostedt@goodmis.org \
--cc=selinux@vger.kernel.org \
--cc=torvalds@linux-foundation.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