Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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]. This is not
the case here, however, in an effort to remove strlcpy() completely [2],
lets replace strlcpy() here with strscpy(). No return values were used,
so a direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/bpf/20230530155659.309657-1-azeemshaikh38@gmail.com

authored by

Azeem Shaikh and committed by
Daniel Borkmann
ffadc372 0d2da4b5

+2 -2
+2 -2
kernel/bpf/preload/bpf_preload_kern.c
··· 23 23 24 24 static int preload(struct bpf_preload_info *obj) 25 25 { 26 - strlcpy(obj[0].link_name, "maps.debug", sizeof(obj[0].link_name)); 26 + strscpy(obj[0].link_name, "maps.debug", sizeof(obj[0].link_name)); 27 27 obj[0].link = maps_link; 28 - strlcpy(obj[1].link_name, "progs.debug", sizeof(obj[1].link_name)); 28 + strscpy(obj[1].link_name, "progs.debug", sizeof(obj[1].link_name)); 29 29 obj[1].link = progs_link; 30 30 return 0; 31 31 }