Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:WARNING: This function does calculations on 64-bit values, but the actual* execution may occur on 32-bit values. Therefore, things like bitshifts* need extra checks in the 32-bit case.

Proto:static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env, struct bpf_insn *insn, struct bpf_reg_state *dst_reg, struct bpf_reg_state src_reg)

Type:int

Parameter:

TypeParameterName
struct bpf_verifier_env *env
struct bpf_insn *insn
struct bpf_reg_state *dst_reg
struct bpf_reg_statesrc_reg
4808  regs = cur_regs(env)
4809  opcode = alu/jmp fields ( opcode )
4813  insn_bitness = If Instruction classes ( opcode ) == alu mode in double word width Then 64 Else 32
4814  dst = dest register
4817  If insn_bitness == 32 Then
4822  runcate register to smaller size (in bytes)* must be called with size < BPF_REG_SIZE
4823  runcate register to smaller size (in bytes)* must be called with size < BPF_REG_SIZE
4826  smin_val = minimum possible (s64)value
4827  smax_val = maximum possible (s64)value
4828  umin_val = minimum possible (u64)value
4829  umax_val = maximum possible (u64)value
4830  src_known = Returns true if @a is a known constant
4831  dst_known = Returns true if @a is a known constant
4833  If src_known && ( smin_val != smax_val || umin_val != umax_val ) || smin_val > smax_val || umin_val > umax_val Then
4838  Mark a register as having a completely unknown (scalar) value.
4839  Return 0
4842  If Not src_known && opcode != BPF_ADD && opcode != BPF_SUB && opcode != BPF_AND Then
4844  Mark a register as having a completely unknown (scalar) value.
4845  Return 0
4849  Case opcode == BPF_ADD
4851  If ret < 0 Then
4852  verbose(env, "R%d tried to add from different pointers or scalars\n", dst)
4853  Return ret
4859  Else
4867  Else
4872  Break
4873  Case opcode == BPF_SUB
4875  If ret < 0 Then
4876  verbose(env, "R%d tried to sub from different pointers or scalars\n", dst)
4877  Return ret
4884  Else
4892  Else
4898  Break
4899  Case opcode == BPF_MUL
4901  If smin_val < 0 || minimum possible (s64)value < 0 Then
4923  Else
4927  Break
4928  Case opcode == BPF_AND
4929  If src_known && dst_known Then
4940  If minimum possible (s64)value < 0 || smin_val < 0 Then
4946  Else
4955  Break
4956  Case opcode == BPF_OR
4957  If src_known && dst_known Then
4969  If minimum possible (s64)value < 0 || smin_val < 0 Then
4975  Else
4984  Break
4985  Case opcode == BPF_LSH
4986  If umax_val >= insn_bitness Then
4991  Break
4999  If maximum possible (u64)value > 1ULL << 63 - umax_val Then
5002  Else
5009  Break
5010  Case opcode == BPF_RSH
5011  If umax_val >= insn_bitness Then
5016  Break
5039  Break
5041  If umax_val >= insn_bitness Then
5046  Break
5052  If insn_bitness == 32 Then
5055  Else
5069  Break
5070  Default
5072  Break
5080  Uses signed min/max values to inform unsigned, and vice-versa
5081  Attempts to improve var_off based on unsigned min/max information
5082  Return 0
Caller
NameDescribe
adjust_reg_min_max_valsHandles ALU ops other than BPF_END, BPF_NEG and BPF_MOV: computes new min/max* and var_off.