hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/kernel/bpf/btf.c
....@@ -604,31 +604,30 @@
604604 offset < btf->hdr.str_len;
605605 }
606606
607
-static bool __btf_name_char_ok(char c, bool first, bool dot_ok)
607
+static bool __btf_name_char_ok(char c, bool first)
608608 {
609609 if ((first ? !isalpha(c) :
610610 !isalnum(c)) &&
611611 c != '_' &&
612
- ((c == '.' && !dot_ok) ||
613
- c != '.'))
612
+ c != '.')
614613 return false;
615614 return true;
616615 }
617616
618
-static bool __btf_name_valid(const struct btf *btf, u32 offset, bool dot_ok)
617
+static bool __btf_name_valid(const struct btf *btf, u32 offset)
619618 {
620619 /* offset must be valid */
621620 const char *src = &btf->strings[offset];
622621 const char *src_limit;
623622
624
- if (!__btf_name_char_ok(*src, true, dot_ok))
623
+ if (!__btf_name_char_ok(*src, true))
625624 return false;
626625
627626 /* set a limit on identifier length */
628627 src_limit = src + KSYM_NAME_LEN;
629628 src++;
630629 while (*src && src < src_limit) {
631
- if (!__btf_name_char_ok(*src, false, dot_ok))
630
+ if (!__btf_name_char_ok(*src, false))
632631 return false;
633632 src++;
634633 }
....@@ -636,17 +635,14 @@
636635 return !*src;
637636 }
638637
639
-/* Only C-style identifier is permitted. This can be relaxed if
640
- * necessary.
641
- */
642638 static bool btf_name_valid_identifier(const struct btf *btf, u32 offset)
643639 {
644
- return __btf_name_valid(btf, offset, false);
640
+ return __btf_name_valid(btf, offset);
645641 }
646642
647643 static bool btf_name_valid_section(const struct btf *btf, u32 offset)
648644 {
649
- return __btf_name_valid(btf, offset, true);
645
+ return __btf_name_valid(btf, offset);
650646 }
651647
652648 static const char *__btf_name_by_offset(const struct btf *btf, u32 offset)
....@@ -3417,7 +3413,7 @@
34173413 }
34183414
34193415 if (!t->name_off ||
3420
- !__btf_name_valid(env->btf, t->name_off, true)) {
3416
+ !__btf_name_valid(env->btf, t->name_off)) {
34213417 btf_verifier_log_type(env, t, "Invalid name");
34223418 return -EINVAL;
34233419 }
....@@ -3541,6 +3537,7 @@
35413537 struct btf *btf = env->btf;
35423538 u16 i;
35433539
3540
+ env->resolve_mode = RESOLVE_TBD;
35443541 for_each_vsi_from(i, v->next_member, v->t, vsi) {
35453542 u32 var_type_id = vsi->type, type_id, type_size = 0;
35463543 const struct btf_type *var_type = btf_type_by_id(env->btf,
....@@ -3673,6 +3670,11 @@
36733670 btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1);
36743671 err = -EINVAL;
36753672 break;
3673
+ }
3674
+
3675
+ if (btf_type_is_resolve_source_only(arg_type)) {
3676
+ btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1);
3677
+ return -EINVAL;
36763678 }
36773679
36783680 if (args[i].name_off &&
....@@ -4268,6 +4270,7 @@
42684270 if (!ctx_struct)
42694271 /* should not happen */
42704272 return NULL;
4273
+again:
42714274 ctx_tname = btf_name_by_offset(btf_vmlinux, ctx_struct->name_off);
42724275 if (!ctx_tname) {
42734276 /* should not happen */
....@@ -4281,8 +4284,16 @@
42814284 * int socket_filter_bpf_prog(struct __sk_buff *skb)
42824285 * { // no fields of skb are ever used }
42834286 */
4284
- if (strcmp(ctx_tname, tname))
4285
- return NULL;
4287
+ if (strcmp(ctx_tname, tname)) {
4288
+ /* bpf_user_pt_regs_t is a typedef, so resolve it to
4289
+ * underlying struct and check name again
4290
+ */
4291
+ if (!btf_type_is_modifier(ctx_struct))
4292
+ return NULL;
4293
+ while (btf_type_is_modifier(ctx_struct))
4294
+ ctx_struct = btf_type_by_id(btf_vmlinux, ctx_struct->type);
4295
+ goto again;
4296
+ }
42864297 return ctx_type;
42874298 }
42884299