* [PATCH bpf] libbpf: sanitize VAR to conservative 1-byte INT
@ 2019-07-19 19:46 Andrii Nakryiko
2019-07-19 19:50 ` Alexei Starovoitov
0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2019-07-19 19:46 UTC (permalink / raw)
To: bpf, netdev, ast, daniel, rdna
Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko
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>
---
tools/lib/bpf/libbpf.c | 9 +++++++--
1 file 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);
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf] libbpf: sanitize VAR to conservative 1-byte INT
2019-07-19 19:46 [PATCH bpf] libbpf: sanitize VAR to conservative 1-byte INT Andrii Nakryiko
@ 2019-07-19 19:50 ` Alexei Starovoitov
0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2019-07-19 19:50 UTC (permalink / raw)
To: Andrii Nakryiko, bpf, netdev, daniel, Andrey Ignatov
Cc: andrii.nakryiko, Kernel Team
On 7/19/19 12:46 PM, Andrii Nakryiko wrote:
> 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>
Applied. Thanks
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-19 19:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-19 19:46 [PATCH bpf] libbpf: sanitize VAR to conservative 1-byte INT Andrii Nakryiko
2019-07-19 19:50 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).