Skip to content

Commit d588304

Browse files
aspskKernel Patches Daemon
authored andcommitted
bpf: check for insn arrays in check_ptr_alignment
Do not abuse the strict_alignment_once flag, and check if the map is an instruction array inside the check_ptr_alignment() function. Suggested-by: Alexei Starovoitov <[email protected]> Signed-off-by: Anton Protopopov <[email protected]>
1 parent 8c83cb5 commit d588304

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

kernel/bpf/verifier.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6482,6 +6482,8 @@ static int check_ptr_alignment(struct bpf_verifier_env *env,
64826482
break;
64836483
case PTR_TO_MAP_VALUE:
64846484
pointer_desc = "value ";
6485+
if (reg->map_ptr->map_type == BPF_MAP_TYPE_INSN_ARRAY)
6486+
strict = true;
64856487
break;
64866488
case PTR_TO_CTX:
64876489
pointer_desc = "context ";
@@ -7529,16 +7531,14 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regn
75297531
{
75307532
struct bpf_reg_state *regs = cur_regs(env);
75317533
struct bpf_reg_state *reg = regs + regno;
7532-
bool insn_array = reg->type == PTR_TO_MAP_VALUE &&
7533-
reg->map_ptr->map_type == BPF_MAP_TYPE_INSN_ARRAY;
75347534
int size, err = 0;
75357535

75367536
size = bpf_size_to_bytes(bpf_size);
75377537
if (size < 0)
75387538
return size;
75397539

75407540
/* alignment checks will add in reg->off themselves */
7541-
err = check_ptr_alignment(env, reg, off, size, strict_alignment_once || insn_array);
7541+
err = check_ptr_alignment(env, reg, off, size, strict_alignment_once);
75427542
if (err)
75437543
return err;
75447544

0 commit comments

Comments
 (0)