Lines Matching full:env
443 s32 (*check_meta)(struct btf_verifier_env *env,
446 int (*resolve)(struct btf_verifier_env *env,
448 int (*check_member)(struct btf_verifier_env *env,
452 int (*check_kflag_member)(struct btf_verifier_env *env,
456 void (*log_details)(struct btf_verifier_env *env,
466 static int btf_resolve(struct btf_verifier_env *env,
469 static int btf_func_check(struct btf_verifier_env *env,
1420 __printf(2, 3) static void btf_verifier_log(struct btf_verifier_env *env, in btf_verifier_log() argument
1423 struct bpf_verifier_log *log = &env->log; in btf_verifier_log()
1434 __printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env, in __btf_verifier_log_type() argument
1439 struct bpf_verifier_log *log = &env->log; in __btf_verifier_log_type()
1440 struct btf *btf = env->btf; in __btf_verifier_log_type()
1455 if (env->btf->base_btf && IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) in __btf_verifier_log_type()
1460 env->log_type_id, in __btf_verifier_log_type()
1466 btf_type_ops(t)->log_details(env, t); in __btf_verifier_log_type()
1478 #define btf_verifier_log_type(env, t, ...) \ argument
1479 __btf_verifier_log_type((env), (t), true, __VA_ARGS__)
1480 #define btf_verifier_log_basic(env, t, ...) \ argument
1481 __btf_verifier_log_type((env), (t), false, __VA_ARGS__)
1484 static void btf_verifier_log_member(struct btf_verifier_env *env, in btf_verifier_log_member() argument
1489 struct bpf_verifier_log *log = &env->log; in btf_verifier_log_member()
1490 struct btf *btf = env->btf; in btf_verifier_log_member()
1501 if (env->btf->base_btf && IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) in btf_verifier_log_member()
1511 if (env->phase != CHECK_META) in btf_verifier_log_member()
1512 btf_verifier_log_type(env, struct_type, NULL); in btf_verifier_log_member()
1537 static void btf_verifier_log_vsi(struct btf_verifier_env *env, in btf_verifier_log_vsi() argument
1542 struct bpf_verifier_log *log = &env->log; in btf_verifier_log_vsi()
1549 if (env->phase != CHECK_META) in btf_verifier_log_vsi()
1550 btf_verifier_log_type(env, datasec_type, NULL); in btf_verifier_log_vsi()
1564 static void btf_verifier_log_hdr(struct btf_verifier_env *env, in btf_verifier_log_hdr() argument
1567 struct bpf_verifier_log *log = &env->log; in btf_verifier_log_hdr()
1568 const struct btf *btf = env->btf; in btf_verifier_log_hdr()
1588 static int btf_add_type(struct btf_verifier_env *env, struct btf_type *t) in btf_add_type() argument
1590 struct btf *btf = env->btf; in btf_add_type()
1599 btf_verifier_log(env, "Exceeded max num of types"); in btf_add_type()
1786 static int env_resolve_init(struct btf_verifier_env *env) in env_resolve_init() argument
1788 struct btf *btf = env->btf; in env_resolve_init()
1811 env->visit_states = visit_states; in env_resolve_init()
1822 static void btf_verifier_env_free(struct btf_verifier_env *env) in btf_verifier_env_free() argument
1824 kvfree(env->visit_states); in btf_verifier_env_free()
1825 kfree(env); in btf_verifier_env_free()
1828 static bool env_type_is_resolve_sink(const struct btf_verifier_env *env, in env_type_is_resolve_sink() argument
1831 switch (env->resolve_mode) { in env_type_is_resolve_sink()
1853 static bool env_type_is_resolved(const struct btf_verifier_env *env, in env_type_is_resolved() argument
1857 if (type_id < env->btf->start_id) in env_type_is_resolved()
1860 return env->visit_states[type_id - env->btf->start_id] == RESOLVED; in env_type_is_resolved()
1863 static int env_stack_push(struct btf_verifier_env *env, in env_stack_push() argument
1866 const struct btf *btf = env->btf; in env_stack_push()
1869 if (env->top_stack == MAX_RESOLVE_DEPTH) in env_stack_push()
1873 || env->visit_states[type_id - btf->start_id] != NOT_VISITED) in env_stack_push()
1876 env->visit_states[type_id - btf->start_id] = VISITED; in env_stack_push()
1878 v = &env->stack[env->top_stack++]; in env_stack_push()
1883 if (env->resolve_mode == RESOLVE_TBD) { in env_stack_push()
1885 env->resolve_mode = RESOLVE_PTR; in env_stack_push()
1887 env->resolve_mode = RESOLVE_STRUCT_OR_ARRAY; in env_stack_push()
1893 static void env_stack_set_next_member(struct btf_verifier_env *env, in env_stack_set_next_member() argument
1896 env->stack[env->top_stack - 1].next_member = next_member; in env_stack_set_next_member()
1899 static void env_stack_pop_resolved(struct btf_verifier_env *env, in env_stack_pop_resolved() argument
1903 u32 type_id = env->stack[--(env->top_stack)].type_id; in env_stack_pop_resolved()
1904 struct btf *btf = env->btf; in env_stack_pop_resolved()
1909 env->visit_states[type_id] = RESOLVED; in env_stack_pop_resolved()
1912 static const struct resolve_vertex *env_stack_peak(struct btf_verifier_env *env) in env_stack_peak() argument
1914 return env->top_stack ? &env->stack[env->top_stack - 1] : NULL; in env_stack_peak()
2081 static int btf_df_check_member(struct btf_verifier_env *env, in btf_df_check_member() argument
2086 btf_verifier_log_basic(env, struct_type, in btf_df_check_member()
2091 static int btf_df_check_kflag_member(struct btf_verifier_env *env, in btf_df_check_kflag_member() argument
2096 btf_verifier_log_basic(env, struct_type, in btf_df_check_kflag_member()
2104 static int btf_generic_check_kflag_member(struct btf_verifier_env *env, in btf_generic_check_kflag_member() argument
2110 btf_verifier_log_member(env, struct_type, member, in btf_generic_check_kflag_member()
2118 return btf_type_ops(member_type)->check_member(env, struct_type, in btf_generic_check_kflag_member()
2123 static int btf_df_resolve(struct btf_verifier_env *env, in btf_df_resolve() argument
2126 btf_verifier_log_basic(env, v->t, "Unsupported resolve"); in btf_df_resolve()
2137 static int btf_int_check_member(struct btf_verifier_env *env, in btf_int_check_member() argument
2149 btf_verifier_log_member(env, struct_type, member, in btf_int_check_member()
2160 btf_verifier_log_member(env, struct_type, member, in btf_int_check_member()
2167 btf_verifier_log_member(env, struct_type, member, in btf_int_check_member()
2175 static int btf_int_check_kflag_member(struct btf_verifier_env *env, in btf_int_check_kflag_member() argument
2187 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2201 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2208 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2216 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2223 btf_verifier_log_member(env, struct_type, member, in btf_int_check_kflag_member()
2231 static s32 btf_int_check_meta(struct btf_verifier_env *env, in btf_int_check_meta() argument
2239 btf_verifier_log_basic(env, t, in btf_int_check_meta()
2246 btf_verifier_log_type(env, t, "vlen != 0"); in btf_int_check_meta()
2251 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_int_check_meta()
2257 btf_verifier_log_basic(env, t, "Invalid int_data:%x", in btf_int_check_meta()
2265 btf_verifier_log_type(env, t, "nr_bits exceeds %zu", in btf_int_check_meta()
2271 btf_verifier_log_type(env, t, "nr_bits exceeds type_size"); in btf_int_check_meta()
2286 btf_verifier_log_type(env, t, "Unsupported encoding"); in btf_int_check_meta()
2290 btf_verifier_log_type(env, t, NULL); in btf_int_check_meta()
2295 static void btf_int_log(struct btf_verifier_env *env, in btf_int_log() argument
2300 btf_verifier_log(env, in btf_int_log()
2496 static int btf_modifier_check_member(struct btf_verifier_env *env, in btf_modifier_check_member() argument
2504 struct btf *btf = env->btf; in btf_modifier_check_member()
2508 btf_verifier_log_member(env, struct_type, member, in btf_modifier_check_member()
2516 return btf_type_ops(resolved_type)->check_member(env, struct_type, in btf_modifier_check_member()
2521 static int btf_modifier_check_kflag_member(struct btf_verifier_env *env, in btf_modifier_check_kflag_member() argument
2529 struct btf *btf = env->btf; in btf_modifier_check_kflag_member()
2533 btf_verifier_log_member(env, struct_type, member, in btf_modifier_check_kflag_member()
2541 return btf_type_ops(resolved_type)->check_kflag_member(env, struct_type, in btf_modifier_check_kflag_member()
2546 static int btf_ptr_check_member(struct btf_verifier_env *env, in btf_ptr_check_member() argument
2558 btf_verifier_log_member(env, struct_type, member, in btf_ptr_check_member()
2564 btf_verifier_log_member(env, struct_type, member, in btf_ptr_check_member()
2572 static int btf_ref_type_check_meta(struct btf_verifier_env *env, in btf_ref_type_check_meta() argument
2579 btf_verifier_log_type(env, t, "vlen != 0"); in btf_ref_type_check_meta()
2584 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_ref_type_check_meta()
2589 btf_verifier_log_type(env, t, "Invalid type_id"); in btf_ref_type_check_meta()
2598 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_ref_type_check_meta()
2599 btf_verifier_log_type(env, t, "Invalid name"); in btf_ref_type_check_meta()
2603 value = btf_name_by_offset(env->btf, t->name_off); in btf_ref_type_check_meta()
2605 btf_verifier_log_type(env, t, "Invalid name"); in btf_ref_type_check_meta()
2610 btf_verifier_log_type(env, t, "Invalid name"); in btf_ref_type_check_meta()
2615 btf_verifier_log_type(env, t, NULL); in btf_ref_type_check_meta()
2620 static int btf_modifier_resolve(struct btf_verifier_env *env, in btf_modifier_resolve() argument
2626 struct btf *btf = env->btf; in btf_modifier_resolve()
2630 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_modifier_resolve()
2634 if (!env_type_is_resolve_sink(env, next_type) && in btf_modifier_resolve()
2635 !env_type_is_resolved(env, next_type_id)) in btf_modifier_resolve()
2636 return env_stack_push(env, next_type, next_type_id); in btf_modifier_resolve()
2645 if (env_type_is_resolved(env, next_type_id)) in btf_modifier_resolve()
2652 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_modifier_resolve()
2657 env_stack_pop_resolved(env, next_type_id, 0); in btf_modifier_resolve()
2662 static int btf_var_resolve(struct btf_verifier_env *env, in btf_var_resolve() argument
2668 struct btf *btf = env->btf; in btf_var_resolve()
2672 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_var_resolve()
2676 if (!env_type_is_resolve_sink(env, next_type) && in btf_var_resolve()
2677 !env_type_is_resolved(env, next_type_id)) in btf_var_resolve()
2678 return env_stack_push(env, next_type, next_type_id); in btf_var_resolve()
2688 !env_type_is_resolve_sink(env, resolved_type) && in btf_var_resolve()
2689 !env_type_is_resolved(env, resolved_type_id)) in btf_var_resolve()
2690 return env_stack_push(env, resolved_type, in btf_var_resolve()
2699 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_var_resolve()
2703 env_stack_pop_resolved(env, next_type_id, 0); in btf_var_resolve()
2708 static int btf_ptr_resolve(struct btf_verifier_env *env, in btf_ptr_resolve() argument
2714 struct btf *btf = env->btf; in btf_ptr_resolve()
2718 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_ptr_resolve()
2722 if (!env_type_is_resolve_sink(env, next_type) && in btf_ptr_resolve()
2723 !env_type_is_resolved(env, next_type_id)) in btf_ptr_resolve()
2724 return env_stack_push(env, next_type, next_type_id); in btf_ptr_resolve()
2742 !env_type_is_resolve_sink(env, resolved_type) && in btf_ptr_resolve()
2743 !env_type_is_resolved(env, resolved_type_id)) in btf_ptr_resolve()
2744 return env_stack_push(env, resolved_type, in btf_ptr_resolve()
2749 if (env_type_is_resolved(env, next_type_id)) in btf_ptr_resolve()
2755 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_ptr_resolve()
2760 env_stack_pop_resolved(env, next_type_id, 0); in btf_ptr_resolve()
2805 static void btf_ref_type_log(struct btf_verifier_env *env, in btf_ref_type_log() argument
2808 btf_verifier_log(env, "type_id=%u", t->type); in btf_ref_type_log()
2829 static s32 btf_fwd_check_meta(struct btf_verifier_env *env, in btf_fwd_check_meta() argument
2834 btf_verifier_log_type(env, t, "vlen != 0"); in btf_fwd_check_meta()
2839 btf_verifier_log_type(env, t, "type != 0"); in btf_fwd_check_meta()
2845 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_fwd_check_meta()
2846 btf_verifier_log_type(env, t, "Invalid name"); in btf_fwd_check_meta()
2850 btf_verifier_log_type(env, t, NULL); in btf_fwd_check_meta()
2855 static void btf_fwd_type_log(struct btf_verifier_env *env, in btf_fwd_type_log() argument
2858 btf_verifier_log(env, "%s", btf_type_kflag(t) ? "union" : "struct"); in btf_fwd_type_log()
2870 static int btf_array_check_member(struct btf_verifier_env *env, in btf_array_check_member() argument
2878 struct btf *btf = env->btf; in btf_array_check_member()
2881 btf_verifier_log_member(env, struct_type, member, in btf_array_check_member()
2891 btf_verifier_log_member(env, struct_type, member, in btf_array_check_member()
2899 static s32 btf_array_check_meta(struct btf_verifier_env *env, in btf_array_check_meta() argument
2907 btf_verifier_log_basic(env, t, in btf_array_check_meta()
2915 btf_verifier_log_type(env, t, "Invalid name"); in btf_array_check_meta()
2920 btf_verifier_log_type(env, t, "vlen != 0"); in btf_array_check_meta()
2925 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_array_check_meta()
2930 btf_verifier_log_type(env, t, "size != 0"); in btf_array_check_meta()
2938 btf_verifier_log_type(env, t, "Invalid elem"); in btf_array_check_meta()
2943 btf_verifier_log_type(env, t, "Invalid index"); in btf_array_check_meta()
2947 btf_verifier_log_type(env, t, NULL); in btf_array_check_meta()
2952 static int btf_array_resolve(struct btf_verifier_env *env, in btf_array_resolve() argument
2958 struct btf *btf = env->btf; in btf_array_resolve()
2966 btf_verifier_log_type(env, v->t, "Invalid index"); in btf_array_resolve()
2970 if (!env_type_is_resolve_sink(env, index_type) && in btf_array_resolve()
2971 !env_type_is_resolved(env, index_type_id)) in btf_array_resolve()
2972 return env_stack_push(env, index_type, index_type_id); in btf_array_resolve()
2977 btf_verifier_log_type(env, v->t, "Invalid index"); in btf_array_resolve()
2986 btf_verifier_log_type(env, v->t, in btf_array_resolve()
2991 if (!env_type_is_resolve_sink(env, elem_type) && in btf_array_resolve()
2992 !env_type_is_resolved(env, elem_type_id)) in btf_array_resolve()
2993 return env_stack_push(env, elem_type, elem_type_id); in btf_array_resolve()
2997 btf_verifier_log_type(env, v->t, "Invalid elem"); in btf_array_resolve()
3002 btf_verifier_log_type(env, v->t, "Invalid array of int"); in btf_array_resolve()
3007 btf_verifier_log_type(env, v->t, in btf_array_resolve()
3012 env_stack_pop_resolved(env, elem_type_id, elem_size * array->nelems); in btf_array_resolve()
3017 static void btf_array_log(struct btf_verifier_env *env, in btf_array_log() argument
3022 btf_verifier_log(env, "type_id=%u index_type_id=%u nr_elems=%u", in btf_array_log()
3121 static int btf_struct_check_member(struct btf_verifier_env *env, in btf_struct_check_member() argument
3130 btf_verifier_log_member(env, struct_type, member, in btf_struct_check_member()
3138 btf_verifier_log_member(env, struct_type, member, in btf_struct_check_member()
3146 static s32 btf_struct_check_meta(struct btf_verifier_env *env, in btf_struct_check_meta() argument
3153 struct btf *btf = env->btf; in btf_struct_check_meta()
3160 btf_verifier_log_basic(env, t, in btf_struct_check_meta()
3168 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_struct_check_meta()
3169 btf_verifier_log_type(env, t, "Invalid name"); in btf_struct_check_meta()
3173 btf_verifier_log_type(env, t, NULL); in btf_struct_check_meta()
3178 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3187 btf_verifier_log_member(env, t, member, "Invalid name"); in btf_struct_check_meta()
3192 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3199 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3209 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3215 btf_verifier_log_member(env, t, member, in btf_struct_check_meta()
3220 btf_verifier_log_member(env, t, member, NULL); in btf_struct_check_meta()
3227 static int btf_struct_resolve(struct btf_verifier_env *env, in btf_struct_resolve() argument
3245 if (WARN_ON_ONCE(!env_type_is_resolved(env, in btf_struct_resolve()
3249 last_member_type = btf_type_by_id(env->btf, in btf_struct_resolve()
3252 err = btf_type_ops(last_member_type)->check_kflag_member(env, v->t, in btf_struct_resolve()
3256 err = btf_type_ops(last_member_type)->check_member(env, v->t, in btf_struct_resolve()
3265 const struct btf_type *member_type = btf_type_by_id(env->btf, in btf_struct_resolve()
3270 btf_verifier_log_member(env, v->t, member, in btf_struct_resolve()
3275 if (!env_type_is_resolve_sink(env, member_type) && in btf_struct_resolve()
3276 !env_type_is_resolved(env, member_type_id)) { in btf_struct_resolve()
3277 env_stack_set_next_member(env, i + 1); in btf_struct_resolve()
3278 return env_stack_push(env, member_type, member_type_id); in btf_struct_resolve()
3282 err = btf_type_ops(member_type)->check_kflag_member(env, v->t, in btf_struct_resolve()
3286 err = btf_type_ops(member_type)->check_member(env, v->t, in btf_struct_resolve()
3293 env_stack_pop_resolved(env, 0, 0); in btf_struct_resolve()
3298 static void btf_struct_log(struct btf_verifier_env *env, in btf_struct_log() argument
3301 btf_verifier_log(env, "size=%u vlen=%u", t->size, btf_type_vlen(t)); in btf_struct_log()
4203 static int btf_enum_check_member(struct btf_verifier_env *env, in btf_enum_check_member() argument
4212 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_member()
4220 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_member()
4228 static int btf_enum_check_kflag_member(struct btf_verifier_env *env, in btf_enum_check_kflag_member() argument
4240 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_kflag_member()
4247 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_kflag_member()
4255 btf_verifier_log_member(env, struct_type, member, in btf_enum_check_kflag_member()
4263 static s32 btf_enum_check_meta(struct btf_verifier_env *env, in btf_enum_check_meta() argument
4268 struct btf *btf = env->btf; in btf_enum_check_meta()
4277 btf_verifier_log_basic(env, t, in btf_enum_check_meta()
4284 btf_verifier_log_type(env, t, "Unexpected size"); in btf_enum_check_meta()
4290 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_enum_check_meta()
4291 btf_verifier_log_type(env, t, "Invalid name"); in btf_enum_check_meta()
4295 btf_verifier_log_type(env, t, NULL); in btf_enum_check_meta()
4299 btf_verifier_log(env, "\tInvalid name_offset:%u", in btf_enum_check_meta()
4307 btf_verifier_log_type(env, t, "Invalid name"); in btf_enum_check_meta()
4311 if (env->log.level == BPF_LOG_KERNEL) in btf_enum_check_meta()
4314 btf_verifier_log(env, fmt_str, in btf_enum_check_meta()
4322 static void btf_enum_log(struct btf_verifier_env *env, in btf_enum_log() argument
4325 btf_verifier_log(env, "size=%u vlen=%u", t->size, btf_type_vlen(t)); in btf_enum_log()
4371 static s32 btf_enum64_check_meta(struct btf_verifier_env *env, in btf_enum64_check_meta() argument
4376 struct btf *btf = env->btf; in btf_enum64_check_meta()
4385 btf_verifier_log_basic(env, t, in btf_enum64_check_meta()
4392 btf_verifier_log_type(env, t, "Unexpected size"); in btf_enum64_check_meta()
4398 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_enum64_check_meta()
4399 btf_verifier_log_type(env, t, "Invalid name"); in btf_enum64_check_meta()
4403 btf_verifier_log_type(env, t, NULL); in btf_enum64_check_meta()
4407 btf_verifier_log(env, "\tInvalid name_offset:%u", in btf_enum64_check_meta()
4415 btf_verifier_log_type(env, t, "Invalid name"); in btf_enum64_check_meta()
4419 if (env->log.level == BPF_LOG_KERNEL) in btf_enum64_check_meta()
4423 btf_verifier_log(env, fmt_str, in btf_enum64_check_meta()
4474 static s32 btf_func_proto_check_meta(struct btf_verifier_env *env, in btf_func_proto_check_meta() argument
4481 btf_verifier_log_basic(env, t, in btf_func_proto_check_meta()
4488 btf_verifier_log_type(env, t, "Invalid name"); in btf_func_proto_check_meta()
4493 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_func_proto_check_meta()
4497 btf_verifier_log_type(env, t, NULL); in btf_func_proto_check_meta()
4502 static void btf_func_proto_log(struct btf_verifier_env *env, in btf_func_proto_log() argument
4508 btf_verifier_log(env, "return=%u args=(", t->type); in btf_func_proto_log()
4510 btf_verifier_log(env, "void"); in btf_func_proto_log()
4516 btf_verifier_log(env, "vararg"); in btf_func_proto_log()
4520 btf_verifier_log(env, "%u %s", args[0].type, in btf_func_proto_log()
4521 __btf_name_by_offset(env->btf, in btf_func_proto_log()
4524 btf_verifier_log(env, ", %u %s", args[i].type, in btf_func_proto_log()
4525 __btf_name_by_offset(env->btf, in btf_func_proto_log()
4532 btf_verifier_log(env, ", %u %s", last_arg->type, in btf_func_proto_log()
4533 __btf_name_by_offset(env->btf, in btf_func_proto_log()
4536 btf_verifier_log(env, ", vararg"); in btf_func_proto_log()
4540 btf_verifier_log(env, ")"); in btf_func_proto_log()
4561 static s32 btf_func_check_meta(struct btf_verifier_env *env, in btf_func_check_meta() argument
4566 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_func_check_meta()
4567 btf_verifier_log_type(env, t, "Invalid name"); in btf_func_check_meta()
4572 btf_verifier_log_type(env, t, "Invalid func linkage"); in btf_func_check_meta()
4577 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_func_check_meta()
4581 btf_verifier_log_type(env, t, NULL); in btf_func_check_meta()
4586 static int btf_func_resolve(struct btf_verifier_env *env, in btf_func_resolve() argument
4593 err = btf_func_check(env, t); in btf_func_resolve()
4597 env_stack_pop_resolved(env, next_type_id, 0); in btf_func_resolve()
4610 static s32 btf_var_check_meta(struct btf_verifier_env *env, in btf_var_check_meta() argument
4618 btf_verifier_log_basic(env, t, in btf_var_check_meta()
4625 btf_verifier_log_type(env, t, "vlen != 0"); in btf_var_check_meta()
4630 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_var_check_meta()
4635 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_var_check_meta()
4636 btf_verifier_log_type(env, t, "Invalid name"); in btf_var_check_meta()
4642 btf_verifier_log_type(env, t, "Invalid type_id"); in btf_var_check_meta()
4649 btf_verifier_log_type(env, t, "Linkage not supported"); in btf_var_check_meta()
4653 btf_verifier_log_type(env, t, NULL); in btf_var_check_meta()
4658 static void btf_var_log(struct btf_verifier_env *env, const struct btf_type *t) in btf_var_log() argument
4662 btf_verifier_log(env, "type_id=%u linkage=%u", t->type, var->linkage); in btf_var_log()
4674 static s32 btf_datasec_check_meta(struct btf_verifier_env *env, in btf_datasec_check_meta() argument
4684 btf_verifier_log_basic(env, t, in btf_datasec_check_meta()
4691 btf_verifier_log_type(env, t, "size == 0"); in btf_datasec_check_meta()
4696 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_datasec_check_meta()
4701 !btf_name_valid_section(env->btf, t->name_off)) { in btf_datasec_check_meta()
4702 btf_verifier_log_type(env, t, "Invalid name"); in btf_datasec_check_meta()
4706 btf_verifier_log_type(env, t, NULL); in btf_datasec_check_meta()
4711 btf_verifier_log_vsi(env, t, vsi, in btf_datasec_check_meta()
4717 btf_verifier_log_vsi(env, t, vsi, in btf_datasec_check_meta()
4723 btf_verifier_log_vsi(env, t, vsi, in btf_datasec_check_meta()
4730 btf_verifier_log_vsi(env, t, vsi, in btf_datasec_check_meta()
4735 btf_verifier_log_vsi(env, t, vsi, NULL); in btf_datasec_check_meta()
4740 btf_verifier_log_type(env, t, "Invalid btf_info size"); in btf_datasec_check_meta()
4747 static int btf_datasec_resolve(struct btf_verifier_env *env, in btf_datasec_resolve() argument
4751 struct btf *btf = env->btf; in btf_datasec_resolve()
4754 env->resolve_mode = RESOLVE_TBD; in btf_datasec_resolve()
4757 const struct btf_type *var_type = btf_type_by_id(env->btf, in btf_datasec_resolve()
4760 btf_verifier_log_vsi(env, v->t, vsi, in btf_datasec_resolve()
4765 if (!env_type_is_resolve_sink(env, var_type) && in btf_datasec_resolve()
4766 !env_type_is_resolved(env, var_type_id)) { in btf_datasec_resolve()
4767 env_stack_set_next_member(env, i + 1); in btf_datasec_resolve()
4768 return env_stack_push(env, var_type, var_type_id); in btf_datasec_resolve()
4773 btf_verifier_log_vsi(env, v->t, vsi, "Invalid type"); in btf_datasec_resolve()
4778 btf_verifier_log_vsi(env, v->t, vsi, "Invalid size"); in btf_datasec_resolve()
4783 env_stack_pop_resolved(env, 0, 0); in btf_datasec_resolve()
4787 static void btf_datasec_log(struct btf_verifier_env *env, in btf_datasec_log() argument
4790 btf_verifier_log(env, "size=%u vlen=%u", t->size, btf_type_vlen(t)); in btf_datasec_log()
4826 static s32 btf_float_check_meta(struct btf_verifier_env *env, in btf_float_check_meta() argument
4831 btf_verifier_log_type(env, t, "vlen != 0"); in btf_float_check_meta()
4836 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_float_check_meta()
4842 btf_verifier_log_type(env, t, "Invalid type_size"); in btf_float_check_meta()
4846 btf_verifier_log_type(env, t, NULL); in btf_float_check_meta()
4851 static int btf_float_check_member(struct btf_verifier_env *env, in btf_float_check_member() argument
4870 btf_verifier_log_member(env, struct_type, member, in btf_float_check_member()
4878 btf_verifier_log_member(env, struct_type, member, in btf_float_check_member()
4886 static void btf_float_log(struct btf_verifier_env *env, in btf_float_log() argument
4889 btf_verifier_log(env, "size=%u", t->size); in btf_float_log()
4901 static s32 btf_decl_tag_check_meta(struct btf_verifier_env *env, in btf_decl_tag_check_meta() argument
4911 btf_verifier_log_basic(env, t, in btf_decl_tag_check_meta()
4917 value = btf_name_by_offset(env->btf, t->name_off); in btf_decl_tag_check_meta()
4919 btf_verifier_log_type(env, t, "Invalid value"); in btf_decl_tag_check_meta()
4924 btf_verifier_log_type(env, t, "vlen != 0"); in btf_decl_tag_check_meta()
4929 btf_verifier_log_type(env, t, "Invalid btf_info kind_flag"); in btf_decl_tag_check_meta()
4935 btf_verifier_log_type(env, t, "Invalid component_idx"); in btf_decl_tag_check_meta()
4939 btf_verifier_log_type(env, t, NULL); in btf_decl_tag_check_meta()
4944 static int btf_decl_tag_resolve(struct btf_verifier_env *env, in btf_decl_tag_resolve() argument
4950 struct btf *btf = env->btf; in btf_decl_tag_resolve()
4956 btf_verifier_log_type(env, v->t, "Invalid type_id"); in btf_decl_tag_resolve()
4960 if (!env_type_is_resolve_sink(env, next_type) && in btf_decl_tag_resolve()
4961 !env_type_is_resolved(env, next_type_id)) in btf_decl_tag_resolve()
4962 return env_stack_push(env, next_type, next_type_id); in btf_decl_tag_resolve()
4967 btf_verifier_log_type(env, v->t, "Invalid component_idx"); in btf_decl_tag_resolve()
4980 btf_verifier_log_type(env, v->t, "Invalid component_idx"); in btf_decl_tag_resolve()
4985 env_stack_pop_resolved(env, next_type_id, 0); in btf_decl_tag_resolve()
4990 static void btf_decl_tag_log(struct btf_verifier_env *env, const struct btf_type *t) in btf_decl_tag_log() argument
4992 btf_verifier_log(env, "type=%u component_idx=%d", t->type, in btf_decl_tag_log()
5005 static int btf_func_proto_check(struct btf_verifier_env *env, in btf_func_proto_check() argument
5014 btf = env->btf; in btf_func_proto_check()
5024 btf_verifier_log_type(env, t, "Invalid return type"); in btf_func_proto_check()
5029 btf_verifier_log_type(env, t, "Invalid return type"); in btf_func_proto_check()
5034 !env_type_is_resolved(env, ret_type_id)) { in btf_func_proto_check()
5035 err = btf_resolve(env, ret_type, ret_type_id); in btf_func_proto_check()
5042 btf_verifier_log_type(env, t, "Invalid return type"); in btf_func_proto_check()
5053 btf_verifier_log_type(env, t, "Invalid arg#%u", in btf_func_proto_check()
5067 btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1); in btf_func_proto_check()
5072 btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1); in btf_func_proto_check()
5079 btf_verifier_log_type(env, t, in btf_func_proto_check()
5085 !env_type_is_resolved(env, arg_type_id)) { in btf_func_proto_check()
5086 err = btf_resolve(env, arg_type, arg_type_id); in btf_func_proto_check()
5092 btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1); in btf_func_proto_check()
5100 static int btf_func_check(struct btf_verifier_env *env, in btf_func_check() argument
5108 btf = env->btf; in btf_func_check()
5112 btf_verifier_log_type(env, t, "Invalid type_id"); in btf_func_check()
5120 btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1); in btf_func_check()
5150 static s32 btf_check_meta(struct btf_verifier_env *env, in btf_check_meta() argument
5158 btf_verifier_log(env, "[%u] meta_left:%u meta_needed:%zu", in btf_check_meta()
5159 env->log_type_id, meta_left, sizeof(*t)); in btf_check_meta()
5165 btf_verifier_log(env, "[%u] Invalid btf_info:%x", in btf_check_meta()
5166 env->log_type_id, t->info); in btf_check_meta()
5172 btf_verifier_log(env, "[%u] Invalid kind:%u", in btf_check_meta()
5173 env->log_type_id, BTF_INFO_KIND(t->info)); in btf_check_meta()
5177 if (!btf_name_offset_valid(env->btf, t->name_off)) { in btf_check_meta()
5178 btf_verifier_log(env, "[%u] Invalid name_offset:%u", in btf_check_meta()
5179 env->log_type_id, t->name_off); in btf_check_meta()
5183 var_meta_size = btf_type_ops(t)->check_meta(env, t, meta_left); in btf_check_meta()
5192 static int btf_check_all_metas(struct btf_verifier_env *env) in btf_check_all_metas() argument
5194 struct btf *btf = env->btf; in btf_check_all_metas()
5202 env->log_type_id = btf->base_btf ? btf->start_id : 1; in btf_check_all_metas()
5207 meta_size = btf_check_meta(env, t, end - cur); in btf_check_all_metas()
5211 btf_add_type(env, t); in btf_check_all_metas()
5213 env->log_type_id++; in btf_check_all_metas()
5219 static bool btf_resolve_valid(struct btf_verifier_env *env, in btf_resolve_valid() argument
5223 struct btf *btf = env->btf; in btf_resolve_valid()
5225 if (!env_type_is_resolved(env, type_id)) in btf_resolve_valid()
5260 static int btf_resolve(struct btf_verifier_env *env, in btf_resolve() argument
5263 u32 save_log_type_id = env->log_type_id; in btf_resolve()
5267 env->resolve_mode = RESOLVE_TBD; in btf_resolve()
5268 env_stack_push(env, t, type_id); in btf_resolve()
5269 while (!err && (v = env_stack_peak(env))) { in btf_resolve()
5270 env->log_type_id = v->type_id; in btf_resolve()
5271 err = btf_type_ops(v->t)->resolve(env, v); in btf_resolve()
5274 env->log_type_id = type_id; in btf_resolve()
5276 btf_verifier_log_type(env, t, in btf_resolve()
5280 btf_verifier_log_type(env, t, "Loop detected"); in btf_resolve()
5284 if (!err && !btf_resolve_valid(env, t, type_id)) { in btf_resolve()
5285 btf_verifier_log_type(env, t, "Invalid resolve state"); in btf_resolve()
5289 env->log_type_id = save_log_type_id; in btf_resolve()
5293 static int btf_check_all_types(struct btf_verifier_env *env) in btf_check_all_types() argument
5295 struct btf *btf = env->btf; in btf_check_all_types()
5300 err = env_resolve_init(env); in btf_check_all_types()
5304 env->phase++; in btf_check_all_types()
5309 env->log_type_id = type_id; in btf_check_all_types()
5311 !env_type_is_resolved(env, type_id)) { in btf_check_all_types()
5312 err = btf_resolve(env, t, type_id); in btf_check_all_types()
5318 err = btf_func_proto_check(env, t); in btf_check_all_types()
5327 static int btf_parse_type_sec(struct btf_verifier_env *env) in btf_parse_type_sec() argument
5329 const struct btf_header *hdr = &env->btf->hdr; in btf_parse_type_sec()
5334 btf_verifier_log(env, "Unaligned type_off"); in btf_parse_type_sec()
5338 if (!env->btf->base_btf && !hdr->type_len) { in btf_parse_type_sec()
5339 btf_verifier_log(env, "No type found"); in btf_parse_type_sec()
5343 err = btf_check_all_metas(env); in btf_parse_type_sec()
5347 return btf_check_all_types(env); in btf_parse_type_sec()
5350 static int btf_parse_str_sec(struct btf_verifier_env *env) in btf_parse_str_sec() argument
5353 struct btf *btf = env->btf; in btf_parse_str_sec()
5361 btf_verifier_log(env, "String section is not at the end"); in btf_parse_str_sec()
5370 btf_verifier_log(env, "Invalid string section"); in btf_parse_str_sec()
5374 btf_verifier_log(env, "Invalid string section"); in btf_parse_str_sec()
5394 static int btf_check_sec_info(struct btf_verifier_env *env, in btf_check_sec_info() argument
5402 btf = env->btf; in btf_check_sec_info()
5418 btf_verifier_log(env, "Invalid section offset"); in btf_check_sec_info()
5423 btf_verifier_log(env, "Unsupported section found"); in btf_check_sec_info()
5427 btf_verifier_log(env, "Section overlap found"); in btf_check_sec_info()
5431 btf_verifier_log(env, in btf_check_sec_info()
5440 btf_verifier_log(env, "Unsupported section found"); in btf_check_sec_info()
5447 static int btf_parse_hdr(struct btf_verifier_env *env) in btf_parse_hdr() argument
5453 btf = env->btf; in btf_parse_hdr()
5457 btf_verifier_log(env, "hdr_len not found"); in btf_parse_hdr()
5464 btf_verifier_log(env, "btf_header not found"); in btf_parse_hdr()
5475 btf_verifier_log(env, "Unsupported btf_header"); in btf_parse_hdr()
5486 btf_verifier_log_hdr(env, btf_data_size); in btf_parse_hdr()
5489 btf_verifier_log(env, "Invalid magic"); in btf_parse_hdr()
5494 btf_verifier_log(env, "Unsupported version"); in btf_parse_hdr()
5499 btf_verifier_log(env, "Unsupported flags"); in btf_parse_hdr()
5504 btf_verifier_log(env, "No data"); in btf_parse_hdr()
5508 return btf_check_sec_info(env, btf_data_size); in btf_parse_hdr()
5653 static int btf_check_type_tags(struct btf_verifier_env *env, in btf_check_type_tags() argument
5676 btf_verifier_log(env, "Max chain length or cycle detected"); in btf_check_type_tags()
5681 btf_verifier_log(env, "Type tags don't precede modifiers"); in btf_check_type_tags()
5720 struct btf_verifier_env *env = NULL; in btf_parse() local
5728 env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN); in btf_parse()
5729 if (!env) in btf_parse()
5735 err = bpf_vlog_init(&env->log, attr->btf_log_level, in btf_parse()
5745 env->btf = btf; in btf_parse()
5761 err = btf_parse_hdr(env); in btf_parse()
5767 err = btf_parse_str_sec(env); in btf_parse()
5771 err = btf_parse_type_sec(env); in btf_parse()
5775 err = btf_check_type_tags(env, btf, 1); in btf_parse()
5779 struct_meta_tab = btf_parse_struct_metas(&env->log, btf); in btf_parse()
5796 err = finalize_log(&env->log, uattr, uattr_size); in btf_parse()
5800 btf_verifier_env_free(env); in btf_parse()
5808 ret = finalize_log(&env->log, uattr, uattr_size); in btf_parse()
5812 btf_verifier_env_free(env); in btf_parse()
6147 static struct btf *btf_parse_base(struct btf_verifier_env *env, const char *name, in BTF_ID()
6161 env->btf = btf; in BTF_ID()
6168 err = btf_parse_hdr(env); in BTF_ID()
6174 err = btf_parse_str_sec(env); in BTF_ID()
6178 err = btf_check_all_metas(env); in BTF_ID()
6182 err = btf_check_type_tags(env, btf, 1); in BTF_ID()
6200 struct btf_verifier_env *env = NULL; in btf_parse_vmlinux() local
6205 env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN); in btf_parse_vmlinux()
6206 if (!env) in btf_parse_vmlinux()
6209 log = &env->log; in btf_parse_vmlinux()
6211 btf = btf_parse_base(env, "vmlinux", __start_BTF, __stop_BTF - __start_BTF); in btf_parse_vmlinux()
6223 btf_verifier_env_free(env); in btf_parse_vmlinux()
6245 struct btf_verifier_env *env = NULL; in btf_parse_module() local
6255 env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN); in btf_parse_module()
6256 if (!env) in btf_parse_module()
6259 log = &env->log; in btf_parse_module()
6263 base_btf = btf_parse_base(env, ".BTF.base", base_data, base_data_size); in btf_parse_module()
6277 env->btf = btf; in btf_parse_module()
6292 err = btf_parse_hdr(env); in btf_parse_module()
6298 err = btf_parse_str_sec(env); in btf_parse_module()
6302 err = btf_check_all_metas(env); in btf_parse_module()
6306 err = btf_check_type_tags(env, btf, btf_nr_types(base_btf)); in btf_parse_module()
6318 btf_verifier_env_free(env); in btf_parse_module()
6323 btf_verifier_env_free(env); in btf_parse_module()
7362 int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog) in btf_prepare_func_args() argument
7364 bool is_global = subprog_aux(env, subprog)->linkage == BTF_FUNC_GLOBAL; in btf_prepare_func_args()
7365 struct bpf_subprog_info *sub = subprog_info(env, subprog); in btf_prepare_func_args()
7366 struct bpf_verifier_log *log = &env->log; in btf_prepare_func_args()
7367 struct bpf_prog *prog = env->prog; in btf_prepare_func_args()