Skip to content

Commit

Permalink
bpf: Allow all printable characters in BTF DATASEC names
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
eddyz87 authored and anakryiko committed Mar 6, 2024
1 parent 733e5e8 commit bd70a8f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion kernel/bpf/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,9 +809,23 @@ static bool btf_name_valid_identifier(const struct btf *btf, u32 offset)
return __btf_name_valid(btf, offset);
}

/* Allow any printable character in DATASEC names */
static bool btf_name_valid_section(const struct btf *btf, u32 offset)
{
return __btf_name_valid(btf, offset);
/* offset must be valid */
const char *src = btf_str_by_offset(btf, offset);
const char *src_limit;

/* set a limit on identifier length */
src_limit = src + KSYM_NAME_LEN;
src++;
while (*src && src < src_limit) {
if (!isprint(*src))
return false;
src++;
}

return !*src;
}

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

0 comments on commit bd70a8f

Please sign in to comment.