Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\bpf\verifier.c Create Date:2022-07-28 13:05:46
Last Modify:2022-05-19 20:02:10 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:check_attach_btf_id

Proto:static int check_attach_btf_id(struct bpf_verifier_env *env)

Type:int

Parameter:

TypeParameterName
struct bpf_verifier_env *env
9518  prog = BPF program being verified
9519  tgt_prog = linked_prog
9520  btf_id = in-kernel BTF type id to attach to
9521  prefix[] = "btf_trace_"
9522  ret = 0 , subprog = -1
9525  bool conservative = true
9531  If Type of BPF program != BPF_PROG_TYPE_TRACING Then Return 0
9534  If Not btf_id Then
9535  verbose(env, "Tracing programs must provide btf_id\n")
9536  Return -EINVAL
9538  btf = bpf_prog_get_target_btf(prog)
9539  If Not btf Then
9540  verbose(env, "FENTRY/FEXIT program can only be attached to another program annotated with BTF\n")
9542  Return -EINVAL
9544  t = btf_type_by_id(btf, btf_id)
9545  If Not t Then
9546  verbose(env, "attach_btf_id %u is invalid\n", btf_id)
9547  Return -EINVAL
9549  tname = btf_name_by_offset(btf, name_off)
9550  If Not tname Then
9551  verbose(env, "attach_btf_id %u doesn't have a name\n", btf_id)
9552  Return -EINVAL
9554  If tgt_prog Then
9555  aux = Auxiliary fields
9557  When i < func_info_cnt cycle If type_id == btf_id Then
9559  subprog = i
9560  Break
9562  If subprog == -1 Then
9563  verbose(env, "Subprog %s doesn't exist\n", tname)
9564  Return -EINVAL
9566  conservative = unreliable
9567  key = id << 32 | btf_id
9568  Else
9569  key = btf_id
9574  If tgt_prog Then
9575  verbose(env, "Only FENTRY/FEXIT progs are attachable to another BPF prog\n")
9577  Return -EINVAL
9579  If Not btf_type_is_typedef(t) Then
9580  verbose(env, "attach_btf_id %u is not a typedef\n", btf_id)
9582  Return -EINVAL
9584  If strncmp(prefix, tname, size of prefix - 1) Then
9585  verbose(env, "attach_btf_id %u points to wrong type name %s\n", btf_id, tname)
9587  Return -EINVAL
9589  tname += size of prefix - 1
9590  t = btf_type_by_id(btf, type)
9591  If Not btf_type_is_ptr(t) Then Return -EINVAL
9594  t = btf_type_by_id(btf, type)
9595  If Not btf_type_is_func_proto(t) Then Return -EINVAL
9605  Return 0
9606  Case For some prog types == BPF_TRACE_FENTRY
9608  If Not btf_type_is_func(t) Then
9609  verbose(env, "attach_btf_id %u is not a function\n", btf_id)
9611  Return -EINVAL
9613  t = btf_type_by_id(btf, type)
9614  If Not btf_type_is_func_proto(t) Then Return -EINVAL
9617  If Not tr Then Return -ENOMEM
9623  If addr Then
9624  trampoline = tr
9625  Go to out
9627  If tgt_prog && conservative Then
9633  If ret < 0 Then Go to out
9635  If tgt_prog Then
9636  If Not Is our filter JIT'ed? Then
9638  verbose(env, "Can trace only JITed BPF progs\n")
9639  ret = -EINVAL
9640  Go to out
9644  verbose(env, "Cannot recursively attach\n")
9645  ret = -EINVAL
9646  Go to out
9648  If subprog == 0 Then addr = bpf_func
9650  Else addr = bpf_func
9652  Else
9654  If Not addr Then
9655  verbose(env, "The address of function %s cannot be found\n", tname)
9658  ret = -ENOENT
9659  Go to out
9662  addr = addr
9663  trampoline = tr
9664  out :
9666  If ret Then bpf_trampoline_put(tr)
9668  Return ret
9669  Default
9670  Return -EINVAL
Caller
NameDescribe
bpf_check