Skip to contentSkip to conversation

bpf: btf: Fix end boundary calculation for type section

PATCH Applied Martin KaFai Lau 3 participants 3 messages Sep 12, 2018 – Sep 13, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: btf: Fix end boundary calculation for type section

The end boundary math for type section is incorrect in btf_check_all_metas(). It just happens that hdr->type_off is always 0 for now because there are only two sections (type and string) and string section must be at the end (ensured in btf_parse_str_sec).

However, type_off may not be 0 if a new section would be added later. This patch fixes it.

Fixes f80442a4cd18 ("bpf: btf: Change how section is supported in btf_header")
---
 kernel/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/btf.c +1 -1
index 2590700237c1..138f0302692e 100644
@@ -1844,7 +1844,7 @@ static int btf_check_all_metas(struct btf_verifier_env *env)
 
 	hdr = &btf->hdr;
 	cur = btf->nohdr_data + hdr->type_off;
-	end = btf->nohdr_data + hdr->type_len;
+	end = cur + hdr->type_len;
 
 	env->log_type_id = 1;
 	while (cur < end) {
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Martin KaFai Lau

The end boundary math for type section is incorrect in btf_check_all_metas(). It just happens that hdr->type_off is always 0 for now because there are only two sections (type and string) and string section must be at the end (ensured in btf_parse_str_sec).

Quoted 6 lines

However, type_off may not be 0 if a new section would be added later. This patch fixes it.

Fixes f80442a4cd18 ("bpf: btf: Change how section is supported in btf_header")
Quoted 18 lines
---
  kernel/bpf/btf.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/btf.c +1 -1
index 2590700237c1..138f0302692e 100644
@@ -1844,7 +1844,7 @@ static int btf_check_all_metas(struct btf_verifier_env *env)
 
  	hdr = &btf->hdr;
  	cur = btf->nohdr_data + hdr->type_off;
-	end = btf->nohdr_data + hdr->type_len;
+	end = cur + hdr->type_len;
 
  	env->log_type_id = 1;
  	while (cur < end) {
maintainer Applied
#2 lore raw
In reply to Martin KaFai Lau
Quoted 6 lines · Martin KaFai Lau

The end boundary math for type section is incorrect in btf_check_all_metas(). It just happens that hdr->type_off is always 0 for now because there are only two sections (type and string) and string section must be at the end (ensured in btf_parse_str_sec).

Quoted 6 lines

However, type_off may not be 0 if a new section would be added later. This patch fixes it.

Fixes f80442a4cd18 ("bpf: btf: Change how section is supported in btf_header")

Applied to bpf, thanks everyone!