[PATCH v2 5/5] drivers: Remove get_task_comm() and print task comm directly

2024-12-18 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Reviewed-by: Jiri Slaby (For tty) Reviewed-by: Lyude Paul (For nouveau)

[PATCH v2 4/5] security: Remove get_task_comm() and print task comm directly

2024-12-18 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Reviewed-by: Paul Moore Acked-by: Kees Cook Cc: James Morris Cc: "

[PATCH v2 3/5] net: Remove get_task_comm() and print task comm directly

2024-12-18 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Cc: Johannes Berg --- net/wireless/wext-core.c | 4 +--- 1 file changed

[PATCH v2 2/5] arch: Remove get_task_comm() and print task comm directly

2024-12-18 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Cc: Vineet Gupta Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov

[PATCH v2 0/5] Remove get_task_comm() and print task comm directly

2024-12-18 Thread Yafang Shao
//lore.kernel.org/all/20241213054610.55843-1-laoar.s...@gmail.com/ Yafang Shao (5): kernel: Remove get_task_comm() and print task comm directly arch: Remove get_task_comm() and print task comm directly net: Remove get_task_comm() and print task comm directly security: Remove get_task_comm() and pri

[PATCH v2 1/5] kernel: Remove get_task_comm() and print task comm directly

2024-12-18 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Cc: Serge Hallyn Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Peter Zijlstra

Re: [PATCH 1/7] vsprintf: Add %pTN to print task name

2024-12-13 Thread Yafang Shao
On Fri, Dec 13, 2024 at 4:05 PM Petr Mladek wrote: > > On Fri 2024-12-13 13:46:04, Yafang Shao wrote: > > Since the task->comm is guaranteed to be NUL-ternimated, we can print it > > directly. Add a new vsnprintf format specifier "%pTN" to print task comm, &g

[PATCH 7/7] fs: Use %pTN to print task name

2024-12-12 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Cc: Mark Fasheh Cc: Joel Becker Cc: Joseph Qi --- fs/ocfs2/clus

[PATCH 6/7] drivers: Repace get_task_comm() with %pTN

2024-12-12 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Cc: Ofir Bitton Cc: Oded Gabbay Cc: Jani Nikula Cc: Rodrigo Vivi Cc: Joo

[PATCH 5/7] security: Replace get_task_comm() with %pTN

2024-12-12 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Cc: Kees Cook Cc: Paul Moore Cc: James Morris Cc: "Serge E

[PATCH 4/7] net: Replace get_task_comm() with %pTN

2024-12-12 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Cc: Johannes Berg --- net/wireless/wext-core.c | 6 ++ 1 file changed

[PATCH 0/7] vsprintf: Add %pTN to print Task Name

2024-12-12 Thread Yafang Shao
a subsequent patch. Suggested-by: Linus Torvalds Link: https://lore.kernel.org/bpf/CAHk-=wgqrwFXK-CO8-V4fwUh5ymnUZ=wjnfyufv1dm9rc1t...@mail.gmail.com Yafang Shao (7): vsprintf: Add %pTN to print task name kernel: Replace get_task_comm() with %pTN arch: Replace get_task_comm() with %pTN

[PATCH 3/7] arch: Replace get_task_comm() with %pTN

2024-12-12 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Cc: Vineet Gupta Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov

[PATCH 2/7] kernel: Replace get_task_comm() with %pTN

2024-12-12 Thread Yafang Shao
Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copye it into a separate buffer. This simplifies the code and avoids unnecessary operations. Signed-off-by: Yafang Shao Cc: Serge Hallyn Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Peter Zijlstra

[PATCH 1/7] vsprintf: Add %pTN to print task name

2024-12-12 Thread Yafang Shao
ion, the user no longer needs to care about retrieving task name. checkpatch.pl is updated accordingly. Link: https://lore.kernel.org/bpf/CAHk-=wgqrwFXK-CO8-V4fwUh5ymnUZ=wjnfyufv1dm9rc1t...@mail.gmail.com Suggested-by: Linus Torvalds Signed-off-by: Yafang Shao Cc: Andrew Morton Cc: Petr Mladek

[PATCH v9 7/7] drm: Replace strcpy() with strscpy()

2024-10-07 Thread Yafang Shao
To prevent errors from occurring when the src string is longer than the dst string in strcpy(), we should use strscpy() instead. This approach also facilitates future extensions to the task comm. Suggested-by: Justin Stitt Signed-off-by: Yafang Shao Acked-by: Daniel Vetter Reviewed-by: Justin

[PATCH v9 6/7] mm/util: Deduplicate code in {kstrdup, kstrndup, kmemdup_nul}

2024-10-07 Thread Yafang Shao
These three functions follow the same pattern. To deduplicate the code, let's introduce a common helper __kmemdup_nul(). Suggested-by: Andrew Morton Signed-off-by: Yafang Shao Cc: Simon Horman Cc: Matthew Wilcox Cc: Alejandro Colomar --- mm/util.c

[PATCH v9 5/7] mm/util: Fix possible race condition in kstrdup()

2024-10-07 Thread Yafang Shao
the memcpy. It is worth noting that memcpy() is not atomic, so the new string can be shorter when memcpy() already copied past the new NUL. Signed-off-by: Yafang Shao Cc: Andrew Morton Cc: Alejandro Colomar Cc: Andy Shevchenko --- mm/util.c | 9 - 1 file changed, 8 insertions(+), 1 delet

[PATCH v9 4/7] bpftool: Ensure task comm is always NUL-terminated

2024-10-07 Thread Yafang Shao
Let's explicitly ensure the destination string is NUL-terminated. This way, it won't be affected by changes to the source string. Signed-off-by: Yafang Shao Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/pids.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/bpf/bpftoo

[PATCH v9 3/7] security: Replace memcpy() with get_task_comm()

2024-10-07 Thread Yafang Shao
future extensions to the task comm. Signed-off-by: Yafang Shao LINK: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npjoop8chlpefafv0onyt...@mail.gmail.com/ [0] Acked-by: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek ---

[PATCH v9 2/7] auditsc: Replace memcpy() with strscpy()

2024-10-07 Thread Yafang Shao
Using strscpy() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Paul Moore Reviewed-by: Justin Stitt Cc: Eric Paris --- kernel

[PATCH v9 1/7] Get rid of __get_task_comm()

2024-10-07 Thread Yafang Shao
: https://lore.kernel.org/all/CAHk-=whwtuc-ajmgjveaetkomemfstwkwu99v7+b6ayhmma...@mail.gmail.com/ Signed-off-by: Yafang Shao Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook Cc: Alexei Starovoitov Cc: Matus Jokay Cc: Alejandro Colomar Cc: "Serge E. H

[PATCH v9 0/7] Improve the copy of task comm

2024-10-07 Thread Yafang Shao
opping task_lock (Catalin) v1->v2: https://lore.kernel.org/bpf/20240613023044.45873-1-laoar.s...@gmail.com/ - Add comment for dropping task_lock() in __get_task_comm() (Alexei) - Drop changes in trace event (Steven) - Fix comment on task comm (Matus) v1: https://lore.kernel.org/all/20240602023754.254

Re: [PATCH v7 5/8] mm/util: Fix possible race condition in kstrdup()

2024-09-27 Thread Yafang Shao
On Fri, Sep 27, 2024 at 1:35 AM Andy Shevchenko wrote: > > On Thu, Sep 26, 2024 at 7:44 PM Yafang Shao wrote: > > > > In kstrdup(), it is critical to ensure that the dest string is always > > NUL-terminated. However, potential race condidtion can occur between a > >

Re: [PATCH v8 8/8] drm: Replace strcpy() with strscpy()

2024-09-12 Thread Yafang Shao
On Fri, Sep 13, 2024 at 5:28 AM Justin Stitt wrote: > > Hi, > > On Wed, Aug 28, 2024 at 11:03:21AM GMT, Yafang Shao wrote: > > To prevent erros from occurring when the src string is longer than the > > dst string in strcpy(), we should use strscpy() instead. This >

Re: [PATCH v8 4/8] bpftool: Ensure task comm is always NUL-terminated

2024-09-12 Thread Yafang Shao
On Fri, Sep 13, 2024 at 5:14 AM Justin Stitt wrote: > > Hi, > > On Wed, Aug 28, 2024 at 11:03:17AM GMT, Yafang Shao wrote: > > Let's explicitly ensure the destination string is NUL-terminated. This way, > > it won't be affected by changes to the source string.

Re: [PATCH v8 1/8] Get rid of __get_task_comm()

2024-08-28 Thread Yafang Shao
On Wed, Aug 28, 2024 at 10:04 PM Kees Cook wrote: > > > > On August 27, 2024 8:03:14 PM PDT, Yafang Shao wrote: > >We want to eliminate the use of __get_task_comm() for the following > >reasons: > > > >- The task_lock() is unnecessary > > Quoted f

Re: [PATCH v8 1/8] Get rid of __get_task_comm()

2024-08-28 Thread Yafang Shao
On Wed, Aug 28, 2024 at 8:58 PM Alejandro Colomar wrote: > > On Wed, Aug 28, 2024 at 12:15:40PM GMT, Alejandro Colomar wrote: > > Hi Yafang, > > > > On Wed, Aug 28, 2024 at 11:03:14AM GMT, Yafang Shao wrote: > > > We want to eliminate the use of __get_task_comm(

Re: [PATCH v8 6/8] mm/util: Deduplicate code in {kstrdup, kstrndup, kmemdup_nul}

2024-08-28 Thread Yafang Shao
On Wed, Aug 28, 2024 at 6:33 PM Alejandro Colomar wrote: > > On Wed, Aug 28, 2024 at 12:32:53PM GMT, Alejandro Colomar wrote: > > On Wed, Aug 28, 2024 at 11:03:19AM GMT, Yafang Shao wrote: > > > These three functions follow the same pattern. To deduplicate the code, > >

Re: [PATCH v8 1/8] Get rid of __get_task_comm()

2024-08-28 Thread Yafang Shao
On Wed, Aug 28, 2024 at 6:15 PM Alejandro Colomar wrote: > > Hi Yafang, > > On Wed, Aug 28, 2024 at 11:03:14AM GMT, Yafang Shao wrote: > > We want to eliminate the use of __get_task_comm() for the following > > reasons: > > > > - The task_lock() is un

[PATCH v8 8/8] drm: Replace strcpy() with strscpy()

2024-08-27 Thread Yafang Shao
To prevent erros from occurring when the src string is longer than the dst string in strcpy(), we should use strscpy() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Daniel Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard Cc

[PATCH v8 7/8] net: Replace strcpy() with strscpy()

2024-08-27 Thread Yafang Shao
To prevent errors from occurring when the src string is longer than the dst string in strcpy(), we should use strscpy() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: "David S. Miller" Cc: David Ahern Cc: Eric Dumazet

[PATCH v8 6/8] mm/util: Deduplicate code in {kstrdup, kstrndup, kmemdup_nul}

2024-08-27 Thread Yafang Shao
These three functions follow the same pattern. To deduplicate the code, let's introduce a common helper __kmemdup_nul(). Suggested-by: Andrew Morton Signed-off-by: Yafang Shao Cc: Simon Horman Cc: Matthew Wilcox Cc: Alejandro Colomar --- mm/util.c

[PATCH v8 5/8] mm/util: Fix possible race condition in kstrdup()

2024-08-27 Thread Yafang Shao
`s` might be updated by the writer to a new value of task->comm. If the new task->comm is larger than the old one, the `buf` might not be NUL-terminated. This can lead to undefined behavior and potential security vulnerabilities. Let's fix it by explicitly adding a NUL terminator. Signed-

[PATCH v8 4/8] bpftool: Ensure task comm is always NUL-terminated

2024-08-27 Thread Yafang Shao
Let's explicitly ensure the destination string is NUL-terminated. This way, it won't be affected by changes to the source string. Signed-off-by: Yafang Shao Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/pids.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/bpf/bpftoo

[PATCH v8 3/8] security: Replace memcpy() with get_task_comm()

2024-08-27 Thread Yafang Shao
future extensions to the task comm. Signed-off-by: Yafang Shao LINK: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npjoop8chlpefafv0onyt...@mail.gmail.com/ [0] Acked-by: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek ---

[PATCH v8 2/8] auditsc: Replace memcpy() with strscpy()

2024-08-27 Thread Yafang Shao
Using strscpy() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Paul Moore Cc: Eric Paris --- kernel/auditsc.c | 6 +++--- 1 file

[PATCH v8 1/8] Get rid of __get_task_comm()

2024-08-27 Thread Yafang Shao
g/all/2jxak5v6dfxlpbxhpm3ey7oup4g2lnr3ueurfbosf5wdo65dk4@srb3hsk72zwq Signed-off-by: Yafang Shao Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook Cc: Alexei Starovoitov Cc: Matus Jokay Cc: Alejandro Colomar Cc: "Serge E. Hallyn" --- fs/exec.c | 10 -- fs/proc/arr

[PATCH v8 0/8] Improve the copy of task comm

2024-08-27 Thread Yafang Shao
@gmail.com/ - Add comment for dropping task_lock() in __get_task_comm() (Alexei) - Drop changes in trace event (Steven) - Fix comment on task comm (Matus) v1: https://lore.kernel.org/all/20240602023754.25443-1-laoar.s...@gmail.com/ Yafang Shao (8): Get rid of __get_task_comm() auditsc: Replace m

Re: [PATCH v7 6/8] mm/util: Deduplicate code in {kstrdup, kstrndup, kmemdup_nul}

2024-08-26 Thread Yafang Shao
On Mon, Aug 26, 2024 at 5:25 PM Alejandro Colomar wrote: > > Hi Yafang, > > On Sat, Aug 17, 2024 at 10:58:02AM GMT, Alejandro Colomar wrote: > > Hi Yafang, > > > > On Sat, Aug 17, 2024 at 10:56:22AM GMT, Yafang Shao wrote: > > > These three functions foll

Re: [PATCH v7 0/8] Improve the copy of task comm

2024-08-25 Thread Yafang Shao
On Sat, Aug 17, 2024 at 10:56 AM Yafang Shao wrote: > > Using {memcpy,strncpy,strcpy,kstrdup} to copy the task comm relies on the > length of task comm. Changes in the task comm could result in a destination > string that is overflow. Therefore, we should explicitly ensure the &

Re: [PATCH v7 4/8] bpftool: Ensure task comm is always NUL-terminated

2024-08-17 Thread Yafang Shao
On Sat, Aug 17, 2024 at 4:39 PM Alejandro Colomar wrote: > > Hi Yafang, > > On Sat, Aug 17, 2024 at 10:56:20AM GMT, Yafang Shao wrote: > > Let's explicitly ensure the destination string is NUL-terminated. This way, > > it won't be affected by changes to the so

[PATCH v7 8/8] drm: Replace strcpy() with strscpy()

2024-08-16 Thread Yafang Shao
To prevent erros from occurring when the src string is longer than the dst string in strcpy(), we should use strscpy() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Daniel Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard Cc

[PATCH v7 7/8] net: Replace strcpy() with strscpy()

2024-08-16 Thread Yafang Shao
To prevent errors from occurring when the src string is longer than the dst string in strcpy(), we should use strscpy() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: "David S. Miller" Cc: David Ahern Cc: Eric Dumazet

[PATCH v7 6/8] mm/util: Deduplicate code in {kstrdup, kstrndup, kmemdup_nul}

2024-08-16 Thread Yafang Shao
These three functions follow the same pattern. To deduplicate the code, let's introduce a common helper __kmemdup_nul(). Suggested-by: Andrew Morton Signed-off-by: Yafang Shao Cc: Simon Horman Cc: Matthew Wilcox --- mm/util.c | 67 +

[PATCH v7 5/8] mm/util: Fix possible race condition in kstrdup()

2024-08-16 Thread Yafang Shao
`s` might be updated by the writer to a new value of task->comm. If the new task->comm is larger than the old one, the `buf` might not be NUL-terminated. This can lead to undefined behavior and potential security vulnerabilities. Let's fix it by explicitly adding a NUL-terminator. Signed-

[PATCH v7 4/8] bpftool: Ensure task comm is always NUL-terminated

2024-08-16 Thread Yafang Shao
Let's explicitly ensure the destination string is NUL-terminated. This way, it won't be affected by changes to the source string. Signed-off-by: Yafang Shao Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/pids.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/bpf/bpftoo

[PATCH v7 3/8] security: Replace memcpy() with get_task_comm()

2024-08-16 Thread Yafang Shao
future extensions to the task comm. Signed-off-by: Yafang Shao LINK: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npjoop8chlpefafv0onyt...@mail.gmail.com/ [0] Acked-by: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek ---

[PATCH v7 2/8] auditsc: Replace memcpy() with strscpy()

2024-08-16 Thread Yafang Shao
Using strscpy() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Paul Moore Cc: Eric Paris --- kernel/auditsc.c | 6 +++--- 1 file

[PATCH v7 1/8] Get rid of __get_task_comm()

2024-08-16 Thread Yafang Shao
g/all/2jxak5v6dfxlpbxhpm3ey7oup4g2lnr3ueurfbosf5wdo65dk4@srb3hsk72zwq Signed-off-by: Yafang Shao Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook Cc: Alexei Starovoitov Cc: Matus Jokay Cc: Alejandro Colomar Cc: "Serge E. Hallyn" --- fs/exec.c | 10 -- fs/proc/arr

[PATCH v7 0/8] Improve the copy of task comm

2024-08-16 Thread Yafang Shao
kstrdup (Andrew) - Add commit log for dropping task_lock (Catalin) v1->v2: https://lore.kernel.org/bpf/20240613023044.45873-1-laoar.s...@gmail.com/ - Add comment for dropping task_lock() in __get_task_comm() (Alexei) - Drop changes in trace event (Steven) - Fix comment on task comm (Matus) v1

Re: [PATCH v6 7/9] tracing: Replace strncpy() with strscpy()

2024-08-13 Thread Yafang Shao
On Wed, Aug 14, 2024 at 6:31 AM Justin Stitt wrote: > > On Tue, Aug 13, 2024 at 3:19 PM Justin Stitt wrote: > > > > Hi, > > > > On Mon, Aug 12, 2024 at 10:29:31AM GMT, Yafang Shao wrote: > > > Using strscpy() to read the task comm ensures that the name is

Re: [PATCH v6 1/9] Get rid of __get_task_comm()

2024-08-12 Thread Yafang Shao
On Mon, Aug 12, 2024 at 4:05 PM Alejandro Colomar wrote: > > Hi Yafang, > > On Mon, Aug 12, 2024 at 10:29:25AM GMT, Yafang Shao wrote: > > We want to eliminate the use of __get_task_comm() for the following > > reasons: > > > > - The task_lock() is un

[PATCH v6 9/9] drm: Replace strcpy() with strscpy()

2024-08-11 Thread Yafang Shao
To prevent erros from occurring when the src string is longer than the dst string in strcpy(), we should use strscpy() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Daniel Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard Cc

[PATCH v6 8/9] net: Replace strcpy() with strscpy()

2024-08-11 Thread Yafang Shao
To prevent errors from occurring when the src string is longer than the dst string in strcpy(), we should use strscpy() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: "David S. Miller" Cc: David Ahern Cc: Eric Dumazet

[PATCH v6 7/9] tracing: Replace strncpy() with strscpy()

2024-08-11 Thread Yafang Shao
Using strscpy() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Masami Hiramatsu (Google) Cc: Steven Rostedt Cc: Mathieu Desnoyers

[PATCH v6 6/9] mm/util: Deduplicate code in {kstrdup, kstrndup, kmemdup_nul}

2024-08-11 Thread Yafang Shao
These three functions follow the same pattern. To deduplicate the code, let's introduce a common helper __kmemdup_nul(). Suggested-by: Andrew Morton Signed-off-by: Yafang Shao Cc: Simon Horman Cc: Matthew Wilcox --- mm/util.c | 67 +

[PATCH v6 5/9] mm/util: Fix possible race condition in kstrdup()

2024-08-11 Thread Yafang Shao
`s` might be updated by the writer to a new value of task->comm. If the new task->comm is larger than the old one, the `buf` might not be NUL-terminated. This can lead to undefined behavior and potential security vulnerabilities. Let's fix it by explicitly adding a NUL-terminator. Signed-

[PATCH v6 4/9] bpftool: Ensure task comm is always NUL-terminated

2024-08-11 Thread Yafang Shao
Let's explicitly ensure the destination string is NUL-terminated. This way, it won't be affected by changes to the source string. Signed-off-by: Yafang Shao Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/pids.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/bpf/bpftoo

[PATCH v6 3/9] security: Replace memcpy() with get_task_comm()

2024-08-11 Thread Yafang Shao
future extensions to the task comm. Signed-off-by: Yafang Shao LINK: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npjoop8chlpefafv0onyt...@mail.gmail.com/ [0] Acked-by: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek ---

[PATCH v6 2/9] auditsc: Replace memcpy() with strscpy()

2024-08-11 Thread Yafang Shao
Using strscpy() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Paul Moore Cc: Eric Paris --- kernel/auditsc.c | 6 +++--- 1 file

[PATCH v6 1/9] Get rid of __get_task_comm()

2024-08-11 Thread Yafang Shao
g/all/2jxak5v6dfxlpbxhpm3ey7oup4g2lnr3ueurfbosf5wdo65dk4@srb3hsk72zwq Signed-off-by: Yafang Shao Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook Cc: Alexei Starovoitov Cc: Matus Jokay Cc: Alejandro Colomar Cc: "Serge E. Hallyn" --- fs/exec.c | 10 -- fs/proc/arr

[PATCH v6 0/9] Improve the copy of task comm

2024-08-11 Thread Yafang Shao
(Andrew) - Add commit log for dropping task_lock (Catalin) v1->v2: https://lore.kernel.org/bpf/20240613023044.45873-1-laoar.s...@gmail.com/ - Add comment for dropping task_lock() in __get_task_comm() (Alexei) - Drop changes in trace event (Steven) - Fix comment on task comm (Matus) Yafang Shao (9):

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

2024-08-07 Thread Yafang Shao
On Wed, Aug 7, 2024 at 1:28 AM Alejandro Colomar wrote: > > Hi Linus, > > Serge let me know about this thread earlier today. > > On 2024-08-05, Linus Torvalds wrote: > > On Mon, 5 Aug 2024 at 20:01, Yafang Shao wrote: > > > > > > One concern about

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

2024-08-05 Thread Yafang Shao
On Tue, Aug 6, 2024 at 11:10 AM Linus Torvalds wrote: > > On Mon, 5 Aug 2024 at 20:01, Yafang Shao 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-by

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

2024-08-05 Thread Yafang Shao
On Tue, Aug 6, 2024 at 5:28 AM Linus Torvalds wrote: > > On Sun, 4 Aug 2024 at 00:56, Yafang Shao wrote: > > > > There is a BUILD_BUG_ON() inside get_task_comm(), so when you use > > get_task_comm(), it implies that the BUILD_BUG_ON() is necessary. > > Let's

[PATCH v5 9/9] drm: Replace strcpy() with __get_task_comm()

2024-08-04 Thread Yafang Shao
To prevent erros from occurring when the src string is longer than the dst string in strcpy(), we should use __get_task_comm() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Daniel Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard

[PATCH v5 8/9] net: Replace strcpy() with __get_task_comm()

2024-08-04 Thread Yafang Shao
To prevent errors from occurring when the src string is longer than the dst string in strcpy(), we should use __get_task_comm() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: "David S. Miller" Cc: David Ahern Cc: Eric D

[PATCH v5 7/9] tracing: Replace strncpy() with __get_task_comm()

2024-08-04 Thread Yafang Shao
Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Masami Hiramatsu (Google) Cc: Steven Rostedt Cc: Mathieu

[PATCH v5 6/9] mm/util: Deduplicate code in {kstrdup, kstrndup, kmemdup_nul}

2024-08-04 Thread Yafang Shao
These three functions follow the same pattern. To deduplicate the code, let's introduce a common helper __kmemdup_nul(). Suggested-by: Andrew Morton Signed-off-by: Yafang Shao Cc: Simon Horman Cc: Matthew Wilcox --- mm/util.c | 67 +

[PATCH v5 5/9] mm/util: Fix possible race condition in kstrdup()

2024-08-04 Thread Yafang Shao
`s` might be updated by the writer to a new value of task->comm. If the new task->comm is larger than the old one, the `buf` might not be NUL-terminated. This can lead to undefined behavior and potential security vulnerabilities. Let's fix it by explicitly adding a NUL-terminator. Signed-

[PATCH v5 4/9] bpftool: Ensure task comm is always NUL-terminated

2024-08-04 Thread Yafang Shao
Let's explicitly ensure the destination string is NUL-terminated. This way, it won't be affected by changes to the source string. Signed-off-by: Yafang Shao Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/pids.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/bpf/bpftoo

[PATCH v5 3/9] security: Replace memcpy() with __get_task_comm()

2024-08-04 Thread Yafang Shao
facilitates future extensions to the task comm. Signed-off-by: Yafang Shao LINK: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npjoop8chlpefafv0onyt...@mail.gmail.com/ [0] Acked-by: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek ---

[PATCH v5 2/9] auditsc: Replace memcpy() with __get_task_comm()

2024-08-04 Thread Yafang Shao
Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Paul Moore Cc: Eric Paris --- kernel/auditsc.c | 6 +++--- 1

[PATCH v5 1/9] fs/exec: Drop task_lock() inside __get_task_comm()

2024-08-04 Thread Yafang Shao
could have long-term mixed results Suggested-by: Linus Torvalds Link: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npjoop8chlpefafv0onyt...@mail.gmail.com [0] Signed-off-by: Yafang Shao Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook Cc

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

2024-08-04 Thread Yafang Shao
ound kstrdup (Andrew) - Add commit log for dropping task_lock (Catalin) v1->v2: https://lore.kernel.org/bpf/20240613023044.45873-1-laoar.s...@gmail.com/ - Add comment for dropping task_lock() in __get_task_comm() (Alexei) - Drop changes in trace event (Steven) - Fix comment on task comm (Matus) v1: https

Re: [PATCH resend v4 00/11] Improve the copy of task comm

2024-07-30 Thread Yafang Shao
On Wed, Jul 31, 2024 at 8:59 AM Andrew Morton wrote: > > On Mon, 29 Jul 2024 10:37:08 +0800 Yafang Shao wrote: > > > Is it appropriate for you to apply this to the mm tree? > > There are a couple of minor conflicts against current 6.11-rc1 which > you'd best check.

Re: [PATCH resend v4 00/11] Improve the copy of task comm

2024-07-29 Thread Yafang Shao
On Mon, Jul 29, 2024 at 5:29 PM Jani Nikula wrote: > > On Mon, 29 Jul 2024, Yafang Shao wrote: > > Hello Andrew, > > > > Is it appropriate for you to apply this to the mm tree? > > > > Using {memcpy,strncpy,strcpy,kstrdup} to copy the task comm relies on the

[PATCH v4 11/11] drm: Replace strcpy() with __get_task_comm()

2024-07-28 Thread Yafang Shao
To prevent erros from occurring when the src string is longer than the dst string in strcpy(), we should use __get_task_comm() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Daniel Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard

[PATCH v4 10/11] net: Replace strcpy() with __get_task_comm()

2024-07-28 Thread Yafang Shao
To prevent errors from occurring when the src string is longer than the dst string in strcpy(), we should use __get_task_comm() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: "David S. Miller" Cc: David Ahern Cc: Eric D

[PATCH v4 09/11] tracing: Replace strncpy() with __get_task_comm()

2024-07-28 Thread Yafang Shao
Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Masami Hiramatsu (Google) Cc: Steven Rostedt Cc: Mathieu

[PATCH v4 08/11] tsacct: Replace strncpy() with __get_task_comm()

2024-07-28 Thread Yafang Shao
Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao --- kernel/tsacct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion

[PATCH v4 07/11] mm/kmemleak: Replace strncpy() with __get_task_comm()

2024-07-28 Thread Yafang Shao
ff-by: Yafang Shao Acked-by: Catalin Marinas Cc: Andrew Morton --- mm/kmemleak.c | 8 +--- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index d5b6fba44fc9..ef29aaab88a0 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -663,13 +663,7 @@ static s

[PATCH v4 06/11] mm/util: Deduplicate code in {kstrdup, kstrndup, kmemdup_nul}

2024-07-28 Thread Yafang Shao
These three functions follow the same pattern. To deduplicate the code, let's introduce a common helper __kmemdup_nul(). Suggested-by: Andrew Morton Signed-off-by: Yafang Shao Cc: Simon Horman Cc: Matthew Wilcox --- mm/util.c | 67 +

[PATCH v4 05/11] mm/util: Fix possible race condition in kstrdup()

2024-07-28 Thread Yafang Shao
`s` might be updated by the writer to a new value of task->comm. If the new task->comm is larger than the old one, the `buf` might not be NUL-terminated. This can lead to undefined behavior and potential security vulnerabilities. Let's fix it by explicitly adding a NUL-terminator. Signed-

[PATCH v4 04/11] bpftool: Ensure task comm is always NUL-terminated

2024-07-28 Thread Yafang Shao
Let's explicitly ensure the destination string is NUL-terminated. This way, it won't be affected by changes to the source string. Signed-off-by: Yafang Shao Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/pids.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/bpf/bpftoo

[PATCH v4 03/11] security: Replace memcpy() with __get_task_comm()

2024-07-28 Thread Yafang Shao
facilitates future extensions to the task comm. Signed-off-by: Yafang Shao LINK: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npjoop8chlpefafv0onyt...@mail.gmail.com/ [0] Acked-by: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek ---

[PATCH v4 02/11] auditsc: Replace memcpy() with __get_task_comm()

2024-07-28 Thread Yafang Shao
Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Paul Moore Cc: Eric Paris --- kernel/auditsc.c | 6 +++--- 1

[PATCH v4 01/11] fs/exec: Drop task_lock() inside __get_task_comm()

2024-07-28 Thread Yafang Shao
could have long-term mixed results Suggested-by: Linus Torvalds Link: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npjoop8chlpefafv0onyt...@mail.gmail.com [0] Signed-off-by: Yafang Shao Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook Cc

[PATCH resend v4 00/11] Improve the copy of task comm

2024-07-28 Thread Yafang Shao
: https://lore.kernel.org/all/20240602023754.25443-1-laoar.s...@gmail.com/ Yafang Shao (11): fs/exec: Drop task_lock() inside __get_task_comm() auditsc: Replace memcpy() with __get_task_comm() security: Replace memcpy() with __get_task_comm() bpftool: Ensure task comm is always NUL

[PATCH v4 11/11] drm: Replace strcpy() with __get_task_comm()

2024-06-28 Thread Yafang Shao
To prevent erros from occurring when the src string is longer than the dst string in strcpy(), we should use __get_task_comm() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Daniel Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard

[PATCH v4 10/11] net: Replace strcpy() with __get_task_comm()

2024-06-28 Thread Yafang Shao
To prevent errors from occurring when the src string is longer than the dst string in strcpy(), we should use __get_task_comm() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: "David S. Miller" Cc: David Ahern Cc: Eric D

[PATCH v4 09/11] tracing: Replace strncpy() with __get_task_comm()

2024-06-28 Thread Yafang Shao
Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Masami Hiramatsu (Google) Cc: Steven Rostedt Cc: Mathieu

[PATCH v4 08/11] tsacct: Replace strncpy() with __get_task_comm()

2024-06-28 Thread Yafang Shao
Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao --- kernel/tsacct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion

[PATCH v4 07/11] mm/kmemleak: Replace strncpy() with __get_task_comm()

2024-06-28 Thread Yafang Shao
ff-by: Yafang Shao Acked-by: Catalin Marinas Cc: Andrew Morton --- mm/kmemleak.c | 8 +--- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index d5b6fba44fc9..ef29aaab88a0 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -663,13 +663,7 @@ static s

[PATCH v4 06/11] mm/util: Deduplicate code in {kstrdup, kstrndup, kmemdup_nul}

2024-06-28 Thread Yafang Shao
These three functions follow the same pattern. To deduplicate the code, let's introduce a common helper __kmemdup_nul(). Suggested-by: Andrew Morton Signed-off-by: Yafang Shao Cc: Simon Horman Cc: Matthew Wilcox --- mm/util.c | 67 +

[PATCH v4 05/11] mm/util: Fix possible race condition in kstrdup()

2024-06-28 Thread Yafang Shao
`s` might be updated by the writer to a new value of task->comm. If the new task->comm is larger than the old one, the `buf` might not be NUL-terminated. This can lead to undefined behavior and potential security vulnerabilities. Let's fix it by explicitly adding a NUL-terminator. Signed-

[PATCH v4 04/11] bpftool: Ensure task comm is always NUL-terminated

2024-06-28 Thread Yafang Shao
Let's explicitly ensure the destination string is NUL-terminated. This way, it won't be affected by changes to the source string. Signed-off-by: Yafang Shao Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/pids.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/bpf/bpftoo

[PATCH v4 03/11] security: Replace memcpy() with __get_task_comm()

2024-06-28 Thread Yafang Shao
facilitates future extensions to the task comm. Signed-off-by: Yafang Shao LINK: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npjoop8chlpefafv0onyt...@mail.gmail.com/ [0] Acked-by: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek ---

[PATCH v4 02/11] auditsc: Replace memcpy() with __get_task_comm()

2024-06-28 Thread Yafang Shao
Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Paul Moore Cc: Eric Paris --- kernel/auditsc.c | 6 +++--- 1

  1   2   >