bpf: Replace all non-returning strlcpy with strscpy
PATCH 1/1 bpf: Replace all non-returning strlcpy with strscpy
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89
--- kernel/bpf/preload/bpf_preload_kern.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/preload/bpf_preload_kern.c +2 -2
@@ -23,9 +23,9 @@ static void free_links_and_skel(void)static int preload (struct bpf_preload_info *obj) { -strlcpy (obj[0 ].link_name,"maps.debug" ,sizeof (obj[0 ].link_name)); +strscpy (obj[0 ].link_name,"maps.debug" ,sizeof (obj[0 ].link_name)); obj[0 ].link = maps_link; -strlcpy (obj[1 ].link_name,"progs.debug" ,sizeof (obj[1 ].link_name)); +strscpy (obj[1 ].link_name,"progs.debug" ,sizeof (obj[1 ].link_name)); obj[1 ].link = progs_link;return 0 ; }
Quoted 8 lines · Azeem Shaikh
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
No return values were used, so direct replacement is safe.
Quoted 4 lines
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89Signed-off-by Azeem Shaikh <[email protected]>
Signature · 1 line
Kees Cook
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 9 lines · On Tue, 30 May 2023 15:56:59 +0000 you wrote:
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
No return values were used, so direct replacement is safe.[...]
Here is the summary with links:
- bpf: Replace all non-returning strlcpy with strscpy
https://git.kernel.org/bpf/bpf-next/c/ffadc372529e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html