Commit 1d4126c4 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

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: default avatarAndrii Nakryiko <andriin@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 04efe591
...@@ -1377,8 +1377,13 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj) ...@@ -1377,8 +1377,13 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj)
if (!has_datasec && kind == BTF_KIND_VAR) { if (!has_datasec && kind == BTF_KIND_VAR) {
/* replace VAR with INT */ /* replace VAR with INT */
t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0); 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) { } else if (!has_datasec && kind == BTF_KIND_DATASEC) {
/* replace DATASEC with STRUCT */ /* replace DATASEC with STRUCT */
struct btf_var_secinfo *v = (void *)(t + 1); struct btf_var_secinfo *v = (void *)(t + 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment