GNU Linux-libre 5.15.131-gnu
[releases.git] / include / linux / bpf_verifier.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
3  */
4 #ifndef _LINUX_BPF_VERIFIER_H
5 #define _LINUX_BPF_VERIFIER_H 1
6
7 #include <linux/bpf.h> /* for enum bpf_reg_type */
8 #include <linux/btf.h> /* for struct btf and btf_id() */
9 #include <linux/filter.h> /* for MAX_BPF_STACK */
10 #include <linux/tnum.h>
11
12 /* Maximum variable offset umax_value permitted when resolving memory accesses.
13  * In practice this is far bigger than any realistic pointer offset; this limit
14  * ensures that umax_value + (int)off + (int)size cannot overflow a u64.
15  */
16 #define BPF_MAX_VAR_OFF (1 << 29)
17 /* Maximum variable size permitted for ARG_CONST_SIZE[_OR_ZERO].  This ensures
18  * that converting umax_value to int cannot overflow.
19  */
20 #define BPF_MAX_VAR_SIZ (1 << 29)
21 /* size of type_str_buf in bpf_verifier. */
22 #define TYPE_STR_BUF_LEN 64
23
24 /* Liveness marks, used for registers and spilled-regs (in stack slots).
25  * Read marks propagate upwards until they find a write mark; they record that
26  * "one of this state's descendants read this reg" (and therefore the reg is
27  * relevant for states_equal() checks).
28  * Write marks collect downwards and do not propagate; they record that "the
29  * straight-line code that reached this state (from its parent) wrote this reg"
30  * (and therefore that reads propagated from this state or its descendants
31  * should not propagate to its parent).
32  * A state with a write mark can receive read marks; it just won't propagate
33  * them to its parent, since the write mark is a property, not of the state,
34  * but of the link between it and its parent.  See mark_reg_read() and
35  * mark_stack_slot_read() in kernel/bpf/verifier.c.
36  */
37 enum bpf_reg_liveness {
38         REG_LIVE_NONE = 0, /* reg hasn't been read or written this branch */
39         REG_LIVE_READ32 = 0x1, /* reg was read, so we're sensitive to initial value */
40         REG_LIVE_READ64 = 0x2, /* likewise, but full 64-bit content matters */
41         REG_LIVE_READ = REG_LIVE_READ32 | REG_LIVE_READ64,
42         REG_LIVE_WRITTEN = 0x4, /* reg was written first, screening off later reads */
43         REG_LIVE_DONE = 0x8, /* liveness won't be updating this register anymore */
44 };
45
46 struct bpf_reg_state {
47         /* Ordering of fields matters.  See states_equal() */
48         enum bpf_reg_type type;
49         /* Fixed part of pointer offset, pointer types only */
50         s32 off;
51         union {
52                 /* valid when type == PTR_TO_PACKET */
53                 int range;
54
55                 /* valid when type == CONST_PTR_TO_MAP | PTR_TO_MAP_VALUE |
56                  *   PTR_TO_MAP_VALUE_OR_NULL
57                  */
58                 struct {
59                         struct bpf_map *map_ptr;
60                         /* To distinguish map lookups from outer map
61                          * the map_uid is non-zero for registers
62                          * pointing to inner maps.
63                          */
64                         u32 map_uid;
65                 };
66
67                 /* for PTR_TO_BTF_ID */
68                 struct {
69                         struct btf *btf;
70                         u32 btf_id;
71                 };
72
73                 u32 mem_size; /* for PTR_TO_MEM | PTR_TO_MEM_OR_NULL */
74
75                 /* Max size from any of the above. */
76                 struct {
77                         unsigned long raw1;
78                         unsigned long raw2;
79                 } raw;
80
81                 u32 subprogno; /* for PTR_TO_FUNC */
82         };
83         /* For PTR_TO_PACKET, used to find other pointers with the same variable
84          * offset, so they can share range knowledge.
85          * For PTR_TO_MAP_VALUE_OR_NULL this is used to share which map value we
86          * came from, when one is tested for != NULL.
87          * For PTR_TO_MEM_OR_NULL this is used to identify memory allocation
88          * for the purpose of tracking that it's freed.
89          * For PTR_TO_SOCKET this is used to share which pointers retain the
90          * same reference to the socket, to determine proper reference freeing.
91          */
92         u32 id;
93         /* PTR_TO_SOCKET and PTR_TO_TCP_SOCK could be a ptr returned
94          * from a pointer-cast helper, bpf_sk_fullsock() and
95          * bpf_tcp_sock().
96          *
97          * Consider the following where "sk" is a reference counted
98          * pointer returned from "sk = bpf_sk_lookup_tcp();":
99          *
100          * 1: sk = bpf_sk_lookup_tcp();
101          * 2: if (!sk) { return 0; }
102          * 3: fullsock = bpf_sk_fullsock(sk);
103          * 4: if (!fullsock) { bpf_sk_release(sk); return 0; }
104          * 5: tp = bpf_tcp_sock(fullsock);
105          * 6: if (!tp) { bpf_sk_release(sk); return 0; }
106          * 7: bpf_sk_release(sk);
107          * 8: snd_cwnd = tp->snd_cwnd;  // verifier will complain
108          *
109          * After bpf_sk_release(sk) at line 7, both "fullsock" ptr and
110          * "tp" ptr should be invalidated also.  In order to do that,
111          * the reg holding "fullsock" and "sk" need to remember
112          * the original refcounted ptr id (i.e. sk_reg->id) in ref_obj_id
113          * such that the verifier can reset all regs which have
114          * ref_obj_id matching the sk_reg->id.
115          *
116          * sk_reg->ref_obj_id is set to sk_reg->id at line 1.
117          * sk_reg->id will stay as NULL-marking purpose only.
118          * After NULL-marking is done, sk_reg->id can be reset to 0.
119          *
120          * After "fullsock = bpf_sk_fullsock(sk);" at line 3,
121          * fullsock_reg->ref_obj_id is set to sk_reg->ref_obj_id.
122          *
123          * After "tp = bpf_tcp_sock(fullsock);" at line 5,
124          * tp_reg->ref_obj_id is set to fullsock_reg->ref_obj_id
125          * which is the same as sk_reg->ref_obj_id.
126          *
127          * From the verifier perspective, if sk, fullsock and tp
128          * are not NULL, they are the same ptr with different
129          * reg->type.  In particular, bpf_sk_release(tp) is also
130          * allowed and has the same effect as bpf_sk_release(sk).
131          */
132         u32 ref_obj_id;
133         /* For scalar types (SCALAR_VALUE), this represents our knowledge of
134          * the actual value.
135          * For pointer types, this represents the variable part of the offset
136          * from the pointed-to object, and is shared with all bpf_reg_states
137          * with the same id as us.
138          */
139         struct tnum var_off;
140         /* Used to determine if any memory access using this register will
141          * result in a bad access.
142          * These refer to the same value as var_off, not necessarily the actual
143          * contents of the register.
144          */
145         s64 smin_value; /* minimum possible (s64)value */
146         s64 smax_value; /* maximum possible (s64)value */
147         u64 umin_value; /* minimum possible (u64)value */
148         u64 umax_value; /* maximum possible (u64)value */
149         s32 s32_min_value; /* minimum possible (s32)value */
150         s32 s32_max_value; /* maximum possible (s32)value */
151         u32 u32_min_value; /* minimum possible (u32)value */
152         u32 u32_max_value; /* maximum possible (u32)value */
153         /* parentage chain for liveness checking */
154         struct bpf_reg_state *parent;
155         /* Inside the callee two registers can be both PTR_TO_STACK like
156          * R1=fp-8 and R2=fp-8, but one of them points to this function stack
157          * while another to the caller's stack. To differentiate them 'frameno'
158          * is used which is an index in bpf_verifier_state->frame[] array
159          * pointing to bpf_func_state.
160          */
161         u32 frameno;
162         /* Tracks subreg definition. The stored value is the insn_idx of the
163          * writing insn. This is safe because subreg_def is used before any insn
164          * patching which only happens after main verification finished.
165          */
166         s32 subreg_def;
167         enum bpf_reg_liveness live;
168         /* if (!precise && SCALAR_VALUE) min/max/tnum don't affect safety */
169         bool precise;
170 };
171
172 enum bpf_stack_slot_type {
173         STACK_INVALID,    /* nothing was stored in this stack slot */
174         STACK_SPILL,      /* register spilled into stack */
175         STACK_MISC,       /* BPF program wrote some data into this slot */
176         STACK_ZERO,       /* BPF program wrote constant zero */
177 };
178
179 #define BPF_REG_SIZE 8  /* size of eBPF register in bytes */
180
181 struct bpf_stack_state {
182         struct bpf_reg_state spilled_ptr;
183         u8 slot_type[BPF_REG_SIZE];
184 };
185
186 struct bpf_reference_state {
187         /* Track each reference created with a unique id, even if the same
188          * instruction creates the reference multiple times (eg, via CALL).
189          */
190         int id;
191         /* Instruction where the allocation of this reference occurred. This
192          * is used purely to inform the user of a reference leak.
193          */
194         int insn_idx;
195         /* There can be a case like:
196          * main (frame 0)
197          *  cb (frame 1)
198          *   func (frame 3)
199          *    cb (frame 4)
200          * Hence for frame 4, if callback_ref just stored boolean, it would be
201          * impossible to distinguish nested callback refs. Hence store the
202          * frameno and compare that to callback_ref in check_reference_leak when
203          * exiting a callback function.
204          */
205         int callback_ref;
206 };
207
208 /* state of the program:
209  * type of all registers and stack info
210  */
211 struct bpf_func_state {
212         struct bpf_reg_state regs[MAX_BPF_REG];
213         /* index of call instruction that called into this func */
214         int callsite;
215         /* stack frame number of this function state from pov of
216          * enclosing bpf_verifier_state.
217          * 0 = main function, 1 = first callee.
218          */
219         u32 frameno;
220         /* subprog number == index within subprog_info
221          * zero == main subprog
222          */
223         u32 subprogno;
224         /* Every bpf_timer_start will increment async_entry_cnt.
225          * It's used to distinguish:
226          * void foo(void) { for(;;); }
227          * void foo(void) { bpf_timer_set_callback(,foo); }
228          */
229         u32 async_entry_cnt;
230         bool in_callback_fn;
231         bool in_async_callback_fn;
232
233         /* The following fields should be last. See copy_func_state() */
234         int acquired_refs;
235         struct bpf_reference_state *refs;
236         int allocated_stack;
237         struct bpf_stack_state *stack;
238 };
239
240 struct bpf_idx_pair {
241         u32 prev_idx;
242         u32 idx;
243 };
244
245 struct bpf_id_pair {
246         u32 old;
247         u32 cur;
248 };
249
250 /* Maximum number of register states that can exist at once */
251 #define BPF_ID_MAP_SIZE (MAX_BPF_REG + MAX_BPF_STACK / BPF_REG_SIZE)
252 #define MAX_CALL_FRAMES 8
253 struct bpf_verifier_state {
254         /* call stack tracking */
255         struct bpf_func_state *frame[MAX_CALL_FRAMES];
256         struct bpf_verifier_state *parent;
257         /*
258          * 'branches' field is the number of branches left to explore:
259          * 0 - all possible paths from this state reached bpf_exit or
260          * were safely pruned
261          * 1 - at least one path is being explored.
262          * This state hasn't reached bpf_exit
263          * 2 - at least two paths are being explored.
264          * This state is an immediate parent of two children.
265          * One is fallthrough branch with branches==1 and another
266          * state is pushed into stack (to be explored later) also with
267          * branches==1. The parent of this state has branches==1.
268          * The verifier state tree connected via 'parent' pointer looks like:
269          * 1
270          * 1
271          * 2 -> 1 (first 'if' pushed into stack)
272          * 1
273          * 2 -> 1 (second 'if' pushed into stack)
274          * 1
275          * 1
276          * 1 bpf_exit.
277          *
278          * Once do_check() reaches bpf_exit, it calls update_branch_counts()
279          * and the verifier state tree will look:
280          * 1
281          * 1
282          * 2 -> 1 (first 'if' pushed into stack)
283          * 1
284          * 1 -> 1 (second 'if' pushed into stack)
285          * 0
286          * 0
287          * 0 bpf_exit.
288          * After pop_stack() the do_check() will resume at second 'if'.
289          *
290          * If is_state_visited() sees a state with branches > 0 it means
291          * there is a loop. If such state is exactly equal to the current state
292          * it's an infinite loop. Note states_equal() checks for states
293          * equvalency, so two states being 'states_equal' does not mean
294          * infinite loop. The exact comparison is provided by
295          * states_maybe_looping() function. It's a stronger pre-check and
296          * much faster than states_equal().
297          *
298          * This algorithm may not find all possible infinite loops or
299          * loop iteration count may be too high.
300          * In such cases BPF_COMPLEXITY_LIMIT_INSNS limit kicks in.
301          */
302         u32 branches;
303         u32 insn_idx;
304         u32 curframe;
305         u32 active_spin_lock;
306         bool speculative;
307
308         /* first and last insn idx of this verifier state */
309         u32 first_insn_idx;
310         u32 last_insn_idx;
311         /* jmp history recorded from first to last.
312          * backtracking is using it to go from last to first.
313          * For most states jmp_history_cnt is [0-3].
314          * For loops can go up to ~40.
315          */
316         struct bpf_idx_pair *jmp_history;
317         u32 jmp_history_cnt;
318 };
319
320 #define bpf_get_spilled_reg(slot, frame)                                \
321         (((slot < frame->allocated_stack / BPF_REG_SIZE) &&             \
322           (frame->stack[slot].slot_type[0] == STACK_SPILL))             \
323          ? &frame->stack[slot].spilled_ptr : NULL)
324
325 /* Iterate over 'frame', setting 'reg' to either NULL or a spilled register. */
326 #define bpf_for_each_spilled_reg(iter, frame, reg)                      \
327         for (iter = 0, reg = bpf_get_spilled_reg(iter, frame);          \
328              iter < frame->allocated_stack / BPF_REG_SIZE;              \
329              iter++, reg = bpf_get_spilled_reg(iter, frame))
330
331 /* Invoke __expr over regsiters in __vst, setting __state and __reg */
332 #define bpf_for_each_reg_in_vstate(__vst, __state, __reg, __expr)   \
333         ({                                                               \
334                 struct bpf_verifier_state *___vstate = __vst;            \
335                 int ___i, ___j;                                          \
336                 for (___i = 0; ___i <= ___vstate->curframe; ___i++) {    \
337                         struct bpf_reg_state *___regs;                   \
338                         __state = ___vstate->frame[___i];                \
339                         ___regs = __state->regs;                         \
340                         for (___j = 0; ___j < MAX_BPF_REG; ___j++) {     \
341                                 __reg = &___regs[___j];                  \
342                                 (void)(__expr);                          \
343                         }                                                \
344                         bpf_for_each_spilled_reg(___j, __state, __reg) { \
345                                 if (!__reg)                              \
346                                         continue;                        \
347                                 (void)(__expr);                          \
348                         }                                                \
349                 }                                                        \
350         })
351
352 /* linked list of verifier states used to prune search */
353 struct bpf_verifier_state_list {
354         struct bpf_verifier_state state;
355         struct bpf_verifier_state_list *next;
356         int miss_cnt, hit_cnt;
357 };
358
359 /* Possible states for alu_state member. */
360 #define BPF_ALU_SANITIZE_SRC            (1U << 0)
361 #define BPF_ALU_SANITIZE_DST            (1U << 1)
362 #define BPF_ALU_NEG_VALUE               (1U << 2)
363 #define BPF_ALU_NON_POINTER             (1U << 3)
364 #define BPF_ALU_IMMEDIATE               (1U << 4)
365 #define BPF_ALU_SANITIZE                (BPF_ALU_SANITIZE_SRC | \
366                                          BPF_ALU_SANITIZE_DST)
367
368 struct bpf_insn_aux_data {
369         union {
370                 enum bpf_reg_type ptr_type;     /* pointer type for load/store insns */
371                 unsigned long map_ptr_state;    /* pointer/poison value for maps */
372                 s32 call_imm;                   /* saved imm field of call insn */
373                 u32 alu_limit;                  /* limit for add/sub register with pointer */
374                 struct {
375                         u32 map_index;          /* index into used_maps[] */
376                         u32 map_off;            /* offset from value base address */
377                 };
378                 struct {
379                         enum bpf_reg_type reg_type;     /* type of pseudo_btf_id */
380                         union {
381                                 struct {
382                                         struct btf *btf;
383                                         u32 btf_id;     /* btf_id for struct typed var */
384                                 };
385                                 u32 mem_size;   /* mem_size for non-struct typed var */
386                         };
387                 } btf_var;
388         };
389         u64 map_key_state; /* constant (32 bit) key tracking for maps */
390         int ctx_field_size; /* the ctx field size for load insn, maybe 0 */
391         u32 seen; /* this insn was processed by the verifier at env->pass_cnt */
392         bool sanitize_stack_spill; /* subject to Spectre v4 sanitation */
393         bool zext_dst; /* this insn zero extends dst reg */
394         u8 alu_state; /* used in combination with alu_limit */
395
396         /* below fields are initialized once */
397         unsigned int orig_idx; /* original instruction index */
398         bool prune_point;
399 };
400
401 #define MAX_USED_MAPS 64 /* max number of maps accessed by one eBPF program */
402 #define MAX_USED_BTFS 64 /* max number of BTFs accessed by one BPF program */
403
404 #define BPF_VERIFIER_TMP_LOG_SIZE       1024
405
406 struct bpf_verifier_log {
407         u32 level;
408         char kbuf[BPF_VERIFIER_TMP_LOG_SIZE];
409         char __user *ubuf;
410         u32 len_used;
411         u32 len_total;
412 };
413
414 static inline bool bpf_verifier_log_full(const struct bpf_verifier_log *log)
415 {
416         return log->len_used >= log->len_total - 1;
417 }
418
419 #define BPF_LOG_LEVEL1  1
420 #define BPF_LOG_LEVEL2  2
421 #define BPF_LOG_STATS   4
422 #define BPF_LOG_LEVEL   (BPF_LOG_LEVEL1 | BPF_LOG_LEVEL2)
423 #define BPF_LOG_MASK    (BPF_LOG_LEVEL | BPF_LOG_STATS)
424 #define BPF_LOG_KERNEL  (BPF_LOG_MASK + 1) /* kernel internal flag */
425
426 static inline bool bpf_verifier_log_needed(const struct bpf_verifier_log *log)
427 {
428         return log &&
429                 ((log->level && log->ubuf && !bpf_verifier_log_full(log)) ||
430                  log->level == BPF_LOG_KERNEL);
431 }
432
433 static inline bool
434 bpf_verifier_log_attr_valid(const struct bpf_verifier_log *log)
435 {
436         return log->len_total >= 128 && log->len_total <= UINT_MAX >> 2 &&
437                log->level && log->ubuf && !(log->level & ~BPF_LOG_MASK);
438 }
439
440 #define BPF_MAX_SUBPROGS 256
441
442 struct bpf_subprog_info {
443         /* 'start' has to be the first field otherwise find_subprog() won't work */
444         u32 start; /* insn idx of function entry point */
445         u32 linfo_idx; /* The idx to the main_prog->aux->linfo */
446         u16 stack_depth; /* max. stack depth used by this function */
447         bool has_tail_call;
448         bool tail_call_reachable;
449         bool has_ld_abs;
450         bool is_async_cb;
451 };
452
453 /* single container for all structs
454  * one verifier_env per bpf_check() call
455  */
456 struct bpf_verifier_env {
457         u32 insn_idx;
458         u32 prev_insn_idx;
459         struct bpf_prog *prog;          /* eBPF program being verified */
460         const struct bpf_verifier_ops *ops;
461         struct bpf_verifier_stack_elem *head; /* stack of verifier states to be processed */
462         int stack_size;                 /* number of states to be processed */
463         bool strict_alignment;          /* perform strict pointer alignment checks */
464         bool test_state_freq;           /* test verifier with different pruning frequency */
465         struct bpf_verifier_state *cur_state; /* current verifier state */
466         struct bpf_verifier_state_list **explored_states; /* search pruning optimization */
467         struct bpf_verifier_state_list *free_list;
468         struct bpf_map *used_maps[MAX_USED_MAPS]; /* array of map's used by eBPF program */
469         struct btf_mod_pair used_btfs[MAX_USED_BTFS]; /* array of BTF's used by BPF program */
470         u32 used_map_cnt;               /* number of used maps */
471         u32 used_btf_cnt;               /* number of used BTF objects */
472         u32 id_gen;                     /* used to generate unique reg IDs */
473         bool explore_alu_limits;
474         bool allow_ptr_leaks;
475         bool allow_uninit_stack;
476         bool allow_ptr_to_map_access;
477         bool bpf_capable;
478         bool bypass_spec_v1;
479         bool bypass_spec_v4;
480         bool seen_direct_write;
481         struct bpf_insn_aux_data *insn_aux_data; /* array of per-insn state */
482         const struct bpf_line_info *prev_linfo;
483         struct bpf_verifier_log log;
484         struct bpf_subprog_info subprog_info[BPF_MAX_SUBPROGS + 1];
485         struct bpf_id_pair idmap_scratch[BPF_ID_MAP_SIZE];
486         struct {
487                 int *insn_state;
488                 int *insn_stack;
489                 int cur_stack;
490         } cfg;
491         u32 pass_cnt; /* number of times do_check() was called */
492         u32 subprog_cnt;
493         /* number of instructions analyzed by the verifier */
494         u32 prev_insn_processed, insn_processed;
495         /* number of jmps, calls, exits analyzed so far */
496         u32 prev_jmps_processed, jmps_processed;
497         /* total verification time */
498         u64 verification_time;
499         /* maximum number of verifier states kept in 'branching' instructions */
500         u32 max_states_per_insn;
501         /* total number of allocated verifier states */
502         u32 total_states;
503         /* some states are freed during program analysis.
504          * this is peak number of states. this number dominates kernel
505          * memory consumption during verification
506          */
507         u32 peak_states;
508         /* longest register parentage chain walked for liveness marking */
509         u32 longest_mark_read_walk;
510         bpfptr_t fd_array;
511         /* buffer used in reg_type_str() to generate reg_type string */
512         char type_str_buf[TYPE_STR_BUF_LEN];
513 };
514
515 __printf(2, 0) void bpf_verifier_vlog(struct bpf_verifier_log *log,
516                                       const char *fmt, va_list args);
517 __printf(2, 3) void bpf_verifier_log_write(struct bpf_verifier_env *env,
518                                            const char *fmt, ...);
519 __printf(2, 3) void bpf_log(struct bpf_verifier_log *log,
520                             const char *fmt, ...);
521
522 static inline struct bpf_func_state *cur_func(struct bpf_verifier_env *env)
523 {
524         struct bpf_verifier_state *cur = env->cur_state;
525
526         return cur->frame[cur->curframe];
527 }
528
529 static inline struct bpf_reg_state *cur_regs(struct bpf_verifier_env *env)
530 {
531         return cur_func(env)->regs;
532 }
533
534 int bpf_prog_offload_verifier_prep(struct bpf_prog *prog);
535 int bpf_prog_offload_verify_insn(struct bpf_verifier_env *env,
536                                  int insn_idx, int prev_insn_idx);
537 int bpf_prog_offload_finalize(struct bpf_verifier_env *env);
538 void
539 bpf_prog_offload_replace_insn(struct bpf_verifier_env *env, u32 off,
540                               struct bpf_insn *insn);
541 void
542 bpf_prog_offload_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt);
543
544 int check_ctx_reg(struct bpf_verifier_env *env,
545                   const struct bpf_reg_state *reg, int regno);
546 int check_mem_reg(struct bpf_verifier_env *env, struct bpf_reg_state *reg,
547                    u32 regno, u32 mem_size);
548
549 /* this lives here instead of in bpf.h because it needs to dereference tgt_prog */
550 static inline u64 bpf_trampoline_compute_key(const struct bpf_prog *tgt_prog,
551                                              struct btf *btf, u32 btf_id)
552 {
553         if (tgt_prog)
554                 return ((u64)tgt_prog->aux->id << 32) | btf_id;
555         else
556                 return ((u64)btf_obj_id(btf) << 32) | 0x80000000 | btf_id;
557 }
558
559 /* unpack the IDs from the key as constructed above */
560 static inline void bpf_trampoline_unpack_key(u64 key, u32 *obj_id, u32 *btf_id)
561 {
562         if (obj_id)
563                 *obj_id = key >> 32;
564         if (btf_id)
565                 *btf_id = key & 0x7FFFFFFF;
566 }
567
568 int bpf_check_attach_target(struct bpf_verifier_log *log,
569                             const struct bpf_prog *prog,
570                             const struct bpf_prog *tgt_prog,
571                             u32 btf_id,
572                             struct bpf_attach_target_info *tgt_info);
573
574 #define BPF_BASE_TYPE_MASK      GENMASK(BPF_BASE_TYPE_BITS - 1, 0)
575
576 /* extract base type from bpf_{arg, return, reg}_type. */
577 static inline u32 base_type(u32 type)
578 {
579         return type & BPF_BASE_TYPE_MASK;
580 }
581
582 /* extract flags from an extended type. See bpf_type_flag in bpf.h. */
583 static inline u32 type_flag(u32 type)
584 {
585         return type & ~BPF_BASE_TYPE_MASK;
586 }
587
588 #endif /* _LINUX_BPF_VERIFIER_H */