Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\bpf\btf.c Create Date:2022-07-28 13:21:12
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:btf_struct_access

Proto:int btf_struct_access(struct bpf_verifier_log *log, const struct btf_type *t, int off, int size, enum bpf_access_type atype, u32 *next_btf_id)

Type:int

Parameter:

TypeParameterName
struct bpf_verifier_log *log
const struct btf_type *t
intoff
intsize
enum bpf_access_typeatype
u32 *next_btf_id
3732  msize = 0 , total_nelems = 0
3733  const struct btf_type * mtype, * elem_type = NULL
3737  again :
3738  tname = __btf_name_by_offset(btf_vmlinux, name_off)
3739  If Not is only a special case of struct:* all its offsetof(member) == 0 Then
3740  bpf_log(log, "Type '%s' is not a struct", tname)
3741  Return -EINVAL
3745  If btf_member_bitfield_size(t, member) Then Continue
3750  moff = btf_member_bit_offset(t, member) / 8
3751  If off + size <= moff Then Break
3755  If off < moff Then Continue
3759  mtype = btf_type_by_id(btf_vmlinux, type)
3760  mname = __btf_name_by_offset(btf_vmlinux, name_off)
3762  mtype = Resolve the size of a passed-in "type"* return type: type "u32[x][y]", i.e. BTF_KIND_ARRAY,* *type_size: (x * y * sizeof(u32)). Hence, *type_size always* corresponds to the return type.* *elem_type: u32* *total_nelems: (x * y)
3764  If IS_ERR(mtype) Then
3765  bpf_log(log, "field %s doesn't have size\n", mname)
3766  Return -EFAULT
3769  mtrue_end = moff + msize
3770  If off >= mtrue_end Then Continue
3774  If btf_type_is_array(mtype) Then
3818  If moff == mtrue_end Then Continue
3821  msize /= total_nelems
3822  elem_idx = (off - moff) / msize
3823  moff += elem_idx * msize
3824  mtype = elem_type
3832  t = mtype
3835  off -= moff
3836  Go to again
3839  If btf_type_is_ptr(mtype) Then
3842  If msize != size || off != moff Then
3843  bpf_log(log, "cannot access ptr member %s with moff %u in struct %s with off %u size %u\n", mname, moff, tname, off, size)
3846  Return -EACCES
3865  If off + size > mtrue_end Then
3866  bpf_log(log, "access beyond the end of member %s (mend:%u) in struct %s with off %u size %u\n", mname, mtrue_end, tname, off, size)
3869  Return -EACCES
3872  Return g doesn't contain a valid pointer
3874  bpf_log(log, "struct %s doesn't have field at offset %d\n", tname, off)
3875  Return -EINVAL
Caller
NameDescribe
check_ptr_to_btf_access