Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:check_btf_func

Proto:static int check_btf_func(struct bpf_verifier_env *env, const union bpf_attr *attr, union bpf_attr __user *uattr)

Type:int

Parameter:

TypeParameterName
struct bpf_verifier_env *env
const union bpf_attr *attr
union bpf_attr __user *uattr
6669  krec_size = sizeof(structbpf_func_info)
6671  struct bpf_func_info_aux * info_aux = NULL
6675  __user * urecord
6676  prev_offset = 0
6677  ret = 0
6679  nfuncs = number of bpf_func_info records
6680  If Not nfuncs Then Return 0
6683  If nfuncs != subprog_cnt Then
6684  verbose(env, "number of funcs in func_info doesn't match number of subprogs\n")
6685  Return -EINVAL
6688  urec_size = userspace bpf_func_info size
6689  If urec_size < The minimum supported BTF func info size || urec_size > MAX_FUNCINFO_REC_SIZE || urec_size % sizeof(u32) Then
6692  verbose(env, "invalid func info rec size %u\n", urec_size)
6693  Return -EINVAL
6696  prog = BPF program being verified
6697  btf = btf
6699  urecord = u64_to_user_ptr(func_info)
6700  min_size = min_t - return minimum of two values, using the specified type*@type: data type to use*@x: first value*@y: second value(u32, krec_size, urec_size)
6702  krecord = kvcalloc(nfuncs, krec_size, GFP_KERNEL | DOC: Action modifiers* Action modifiers* ~~~~~~~~~~~~~~~~* %__GFP_NOWARN suppresses allocation failure reports.* %__GFP_COMP address compound page metadata.* %__GFP_ZERO returns a zeroed page on success.)
6703  If Not krecord Then Return -ENOMEM
6705  info_aux = kcalloc - allocate memory for an array. The memory is set to zero.*@n: number of elements.*@size: element size.*@flags: the type of memory to allocate (see kmalloc).
6706  If Not info_aux Then Go to err_free
6709  When i < nfuncs cycle
6710  ret = If we're handed a bigger struct than we know of, ensure all the unknown bits* are 0 - i.e. new user-space does not rely on any kernel feature extensions* we don't know about yet.* There is a ToCToU between this function call and the following
6711  If ret Then
6712  If ret == -E2BIG Then
6713  verbose(env, "nonzero tailing record in func info")
6720  Go to err_free
6723  If copy_from_user( & krecord[i], urecord, min_size) Then
6724  ret = -EFAULT
6725  Go to err_free
6729  If i == 0 Then
6730  If insn_off Then
6731  verbose(env, "nonzero insn_off %u for the first func info record", insn_off)
6734  ret = -EINVAL
6735  Go to err_free
6737  Else if insn_off <= prev_offset Then
6738  verbose(env, "same or smaller insn offset (%u) than previous func info record (%u)", insn_off, prev_offset)
6741  ret = -EINVAL
6742  Go to err_free
6746  verbose(env, "func_info BTF section doesn't match subprog layout in BPF program\n")
6747  ret = -EINVAL
6748  Go to err_free
6752  type = btf_type_by_id(btf, type_id)
6754  verbose(env, "invalid type id %d in func info", type_id)
6756  ret = -EINVAL
6757  Go to err_free
6759  prev_offset = insn_off
6760  urecord += urec_size
6763  func_info = krecord
6764  func_info_cnt = nfuncs
6765  func_info_aux = info_aux
6766  Return 0
6768  err_free :
6769  kvfree(krecord)
6770  kfree(info_aux)
6771  Return ret
Caller
NameDescribe
check_btf_info