]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Avoid reading past ELF data section end when copying license
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 14 Dec 2021 23:20:54 +0000 (15:20 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 15 Dec 2021 05:59:33 +0000 (21:59 -0800)
commit5dd7442b76ada55e30097ecb95b8f93ed37c4d7a
tree6472b1652415cc9f7aee558e818b78e2c07cd366
parenta83a58fc4142ee194e55c0f3a172070a6078dc89
libbpf: Avoid reading past ELF data section end when copying license

Fix possible read beyond ELF "license" data section if the license
string is not properly zero-terminated. Use the fact that libbpf_strlcpy
never accesses the (N-1)st byte of the source string because it's
replaced with '\0' anyways.

If this happens, it's a violation of contract between libbpf and a user,
but not handling this more robustly upsets CIFuzz, so given the fix is
trivial, let's fix the potential issue.

Fixes: 7937bce132c9 ("libbpf: Add sane strncpy alternative and use it internally")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211214232054.3458774-1-andrii@kernel.org
tools/lib/bpf/libbpf.c