libbpf: Fix potential misaligned memory access in btf_ext__new()
authorAndrii Nakryiko <andrii@kernel.org>
Wed, 24 Nov 2021 00:23:14 +0000 (16:23 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 10:03:16 +0000 (11:03 +0100)
commitf8ca67f3fc9e11a0faee67993991d105c6025835
tree87d7706b9085afdcd67ccc3eb0ea825bd008fcc9
parentae38d31443240ed5dfcebf71b9ca6c0528667896
libbpf: Fix potential misaligned memory access in btf_ext__new()

[ Upstream commit 401891a9debaf0a684502f2aaecf53448cee9414 ]

Perform a memory copy before we do the sanity checks of btf_ext_hdr.
This prevents misaligned memory access if raw btf_ext data is not 4-byte
aligned ([0]).

While at it, also add missing const qualifier.

  [0] Closes: https://github.com/libbpf/libbpf/issues/391

Fixes: 2993e0515bb4 ("tools/bpf: add support to read .BTF.ext sections")
Reported-by: Evgeny Vereshchagin <evvers@ya.ru>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20211124002325.1737739-3-andrii@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/btf.c
tools/lib/bpf/btf.h