Skip to content

Commit bd70a8f

Browse files
eddyz87anakryiko
authored andcommitted
bpf: Allow all printable characters in BTF DATASEC names
The intent is to allow libbpf to use SEC("?.struct_ops") to identify struct_ops maps that are optional, e.g. like in the following BPF code: SEC("?.struct_ops") struct test_ops optional_map = { ... }; Which yields the following BTF: ... [13] DATASEC '?.struct_ops' size=0 vlen=... ... To load such BTF libbpf rewrites DATASEC name before load. After this patch the rewrite won't be necessary. Signed-off-by: Eduard Zingerman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 733e5e8 commit bd70a8f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

kernel/bpf/btf.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,23 @@ static bool btf_name_valid_identifier(const struct btf *btf, u32 offset)
809809
return __btf_name_valid(btf, offset);
810810
}
811811

812+
/* Allow any printable character in DATASEC names */
812813
static bool btf_name_valid_section(const struct btf *btf, u32 offset)
813814
{
814-
return __btf_name_valid(btf, offset);
815+
/* offset must be valid */
816+
const char *src = btf_str_by_offset(btf, offset);
817+
const char *src_limit;
818+
819+
/* set a limit on identifier length */
820+
src_limit = src + KSYM_NAME_LEN;
821+
src++;
822+
while (*src && src < src_limit) {
823+
if (!isprint(*src))
824+
return false;
825+
src++;
826+
}
827+
828+
return !*src;
815829
}
816830

817831
static const char *__btf_name_by_offset(const struct btf *btf, u32 offset)

0 commit comments

Comments
 (0)