Lines Matching refs:env
407 s32 (*check_meta)(struct btf_verifier_env *env,
410 int (*resolve)(struct btf_verifier_env *env,
412 int (*check_member)(struct btf_verifier_env *env,
416 int (*check_kflag_member)(struct btf_verifier_env *env,
420 void (*log_details)(struct btf_verifier_env *env,
430 static int btf_resolve(struct btf_verifier_env *env,
433 static int btf_func_check(struct btf_verifier_env *env,
1377 __printf(2, 3) static void btf_verifier_log(struct btf_verifier_env *env, in btf_verifier_log() argument
1380 struct bpf_verifier_log *log = &env->log; in btf_verifier_log()
1391 __printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env, in __btf_verifier_log_type() argument
1396 struct bpf_verifier_log *log = &env->log; in __btf_verifier_log_type()
1397 struct btf *btf = env->btf; in __btf_verifier_log_type()
1412 if (env->btf->base_btf && IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) in __btf_verifier_log_type()
1417 env->log_type_id, in __btf_verifier_log_type()
1423 btf_type_ops(t)->log_details(env, t); in __btf_verifier_log_type()
1435 #define btf_verifier_log_type(env, t, ...) \ argument
1436 __btf_verifier_log_type((env), (t), true, __VA_ARGS__)
1437 #define btf_verifier_log_basic(env, t, ...) \ argument
1438 __btf_verifier_log_type((env), (t), false, __VA_ARGS__)
1441 static void btf_verifier_log_member(struct btf_verifier_env *env, in btf_verifier_log_member() argument
1446 struct bpf_verifier_log *log = &env->log; in btf_verifier_log_member()
1447 struct btf *btf = env->btf; in btf_verifier_log_member()
1458 if (env->btf->base_btf && IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) in btf_verifier_log_member()
1468 if (env->phase != CHECK_META) in btf_verifier_log_member()
1469 btf_verifier_log_type(env, struct_type, NULL); in btf_verifier_log_member()
1494 static void btf_verifier_log_vsi(struct btf_verifier_env *env, in btf_verifier_log_vsi() argument
1499 struct bpf_verifier_log *log = &env->log; in btf_verifier_log_vsi()
1506 if (env->phase != CHECK_META) in btf_verifier_log_vsi()
1507 btf_verifier_log_type(env, datasec_type, NULL); in btf_verifier_log_vsi()
1521 static void btf_verifier_log_hdr(struct btf_verifier_env *env, in btf_verifier_log_hdr() argument
1524 struct bpf_verifier_log *log = &env->log; in btf_verifier_log_hdr()
1525 const struct btf *btf = env->btf; in btf_verifier_log_hdr()
1545 static int btf_add_type(struct btf_verifier_env *env, struct btf_type *t) in btf_add_type() argument
1547 struct btf *btf = env->btf; in btf_add_type()
1556 btf_verifier_log(env, "Exceeded max num of types"); in btf_add_type()
1686 static int env_resolve_init(struct btf_verifier_env *env) in env_resolve_init() argument
1688 struct btf *btf = env->btf; in env_resolve_init()
1711 env->visit_states = visit_states; in env_resolve_init()
1722 static void btf_verifier_env_free(struct btf_verifier_env *env) in btf_verifier_env_free() argument
1724 kvfree(env->visit_states); in btf_verifier_env_free()
1725 kfree(env); in btf_verifier_env_free()
1728 static bool env_type_is_resolve_sink(const struct btf_verifier_env *env, in env_type_is_resolve_sink() argument
1731 switch (env->resolve_mode) { in env_type_is_resolve_sink()
1753 static bool env_type_is_resolved(const struct btf_verifier_env *env, in env_type_is_resolved() argument
1757 if (type_id < env->btf->start_id) in env_type_is_resolved()
1760 return env->visit_states[type_id - env->btf->start_id] == RESOLVED; in env_type_is_resolved()
1763 static int env_stack_push(struct btf_verifier_env *env, in env_stack_push() argument
1766 const struct btf *btf = env->btf; in env_stack_push()
1769 if (env->top_stack == MAX_RESOLVE_DEPTH) in env_stack_push()
1773 || env->visit_states[type_id - btf->start_id] != NOT_VISITED) in env_stack_push()
1776 env->visit_states[type_id - btf->start_id] = VISITED; in env_stack_push()
1778 v = &env->stack[env->top_stack++]; in env_stack_push()
1783 if (env->resolve_mode == RESOLVE_TBD) { in env_stack_push()
1785 env->resolve_mode = RESOLVE_PTR; in env_stack_push()
1787 env->resolve_mode = RESOLVE_STRUCT_OR_ARRAY; in env_stack_push()
1793 static void env_stack_set_next_member(struct btf_verifier_env *env, in env_stack_set_next_member() argument
1796 env->stack[env->top_stack - 1].next_member = next_member; in env_stack_set_next_member()
1799 static void env_stack_pop_resolved(struct btf_verifier_env *env, in env_stack_pop_resolved() argument
1803 u32 type_id = env->stack[--(env->top_stack)].type_id; in env_stack_pop_resolved()
1804 struct btf *btf = env->btf; in env_stack_pop_resolved()
1809 env->visit_states[type_id] = RESOLVED; in env_stack_pop_resolved()
1812 static const struct resolve_vertex *env_stack_peak(struct btf_verifier_env *env) in env_stack_peak() argument
1814 return env->top_stack ? &env->stack[env->top_stack - 1] : NULL; in env_stack_peak()
1981 static int btf_df_check_member(struct btf_verifier_env *env, in btf_df_check_member() argument
1986 btf_verifier_log_basic(env, struct_type, in btf_df_check_member()
1991 static int btf_df_check_kflag_member(struct btf_verifier_env *env, in btf_df_check_kflag_member() argument
1996 btf_verifier_log_basic(env, struct_type, in btf_df_check_kflag_member()
2004 static int btf_generic_check_kflag_member(struct btf_verifier_env *env, in btf_generic_check_kflag_member() argument
2010 btf_verifier_log_member(env, struct_type, member, in btf_generic_check_kflag_member()
2018 return btf_type_ops(member_type)->check_member(env, struct_type, in btf_generic_check_kflag_member()
2023 static int btf_df_resolve(struct btf_verifier_env *env, in btf_df_resolve() argument
2026 btf_verifier_log_basic(env, v->t, "Unsupported resolve"); in btf_df_resolve()
2037 static int btf_int_check_member(struct btf_verifier_env *env, in btf_int_check_member() argument
2049 btf_verifier_log_member(env, struct_type, member, in btf_int_check_member()
2060 btf_verifier_log_member(env, struct_type, member, in btf_int_check_member()
2067 btf_verifier_log_member(env, struct_type, member, in btf_int_check_member()
2075 static int btf_int_check_kflag_member(struct btf_verifier_env *env, in btf_int_check_kflag_member() argument
2087 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2101 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2108 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2116 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2123 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2131 static s32 btf_int_check_meta(struct btf_verifier_env *env, in btf_int_check_meta() argument
2139 btf_verifier_log_basic(env, t, in btf_int_check_meta()
2146 btf_verifier_log_type(env, t, "vlen != 0"); in btf_int_check_meta()
2151 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_int_check_meta()
2157 btf_verifier_log_basic(env, t, "Invalid int_data:%x", in btf_int_check_meta()
2165 btf_verifier_log_type(env, t, "nr_bits exceeds %zu", in btf_int_check_meta()
2171 btf_verifier_log_type(env, t, "nr_bits exceeds type_size"); in btf_int_check_meta()
2186 btf_verifier_log_type(env, t, "Unsupported encoding"); in btf_int_check_meta()
2190 btf_verifier_log_type(env, t, NULL); in btf_int_check_meta()
2195 static void btf_int_log(struct btf_verifier_env *env, in btf_int_log() argument
2200 btf_verifier_log(env, in btf_int_log()
2396 static int btf_modifier_check_member(struct btf_verifier_env *env, in btf_modifier_check_member() argument
2404 struct btf *btf = env->btf; in btf_modifier_check_member()
2408 btf_verifier_log_member(env, struct_type, member, in btf_modifier_check_member()
2416 return btf_type_ops(resolved_type)->check_member(env, struct_type, in btf_modifier_check_member()
2421 static int btf_modifier_check_kflag_member(struct btf_verifier_env *env, in btf_modifier_check_kflag_member() argument
2429 struct btf *btf = env->btf; in btf_modifier_check_kflag_member()
2433 btf_verifier_log_member(env, struct_type, member, in btf_modifier_check_kflag_member()
2441 return btf_type_ops(resolved_type)->check_kflag_member(env, struct_type, in btf_modifier_check_kflag_member()
2446 static int btf_ptr_check_member(struct btf_verifier_env *env, in btf_ptr_check_member() argument
2458 btf_verifier_log_member(env, struct_type, member, in btf_ptr_check_member()
2464 btf_verifier_log_member(env, struct_type, member, in btf_ptr_check_member()
2472 static int btf_ref_type_check_meta(struct btf_verifier_env *env, in btf_ref_type_check_meta() argument
2479 btf_verifier_log_type(env, t, "vlen != 0"); in btf_ref_type_check_meta()
2484 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_ref_type_check_meta()
2489 btf_verifier_log_type(env, t, "Invalid type_id"); in btf_ref_type_check_meta()
2498 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_ref_type_check_meta()
2499 btf_verifier_log_type(env, t, "Invalid name"); in btf_ref_type_check_meta()
2503 value = btf_name_by_offset(env->btf, t->name_off); in btf_ref_type_check_meta()
2505 btf_verifier_log_type(env, t, "Invalid name"); in btf_ref_type_check_meta()
2510 btf_verifier_log_type(env, t, "Invalid name"); in btf_ref_type_check_meta()
2515 btf_verifier_log_type(env, t, NULL); in btf_ref_type_check_meta()
2520 static int btf_modifier_resolve(struct btf_verifier_env *env, in btf_modifier_resolve() argument
2526 struct btf *btf = env->btf; in btf_modifier_resolve()
2530 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_modifier_resolve()
2534 if (!env_type_is_resolve_sink(env, next_type) && in btf_modifier_resolve()
2535 !env_type_is_resolved(env, next_type_id)) in btf_modifier_resolve()
2536 return env_stack_push(env, next_type, next_type_id); in btf_modifier_resolve()
2545 if (env_type_is_resolved(env, next_type_id)) in btf_modifier_resolve()
2552 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_modifier_resolve()
2557 env_stack_pop_resolved(env, next_type_id, 0); in btf_modifier_resolve()
2562 static int btf_var_resolve(struct btf_verifier_env *env, in btf_var_resolve() argument
2568 struct btf *btf = env->btf; in btf_var_resolve()
2572 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_var_resolve()
2576 if (!env_type_is_resolve_sink(env, next_type) && in btf_var_resolve()
2577 !env_type_is_resolved(env, next_type_id)) in btf_var_resolve()
2578 return env_stack_push(env, next_type, next_type_id); in btf_var_resolve()
2588 !env_type_is_resolve_sink(env, resolved_type) && in btf_var_resolve()
2589 !env_type_is_resolved(env, resolved_type_id)) in btf_var_resolve()
2590 return env_stack_push(env, resolved_type, in btf_var_resolve()
2599 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_var_resolve()
2603 env_stack_pop_resolved(env, next_type_id, 0); in btf_var_resolve()
2608 static int btf_ptr_resolve(struct btf_verifier_env *env, in btf_ptr_resolve() argument
2614 struct btf *btf = env->btf; in btf_ptr_resolve()
2618 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_ptr_resolve()
2622 if (!env_type_is_resolve_sink(env, next_type) && in btf_ptr_resolve()
2623 !env_type_is_resolved(env, next_type_id)) in btf_ptr_resolve()
2624 return env_stack_push(env, next_type, next_type_id); in btf_ptr_resolve()
2642 !env_type_is_resolve_sink(env, resolved_type) && in btf_ptr_resolve()
2643 !env_type_is_resolved(env, resolved_type_id)) in btf_ptr_resolve()
2644 return env_stack_push(env, resolved_type, in btf_ptr_resolve()
2649 if (env_type_is_resolved(env, next_type_id)) in btf_ptr_resolve()
2655 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_ptr_resolve()
2660 env_stack_pop_resolved(env, next_type_id, 0); in btf_ptr_resolve()
2705 static void btf_ref_type_log(struct btf_verifier_env *env, in btf_ref_type_log() argument
2708 btf_verifier_log(env, "type_id=%u", t->type); in btf_ref_type_log()
2729 static s32 btf_fwd_check_meta(struct btf_verifier_env *env, in btf_fwd_check_meta() argument
2734 btf_verifier_log_type(env, t, "vlen != 0"); in btf_fwd_check_meta()
2739 btf_verifier_log_type(env, t, "type != 0"); in btf_fwd_check_meta()
2745 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_fwd_check_meta()
2746 btf_verifier_log_type(env, t, "Invalid name"); in btf_fwd_check_meta()
2750 btf_verifier_log_type(env, t, NULL); in btf_fwd_check_meta()
2755 static void btf_fwd_type_log(struct btf_verifier_env *env, in btf_fwd_type_log() argument
2758 btf_verifier_log(env, "%s", btf_type_kflag(t) ? "union" : "struct"); in btf_fwd_type_log()
2770 static int btf_array_check_member(struct btf_verifier_env *env, in btf_array_check_member() argument
2778 struct btf *btf = env->btf; in btf_array_check_member()
2781 btf_verifier_log_member(env, struct_type, member, in btf_array_check_member()
2791 btf_verifier_log_member(env, struct_type, member, in btf_array_check_member()
2799 static s32 btf_array_check_meta(struct btf_verifier_env *env, in btf_array_check_meta() argument
2807 btf_verifier_log_basic(env, t, in btf_array_check_meta()
2815 btf_verifier_log_type(env, t, "Invalid name"); in btf_array_check_meta()
2820 btf_verifier_log_type(env, t, "vlen != 0"); in btf_array_check_meta()
2825 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_array_check_meta()
2830 btf_verifier_log_type(env, t, "size != 0"); in btf_array_check_meta()
2838 btf_verifier_log_type(env, t, "Invalid elem"); in btf_array_check_meta()
2843 btf_verifier_log_type(env, t, "Invalid index"); in btf_array_check_meta()
2847 btf_verifier_log_type(env, t, NULL); in btf_array_check_meta()
2852 static int btf_array_resolve(struct btf_verifier_env *env, in btf_array_resolve() argument
2858 struct btf *btf = env->btf; in btf_array_resolve()
2866 btf_verifier_log_type(env, v->t, "Invalid index"); in btf_array_resolve()
2870 if (!env_type_is_resolve_sink(env, index_type) && in btf_array_resolve()
2871 !env_type_is_resolved(env, index_type_id)) in btf_array_resolve()
2872 return env_stack_push(env, index_type, index_type_id); in btf_array_resolve()
2877 btf_verifier_log_type(env, v->t, "Invalid index"); in btf_array_resolve()
2886 btf_verifier_log_type(env, v->t, in btf_array_resolve()
2891 if (!env_type_is_resolve_sink(env, elem_type) && in btf_array_resolve()
2892 !env_type_is_resolved(env, elem_type_id)) in btf_array_resolve()
2893 return env_stack_push(env, elem_type, elem_type_id); in btf_array_resolve()
2897 btf_verifier_log_type(env, v->t, "Invalid elem"); in btf_array_resolve()
2902 btf_verifier_log_type(env, v->t, "Invalid array of int"); in btf_array_resolve()
2907 btf_verifier_log_type(env, v->t, in btf_array_resolve()
2912 env_stack_pop_resolved(env, elem_type_id, elem_size * array->nelems); in btf_array_resolve()
2917 static void btf_array_log(struct btf_verifier_env *env, in btf_array_log() argument
2922 btf_verifier_log(env, "type_id=%u index_type_id=%u nr_elems=%u", in btf_array_log()
3021 static int btf_struct_check_member(struct btf_verifier_env *env, in btf_struct_check_member() argument
3030 btf_verifier_log_member(env, struct_type, member, in btf_struct_check_member()
3038 btf_verifier_log_member(env, struct_type, member, in btf_struct_check_member()
3046 static s32 btf_struct_check_meta(struct btf_verifier_env *env, in btf_struct_check_meta() argument
3053 struct btf *btf = env->btf; in btf_struct_check_meta()
3060 btf_verifier_log_basic(env, t, in btf_struct_check_meta()
3068 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_struct_check_meta()
3069 btf_verifier_log_type(env, t, "Invalid name"); in btf_struct_check_meta()
3073 btf_verifier_log_type(env, t, NULL); in btf_struct_check_meta()
3078 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3087 btf_verifier_log_member(env, t, member, "Invalid name"); in btf_struct_check_meta()
3092 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3099 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3109 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3115 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3120 btf_verifier_log_member(env, t, member, NULL); in btf_struct_check_meta()
3127 static int btf_struct_resolve(struct btf_verifier_env *env, in btf_struct_resolve() argument
3145 if (WARN_ON_ONCE(!env_type_is_resolved(env, in btf_struct_resolve()
3149 last_member_type = btf_type_by_id(env->btf, in btf_struct_resolve()
3152 err = btf_type_ops(last_member_type)->check_kflag_member(env, v->t, in btf_struct_resolve()
3156 err = btf_type_ops(last_member_type)->check_member(env, v->t, in btf_struct_resolve()
3165 const struct btf_type *member_type = btf_type_by_id(env->btf, in btf_struct_resolve()
3170 btf_verifier_log_member(env, v->t, member, in btf_struct_resolve()
3175 if (!env_type_is_resolve_sink(env, member_type) && in btf_struct_resolve()
3176 !env_type_is_resolved(env, member_type_id)) { in btf_struct_resolve()
3177 env_stack_set_next_member(env, i + 1); in btf_struct_resolve()
3178 return env_stack_push(env, member_type, member_type_id); in btf_struct_resolve()
3182 err = btf_type_ops(member_type)->check_kflag_member(env, v->t, in btf_struct_resolve()
3186 err = btf_type_ops(member_type)->check_member(env, v->t, in btf_struct_resolve()
3193 env_stack_pop_resolved(env, 0, 0); in btf_struct_resolve()
3198 static void btf_struct_log(struct btf_verifier_env *env, in btf_struct_log() argument
3201 btf_verifier_log(env, "size=%u vlen=%u", t->size, btf_type_vlen(t)); in btf_struct_log()
3625 static int btf_enum_check_member(struct btf_verifier_env *env, in btf_enum_check_member() argument
3634 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_member()
3642 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_member()
3650 static int btf_enum_check_kflag_member(struct btf_verifier_env *env, in btf_enum_check_kflag_member() argument
3662 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_kflag_member()
3669 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_kflag_member()
3677 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_kflag_member()
3685 static s32 btf_enum_check_meta(struct btf_verifier_env *env, in btf_enum_check_meta() argument
3690 struct btf *btf = env->btf; in btf_enum_check_meta()
3699 btf_verifier_log_basic(env, t, in btf_enum_check_meta()
3706 btf_verifier_log_type(env, t, "Unexpected size"); in btf_enum_check_meta()
3712 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_enum_check_meta()
3713 btf_verifier_log_type(env, t, "Invalid name"); in btf_enum_check_meta()
3717 btf_verifier_log_type(env, t, NULL); in btf_enum_check_meta()
3721 btf_verifier_log(env, "\tInvalid name_offset:%u", in btf_enum_check_meta()
3729 btf_verifier_log_type(env, t, "Invalid name"); in btf_enum_check_meta()
3733 if (env->log.level == BPF_LOG_KERNEL) in btf_enum_check_meta()
3736 btf_verifier_log(env, fmt_str, in btf_enum_check_meta()
3744 static void btf_enum_log(struct btf_verifier_env *env, in btf_enum_log() argument
3747 btf_verifier_log(env, "size=%u vlen=%u", t->size, btf_type_vlen(t)); in btf_enum_log()
3793 static s32 btf_enum64_check_meta(struct btf_verifier_env *env, in btf_enum64_check_meta() argument
3798 struct btf *btf = env->btf; in btf_enum64_check_meta()
3807 btf_verifier_log_basic(env, t, in btf_enum64_check_meta()
3814 btf_verifier_log_type(env, t, "Unexpected size"); in btf_enum64_check_meta()
3820 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_enum64_check_meta()
3821 btf_verifier_log_type(env, t, "Invalid name"); in btf_enum64_check_meta()
3825 btf_verifier_log_type(env, t, NULL); in btf_enum64_check_meta()
3829 btf_verifier_log(env, "\tInvalid name_offset:%u", in btf_enum64_check_meta()
3837 btf_verifier_log_type(env, t, "Invalid name"); in btf_enum64_check_meta()
3841 if (env->log.level == BPF_LOG_KERNEL) in btf_enum64_check_meta()
3845 btf_verifier_log(env, fmt_str, in btf_enum64_check_meta()
3896 static s32 btf_func_proto_check_meta(struct btf_verifier_env *env, in btf_func_proto_check_meta() argument
3903 btf_verifier_log_basic(env, t, in btf_func_proto_check_meta()
3910 btf_verifier_log_type(env, t, "Invalid name"); in btf_func_proto_check_meta()
3915 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_func_proto_check_meta()
3919 btf_verifier_log_type(env, t, NULL); in btf_func_proto_check_meta()
3924 static void btf_func_proto_log(struct btf_verifier_env *env, in btf_func_proto_log() argument
3930 btf_verifier_log(env, "return=%u args=(", t->type); in btf_func_proto_log()
3932 btf_verifier_log(env, "void"); in btf_func_proto_log()
3938 btf_verifier_log(env, "vararg"); in btf_func_proto_log()
3942 btf_verifier_log(env, "%u %s", args[0].type, in btf_func_proto_log()
3943 __btf_name_by_offset(env->btf, in btf_func_proto_log()
3946 btf_verifier_log(env, ", %u %s", args[i].type, in btf_func_proto_log()
3947 __btf_name_by_offset(env->btf, in btf_func_proto_log()
3954 btf_verifier_log(env, ", %u %s", last_arg->type, in btf_func_proto_log()
3955 __btf_name_by_offset(env->btf, in btf_func_proto_log()
3958 btf_verifier_log(env, ", vararg"); in btf_func_proto_log()
3962 btf_verifier_log(env, ")"); in btf_func_proto_log()
3983 static s32 btf_func_check_meta(struct btf_verifier_env *env, in btf_func_check_meta() argument
3988 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_func_check_meta()
3989 btf_verifier_log_type(env, t, "Invalid name"); in btf_func_check_meta()
3994 btf_verifier_log_type(env, t, "Invalid func linkage"); in btf_func_check_meta()
3999 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_func_check_meta()
4003 btf_verifier_log_type(env, t, NULL); in btf_func_check_meta()
4008 static int btf_func_resolve(struct btf_verifier_env *env, in btf_func_resolve() argument
4015 err = btf_func_check(env, t); in btf_func_resolve()
4019 env_stack_pop_resolved(env, next_type_id, 0); in btf_func_resolve()
4032 static s32 btf_var_check_meta(struct btf_verifier_env *env, in btf_var_check_meta() argument
4040 btf_verifier_log_basic(env, t, in btf_var_check_meta()
4047 btf_verifier_log_type(env, t, "vlen != 0"); in btf_var_check_meta()
4052 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_var_check_meta()
4057 !__btf_name_valid(env->btf, t->name_off)) { in btf_var_check_meta()
4058 btf_verifier_log_type(env, t, "Invalid name"); in btf_var_check_meta()
4064 btf_verifier_log_type(env, t, "Invalid type_id"); in btf_var_check_meta()
4071 btf_verifier_log_type(env, t, "Linkage not supported"); in btf_var_check_meta()
4075 btf_verifier_log_type(env, t, NULL); in btf_var_check_meta()
4080 static void btf_var_log(struct btf_verifier_env *env, const struct btf_type *t) in btf_var_log() argument
4084 btf_verifier_log(env, "type_id=%u linkage=%u", t->type, var->linkage); in btf_var_log()
4096 static s32 btf_datasec_check_meta(struct btf_verifier_env *env, in btf_datasec_check_meta() argument
4106 btf_verifier_log_basic(env, t, in btf_datasec_check_meta()
4113 btf_verifier_log_type(env, t, "size == 0"); in btf_datasec_check_meta()
4118 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_datasec_check_meta()
4123 !btf_name_valid_section(env->btf, t->name_off)) { in btf_datasec_check_meta()
4124 btf_verifier_log_type(env, t, "Invalid name"); in btf_datasec_check_meta()
4128 btf_verifier_log_type(env, t, NULL); in btf_datasec_check_meta()
4133 btf_verifier_log_vsi(env, t, vsi, in btf_datasec_check_meta()
4139 btf_verifier_log_vsi(env, t, vsi, in btf_datasec_check_meta()
4145 btf_verifier_log_vsi(env, t, vsi, in btf_datasec_check_meta()
4152 btf_verifier_log_vsi(env, t, vsi, in btf_datasec_check_meta()
4157 btf_verifier_log_vsi(env, t, vsi, NULL); in btf_datasec_check_meta()
4162 btf_verifier_log_type(env, t, "Invalid btf_info size"); in btf_datasec_check_meta()
4169 static int btf_datasec_resolve(struct btf_verifier_env *env, in btf_datasec_resolve() argument
4173 struct btf *btf = env->btf; in btf_datasec_resolve()
4176 env->resolve_mode = RESOLVE_TBD; in btf_datasec_resolve()
4179 const struct btf_type *var_type = btf_type_by_id(env->btf, in btf_datasec_resolve()
4182 btf_verifier_log_vsi(env, v->t, vsi, in btf_datasec_resolve()
4187 if (!env_type_is_resolve_sink(env, var_type) && in btf_datasec_resolve()
4188 !env_type_is_resolved(env, var_type_id)) { in btf_datasec_resolve()
4189 env_stack_set_next_member(env, i + 1); in btf_datasec_resolve()
4190 return env_stack_push(env, var_type, var_type_id); in btf_datasec_resolve()
4195 btf_verifier_log_vsi(env, v->t, vsi, "Invalid type"); in btf_datasec_resolve()
4200 btf_verifier_log_vsi(env, v->t, vsi, "Invalid size"); in btf_datasec_resolve()
4205 env_stack_pop_resolved(env, 0, 0); in btf_datasec_resolve()
4209 static void btf_datasec_log(struct btf_verifier_env *env, in btf_datasec_log() argument
4212 btf_verifier_log(env, "size=%u vlen=%u", t->size, btf_type_vlen(t)); in btf_datasec_log()
4248 static s32 btf_float_check_meta(struct btf_verifier_env *env, in btf_float_check_meta() argument
4253 btf_verifier_log_type(env, t, "vlen != 0"); in btf_float_check_meta()
4258 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_float_check_meta()
4264 btf_verifier_log_type(env, t, "Invalid type_size"); in btf_float_check_meta()
4268 btf_verifier_log_type(env, t, NULL); in btf_float_check_meta()
4273 static int btf_float_check_member(struct btf_verifier_env *env, in btf_float_check_member() argument
4292 btf_verifier_log_member(env, struct_type, member, in btf_float_check_member()
4300 btf_verifier_log_member(env, struct_type, member, in btf_float_check_member()
4308 static void btf_float_log(struct btf_verifier_env *env, in btf_float_log() argument
4311 btf_verifier_log(env, "size=%u", t->size); in btf_float_log()
4323 static s32 btf_decl_tag_check_meta(struct btf_verifier_env *env, in btf_decl_tag_check_meta() argument
4333 btf_verifier_log_basic(env, t, in btf_decl_tag_check_meta()
4339 value = btf_name_by_offset(env->btf, t->name_off); in btf_decl_tag_check_meta()
4341 btf_verifier_log_type(env, t, "Invalid value"); in btf_decl_tag_check_meta()
4346 btf_verifier_log_type(env, t, "vlen != 0"); in btf_decl_tag_check_meta()
4351 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_decl_tag_check_meta()
4357 btf_verifier_log_type(env, t, "Invalid component_idx"); in btf_decl_tag_check_meta()
4361 btf_verifier_log_type(env, t, NULL); in btf_decl_tag_check_meta()
4366 static int btf_decl_tag_resolve(struct btf_verifier_env *env, in btf_decl_tag_resolve() argument
4372 struct btf *btf = env->btf; in btf_decl_tag_resolve()
4378 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_decl_tag_resolve()
4382 if (!env_type_is_resolve_sink(env, next_type) && in btf_decl_tag_resolve()
4383 !env_type_is_resolved(env, next_type_id)) in btf_decl_tag_resolve()
4384 return env_stack_push(env, next_type, next_type_id); in btf_decl_tag_resolve()
4389 btf_verifier_log_type(env, v->t, "Invalid component_idx"); in btf_decl_tag_resolve()
4402 btf_verifier_log_type(env, v->t, "Invalid component_idx"); in btf_decl_tag_resolve()
4407 env_stack_pop_resolved(env, next_type_id, 0); in btf_decl_tag_resolve()
4412 static void btf_decl_tag_log(struct btf_verifier_env *env, const struct btf_type *t) in btf_decl_tag_log() argument
4414 btf_verifier_log(env, "type=%u component_idx=%d", t->type, in btf_decl_tag_log()
4427 static int btf_func_proto_check(struct btf_verifier_env *env, in btf_func_proto_check() argument
4436 btf = env->btf; in btf_func_proto_check()
4446 btf_verifier_log_type(env, t, "Invalid return type"); in btf_func_proto_check()
4451 btf_verifier_log_type(env, t, "Invalid return type"); in btf_func_proto_check()
4456 !env_type_is_resolved(env, ret_type_id)) { in btf_func_proto_check()
4457 err = btf_resolve(env, ret_type, ret_type_id); in btf_func_proto_check()
4464 btf_verifier_log_type(env, t, "Invalid return type"); in btf_func_proto_check()
4475 btf_verifier_log_type(env, t, "Invalid arg#%u", in btf_func_proto_check()
4490 btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1); in btf_func_proto_check()
4496 btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1); in btf_func_proto_check()
4503 btf_verifier_log_type(env, t, in btf_func_proto_check()
4510 !env_type_is_resolved(env, arg_type_id)) { in btf_func_proto_check()
4511 err = btf_resolve(env, arg_type, arg_type_id); in btf_func_proto_check()
4517 btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1); in btf_func_proto_check()
4526 static int btf_func_check(struct btf_verifier_env *env, in btf_func_check() argument
4534 btf = env->btf; in btf_func_check()
4538 btf_verifier_log_type(env, t, "Invalid type_id"); in btf_func_check()
4546 btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1); in btf_func_check()
4576 static s32 btf_check_meta(struct btf_verifier_env *env, in btf_check_meta() argument
4584 btf_verifier_log(env, "[%u] meta_left:%u meta_needed:%zu", in btf_check_meta()
4585 env->log_type_id, meta_left, sizeof(*t)); in btf_check_meta()
4591 btf_verifier_log(env, "[%u] Invalid btf_info:%x", in btf_check_meta()
4592 env->log_type_id, t->info); in btf_check_meta()
4598 btf_verifier_log(env, "[%u] Invalid kind:%u", in btf_check_meta()
4599 env->log_type_id, BTF_INFO_KIND(t->info)); in btf_check_meta()
4603 if (!btf_name_offset_valid(env->btf, t->name_off)) { in btf_check_meta()
4604 btf_verifier_log(env, "[%u] Invalid name_offset:%u", in btf_check_meta()
4605 env->log_type_id, t->name_off); in btf_check_meta()
4609 var_meta_size = btf_type_ops(t)->check_meta(env, t, meta_left); in btf_check_meta()
4618 static int btf_check_all_metas(struct btf_verifier_env *env) in btf_check_all_metas() argument
4620 struct btf *btf = env->btf; in btf_check_all_metas()
4628 env->log_type_id = btf->base_btf ? btf->start_id : 1; in btf_check_all_metas()
4633 meta_size = btf_check_meta(env, t, end - cur); in btf_check_all_metas()
4637 btf_add_type(env, t); in btf_check_all_metas()
4639 env->log_type_id++; in btf_check_all_metas()
4645 static bool btf_resolve_valid(struct btf_verifier_env *env, in btf_resolve_valid() argument
4649 struct btf *btf = env->btf; in btf_resolve_valid()
4651 if (!env_type_is_resolved(env, type_id)) in btf_resolve_valid()
4686 static int btf_resolve(struct btf_verifier_env *env, in btf_resolve() argument
4689 u32 save_log_type_id = env->log_type_id; in btf_resolve()
4693 env->resolve_mode = RESOLVE_TBD; in btf_resolve()
4694 env_stack_push(env, t, type_id); in btf_resolve()
4695 while (!err && (v = env_stack_peak(env))) { in btf_resolve()
4696 env->log_type_id = v->type_id; in btf_resolve()
4697 err = btf_type_ops(v->t)->resolve(env, v); in btf_resolve()
4700 env->log_type_id = type_id; in btf_resolve()
4702 btf_verifier_log_type(env, t, in btf_resolve()
4706 btf_verifier_log_type(env, t, "Loop detected"); in btf_resolve()
4710 if (!err && !btf_resolve_valid(env, t, type_id)) { in btf_resolve()
4711 btf_verifier_log_type(env, t, "Invalid resolve state"); in btf_resolve()
4715 env->log_type_id = save_log_type_id; in btf_resolve()
4719 static int btf_check_all_types(struct btf_verifier_env *env) in btf_check_all_types() argument
4721 struct btf *btf = env->btf; in btf_check_all_types()
4726 err = env_resolve_init(env); in btf_check_all_types()
4730 env->phase++; in btf_check_all_types()
4735 env->log_type_id = type_id; in btf_check_all_types()
4737 !env_type_is_resolved(env, type_id)) { in btf_check_all_types()
4738 err = btf_resolve(env, t, type_id); in btf_check_all_types()
4744 err = btf_func_proto_check(env, t); in btf_check_all_types()
4753 static int btf_parse_type_sec(struct btf_verifier_env *env) in btf_parse_type_sec() argument
4755 const struct btf_header *hdr = &env->btf->hdr; in btf_parse_type_sec()
4760 btf_verifier_log(env, "Unaligned type_off"); in btf_parse_type_sec()
4764 if (!env->btf->base_btf && !hdr->type_len) { in btf_parse_type_sec()
4765 btf_verifier_log(env, "No type found"); in btf_parse_type_sec()
4769 err = btf_check_all_metas(env); in btf_parse_type_sec()
4773 return btf_check_all_types(env); in btf_parse_type_sec()
4776 static int btf_parse_str_sec(struct btf_verifier_env *env) in btf_parse_str_sec() argument
4779 struct btf *btf = env->btf; in btf_parse_str_sec()
4787 btf_verifier_log(env, "String section is not at the end"); in btf_parse_str_sec()
4796 btf_verifier_log(env, "Invalid string section"); in btf_parse_str_sec()
4800 btf_verifier_log(env, "Invalid string section"); in btf_parse_str_sec()
4820 static int btf_check_sec_info(struct btf_verifier_env *env, in btf_check_sec_info() argument
4828 btf = env->btf; in btf_check_sec_info()
4844 btf_verifier_log(env, "Invalid section offset"); in btf_check_sec_info()
4849 btf_verifier_log(env, "Unsupported section found"); in btf_check_sec_info()
4853 btf_verifier_log(env, "Section overlap found"); in btf_check_sec_info()
4857 btf_verifier_log(env, in btf_check_sec_info()
4866 btf_verifier_log(env, "Unsupported section found"); in btf_check_sec_info()
4873 static int btf_parse_hdr(struct btf_verifier_env *env) in btf_parse_hdr() argument
4879 btf = env->btf; in btf_parse_hdr()
4883 btf_verifier_log(env, "hdr_len not found"); in btf_parse_hdr()
4890 btf_verifier_log(env, "btf_header not found"); in btf_parse_hdr()
4901 btf_verifier_log(env, "Unsupported btf_header"); in btf_parse_hdr()
4912 btf_verifier_log_hdr(env, btf_data_size); in btf_parse_hdr()
4915 btf_verifier_log(env, "Invalid magic"); in btf_parse_hdr()
4920 btf_verifier_log(env, "Unsupported version"); in btf_parse_hdr()
4925 btf_verifier_log(env, "Unsupported flags"); in btf_parse_hdr()
4930 btf_verifier_log(env, "No data"); in btf_parse_hdr()
4934 return btf_check_sec_info(env, btf_data_size); in btf_parse_hdr()
4937 static int btf_check_type_tags(struct btf_verifier_env *env, in btf_check_type_tags() argument
4960 btf_verifier_log(env, "Max chain length or cycle detected"); in btf_check_type_tags()
4965 btf_verifier_log(env, "Type tags don't precede modifiers"); in btf_check_type_tags()
4987 struct btf_verifier_env *env = NULL; in btf_parse() local
4996 env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN); in btf_parse()
4997 if (!env) in btf_parse()
5000 log = &env->log; in btf_parse()
5021 env->btf = btf; in btf_parse()
5037 err = btf_parse_hdr(env); in btf_parse()
5043 err = btf_parse_str_sec(env); in btf_parse()
5047 err = btf_parse_type_sec(env); in btf_parse()
5051 err = btf_check_type_tags(env, btf, 1); in btf_parse()
5060 btf_verifier_env_free(env); in btf_parse()
5065 btf_verifier_env_free(env); in btf_parse()
5192 struct btf_verifier_env *env = NULL; in BTF_ID() local
5197 env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN); in BTF_ID()
5198 if (!env) in BTF_ID()
5201 log = &env->log; in BTF_ID()
5209 env->btf = btf; in BTF_ID()
5216 err = btf_parse_hdr(env); in BTF_ID()
5222 err = btf_parse_str_sec(env); in BTF_ID()
5226 err = btf_check_all_metas(env); in BTF_ID()
5230 err = btf_check_type_tags(env, btf, 1); in BTF_ID()
5245 btf_verifier_env_free(env); in BTF_ID()
5249 btf_verifier_env_free(env); in BTF_ID()
5261 struct btf_verifier_env *env = NULL; in btf_parse_module() local
5272 env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN); in btf_parse_module()
5273 if (!env) in btf_parse_module()
5276 log = &env->log; in btf_parse_module()
5284 env->btf = btf; in btf_parse_module()
5300 err = btf_parse_hdr(env); in btf_parse_module()
5306 err = btf_parse_str_sec(env); in btf_parse_module()
5310 err = btf_check_all_metas(env); in btf_parse_module()
5314 err = btf_check_type_tags(env, btf, btf_nr_types(base_btf)); in btf_parse_module()
5318 btf_verifier_env_free(env); in btf_parse_module()
5323 btf_verifier_env_free(env); in btf_parse_module()
6248 static int btf_check_func_arg_match(struct bpf_verifier_env *env, in btf_check_func_arg_match() argument
6255 enum bpf_prog_type prog_type = resolve_prog_type(env->prog); in btf_check_func_arg_match()
6258 struct bpf_verifier_log *log = &env->log; in btf_check_func_arg_match()
6335 ret = mark_chain_precision(env, regno); in btf_check_func_arg_match()
6374 ret = check_func_arg_reg_off(env, reg, regno, arg_type); in btf_check_func_arg_match()
6515 if (!is_dynptr_reg_valid_init(env, reg)) { in btf_check_func_arg_match()
6523 if (!is_dynptr_type_expected(env, reg, in btf_check_func_arg_match()
6537 if (check_kfunc_mem_size_reg(env, ®s[regno + 1], regno + 1)) { in btf_check_func_arg_match()
6556 if (check_mem_reg(env, reg, regno, type_size)) in btf_check_func_arg_match()
6578 if (sleepable && !env->prog->aux->sleepable) { in btf_check_func_arg_match()
6598 int btf_check_subprog_arg_match(struct bpf_verifier_env *env, int subprog, in btf_check_subprog_arg_match() argument
6601 struct bpf_prog *prog = env->prog; in btf_check_subprog_arg_match()
6618 err = btf_check_func_arg_match(env, btf, btf_id, regs, is_global, NULL, false); in btf_check_subprog_arg_match()
6641 int btf_check_subprog_call(struct bpf_verifier_env *env, int subprog, in btf_check_subprog_call() argument
6644 struct bpf_prog *prog = env->prog; in btf_check_subprog_call()
6661 err = btf_check_func_arg_match(env, btf, btf_id, regs, is_global, NULL, true); in btf_check_subprog_call()
6672 int btf_check_kfunc_arg_match(struct bpf_verifier_env *env, in btf_check_kfunc_arg_match() argument
6677 return btf_check_func_arg_match(env, btf, func_id, regs, true, meta, true); in btf_check_kfunc_arg_match()
6687 int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog, in btf_prepare_func_args() argument
6690 struct bpf_verifier_log *log = &env->log; in btf_prepare_func_args()
6691 struct bpf_prog *prog = env->prog; in btf_prepare_func_args()
6786 reg->id = ++env->id_gen; in btf_prepare_func_args()