Skip to content

Commit 9724160

Browse files
FlorentRevestborkmann
authored andcommitted
bpf/btf: Accept function names that contain dots
When building a kernel with LLVM=1, LLVM_IAS=0 and CONFIG_KASAN=y, LLVM leaves DWARF tags for the "asan.module_ctor" & co symbols. In turn, pahole creates BTF_KIND_FUNC entries for these and this makes the BTF metadata validation fail because they contain a dot. In a dramatic turn of event, this BTF verification failure can cause the netfilter_bpf initialization to fail, causing netfilter_core to free the netfilter_helper hashmap and netfilter_ftp to trigger a use-after-free. The risk of u-a-f in netfilter will be addressed separately but the existence of "asan.module_ctor" debug info under some build conditions sounds like a good enough reason to accept functions that contain dots in BTF. Although using only LLVM=1 is the recommended way to compile clang-based kernels, users can certainly do LLVM=1, LLVM_IAS=0 as well and we still try to support that combination according to Nick. To clarify: - > v5.10 kernel, LLVM=1 (LLVM_IAS=0 is not the default) is recommended, but user can still have LLVM=1, LLVM_IAS=0 to trigger the issue - <= 5.10 kernel, LLVM=1 (LLVM_IAS=0 is the default) is recommended in which case GNU as will be used Fixes: 1dc9285 ("bpf: kernel side support for BTF Var and DataSec") Signed-off-by: Florent Revest <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Cc: Yonghong Song <[email protected]> Cc: Nick Desaulniers <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b78b34c commit 9724160

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

kernel/bpf/btf.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,12 @@ static bool btf_name_offset_valid(const struct btf *btf, u32 offset)
744744
return offset < btf->hdr.str_len;
745745
}
746746

747-
static bool __btf_name_char_ok(char c, bool first, bool dot_ok)
747+
static bool __btf_name_char_ok(char c, bool first)
748748
{
749749
if ((first ? !isalpha(c) :
750750
!isalnum(c)) &&
751751
c != '_' &&
752-
((c == '.' && !dot_ok) ||
753-
c != '.'))
752+
c != '.')
754753
return false;
755754
return true;
756755
}
@@ -767,38 +766,35 @@ static const char *btf_str_by_offset(const struct btf *btf, u32 offset)
767766
return NULL;
768767
}
769768

770-
static bool __btf_name_valid(const struct btf *btf, u32 offset, bool dot_ok)
769+
static bool __btf_name_valid(const struct btf *btf, u32 offset)
771770
{
772771
/* offset must be valid */
773772
const char *src = btf_str_by_offset(btf, offset);
774773
const char *src_limit;
775774

776-
if (!__btf_name_char_ok(*src, true, dot_ok))
775+
if (!__btf_name_char_ok(*src, true))
777776
return false;
778777

779778
/* set a limit on identifier length */
780779
src_limit = src + KSYM_NAME_LEN;
781780
src++;
782781
while (*src && src < src_limit) {
783-
if (!__btf_name_char_ok(*src, false, dot_ok))
782+
if (!__btf_name_char_ok(*src, false))
784783
return false;
785784
src++;
786785
}
787786

788787
return !*src;
789788
}
790789

791-
/* Only C-style identifier is permitted. This can be relaxed if
792-
* necessary.
793-
*/
794790
static bool btf_name_valid_identifier(const struct btf *btf, u32 offset)
795791
{
796-
return __btf_name_valid(btf, offset, false);
792+
return __btf_name_valid(btf, offset);
797793
}
798794

799795
static bool btf_name_valid_section(const struct btf *btf, u32 offset)
800796
{
801-
return __btf_name_valid(btf, offset, true);
797+
return __btf_name_valid(btf, offset);
802798
}
803799

804800
static const char *__btf_name_by_offset(const struct btf *btf, u32 offset)
@@ -4422,7 +4418,7 @@ static s32 btf_var_check_meta(struct btf_verifier_env *env,
44224418
}
44234419

44244420
if (!t->name_off ||
4425-
!__btf_name_valid(env->btf, t->name_off, true)) {
4421+
!__btf_name_valid(env->btf, t->name_off)) {
44264422
btf_verifier_log_type(env, t, "Invalid name");
44274423
return -EINVAL;
44284424
}

0 commit comments

Comments
 (0)