summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorAndrii Nakryiko2019-07-19 21:46:03 +0200
committerAlexei Starovoitov2019-07-19 21:48:55 +0200
commit1d4126c4e1190d2f7d3f388552f9bd17ae0c64fc (patch)
tree13ec1c89e1f4d94b40ac626d2eb2be5513d5eae8 /tools/lib
parentlibbpf: fix SIGSEGV when BTF loading fails, but .BTF.ext exists (diff)
downloadkernel-qcow2-linux-1d4126c4e1190d2f7d3f388552f9bd17ae0c64fc.tar.gz
kernel-qcow2-linux-1d4126c4e1190d2f7d3f388552f9bd17ae0c64fc.tar.xz
kernel-qcow2-linux-1d4126c4e1190d2f7d3f388552f9bd17ae0c64fc.zip
libbpf: sanitize VAR to conservative 1-byte INT
If VAR in non-sanitized BTF was size less than 4, converting such VAR into an INT with size=4 will cause BTF validation failure due to violationg of STRUCT (into which DATASEC was converted) member size. Fix by conservatively using size=1. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/libbpf.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 87168f21ef43..d8833ff6c4a1 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1377,8 +1377,13 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj)
if (!has_datasec && kind == BTF_KIND_VAR) {
/* replace VAR with INT */
t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0);
- t->size = sizeof(int);
- *(int *)(t+1) = BTF_INT_ENC(0, 0, 32);
+ /*
+ * using size = 1 is the safest choice, 4 will be too
+ * big and cause kernel BTF validation failure if
+ * original variable took less than 4 bytes
+ */
+ t->size = 1;
+ *(int *)(t+1) = BTF_INT_ENC(0, 0, 8);
} else if (!has_datasec && kind == BTF_KIND_DATASEC) {
/* replace DATASEC with STRUCT */
struct btf_var_secinfo *v = (void *)(t + 1);