@@ -420,25 +420,6 @@ static struct btf_record *reg_btf_record(const struct bpf_reg_state *reg)
420
420
return rec;
421
421
}
422
422
423
- static bool mask_raw_tp_reg_cond(const struct bpf_verifier_env *env, struct bpf_reg_state *reg) {
424
- return reg->type == (PTR_TO_BTF_ID | PTR_TRUSTED | PTR_MAYBE_NULL) &&
425
- bpf_prog_is_raw_tp(env->prog) && !reg->ref_obj_id;
426
- }
427
-
428
- static bool mask_raw_tp_reg(const struct bpf_verifier_env *env, struct bpf_reg_state *reg)
429
- {
430
- if (!mask_raw_tp_reg_cond(env, reg))
431
- return false;
432
- reg->type &= ~PTR_MAYBE_NULL;
433
- return true;
434
- }
435
-
436
- static void unmask_raw_tp_reg(struct bpf_reg_state *reg, bool result)
437
- {
438
- if (result)
439
- reg->type |= PTR_MAYBE_NULL;
440
- }
441
-
442
423
static bool subprog_is_global(const struct bpf_verifier_env *env, int subprog)
443
424
{
444
425
struct bpf_func_info_aux *aux = env->prog->aux->func_info_aux;
@@ -6801,7 +6782,6 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
6801
6782
const char *field_name = NULL;
6802
6783
enum bpf_type_flag flag = 0;
6803
6784
u32 btf_id = 0;
6804
- bool mask;
6805
6785
int ret;
6806
6786
6807
6787
if (!env->allow_ptr_leaks) {
@@ -6873,21 +6853,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
6873
6853
6874
6854
if (ret < 0)
6875
6855
return ret;
6876
- /* For raw_tp progs, we allow dereference of PTR_MAYBE_NULL
6877
- * trusted PTR_TO_BTF_ID, these are the ones that are possibly
6878
- * arguments to the raw_tp. Since internal checks in for trusted
6879
- * reg in check_ptr_to_btf_access would consider PTR_MAYBE_NULL
6880
- * modifier as problematic, mask it out temporarily for the
6881
- * check. Don't apply this to pointers with ref_obj_id > 0, as
6882
- * those won't be raw_tp args.
6883
- *
6884
- * We may end up applying this relaxation to other trusted
6885
- * PTR_TO_BTF_ID with maybe null flag, since we cannot
6886
- * distinguish PTR_MAYBE_NULL tagged for arguments vs normal
6887
- * tagging, but that should expand allowed behavior, and not
6888
- * cause regression for existing behavior.
6889
- */
6890
- mask = mask_raw_tp_reg(env, reg);
6856
+
6891
6857
if (ret != PTR_TO_BTF_ID) {
6892
6858
/* just mark; */
6893
6859
@@ -6948,13 +6914,8 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
6948
6914
clear_trusted_flags(&flag);
6949
6915
}
6950
6916
6951
- if (atype == BPF_READ && value_regno >= 0) {
6917
+ if (atype == BPF_READ && value_regno >= 0)
6952
6918
mark_btf_ld_reg(env, regs, value_regno, ret, reg->btf, btf_id, flag);
6953
- /* We've assigned a new type to regno, so don't undo masking. */
6954
- if (regno == value_regno)
6955
- mask = false;
6956
- }
6957
- unmask_raw_tp_reg(reg, mask);
6958
6919
6959
6920
return 0;
6960
6921
}
@@ -7329,7 +7290,7 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regn
7329
7290
if (!err && t == BPF_READ && value_regno >= 0)
7330
7291
mark_reg_unknown(env, regs, value_regno);
7331
7292
} else if (base_type(reg->type) == PTR_TO_BTF_ID &&
7332
- (mask_raw_tp_reg_cond(env, reg) || !type_may_be_null(reg->type) )) {
7293
+ !type_may_be_null(reg->type)) {
7333
7294
err = check_ptr_to_btf_access(env, regs, regno, off, size, t,
7334
7295
value_regno);
7335
7296
} else if (reg->type == CONST_PTR_TO_MAP) {
@@ -9032,7 +8993,6 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
9032
8993
enum bpf_reg_type type = reg->type;
9033
8994
u32 *arg_btf_id = NULL;
9034
8995
int err = 0;
9035
- bool mask;
9036
8996
9037
8997
if (arg_type == ARG_DONTCARE)
9038
8998
return 0;
@@ -9073,11 +9033,11 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
9073
9033
base_type(arg_type) == ARG_PTR_TO_SPIN_LOCK)
9074
9034
arg_btf_id = fn->arg_btf_id[arg];
9075
9035
9076
- mask = mask_raw_tp_reg(env, reg);
9077
9036
err = check_reg_type(env, regno, arg_type, arg_btf_id, meta);
9037
+ if (err)
9038
+ return err;
9078
9039
9079
- err = err ?: check_func_arg_reg_off(env, reg, regno, arg_type);
9080
- unmask_raw_tp_reg(reg, mask);
9040
+ err = check_func_arg_reg_off(env, reg, regno, arg_type);
9081
9041
if (err)
9082
9042
return err;
9083
9043
@@ -9872,17 +9832,14 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
9872
9832
return ret;
9873
9833
} else if (base_type(arg->arg_type) == ARG_PTR_TO_BTF_ID) {
9874
9834
struct bpf_call_arg_meta meta;
9875
- bool mask;
9876
9835
int err;
9877
9836
9878
9837
if (register_is_null(reg) && type_may_be_null(arg->arg_type))
9879
9838
continue;
9880
9839
9881
9840
memset(&meta, 0, sizeof(meta)); /* leave func_id as zero */
9882
- mask = mask_raw_tp_reg(env, reg);
9883
9841
err = check_reg_type(env, regno, arg->arg_type, &arg->btf_id, &meta);
9884
9842
err = err ?: check_func_arg_reg_off(env, reg, regno, arg->arg_type);
9885
- unmask_raw_tp_reg(reg, mask);
9886
9843
if (err)
9887
9844
return err;
9888
9845
} else {
@@ -12205,7 +12162,6 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
12205
12162
enum bpf_arg_type arg_type = ARG_DONTCARE;
12206
12163
u32 regno = i + 1, ref_id, type_size;
12207
12164
bool is_ret_buf_sz = false;
12208
- bool mask = false;
12209
12165
int kf_arg_type;
12210
12166
12211
12167
t = btf_type_skip_modifiers(btf, args[i].type, NULL);
@@ -12264,15 +12220,12 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
12264
12220
return -EINVAL;
12265
12221
}
12266
12222
12267
- mask = mask_raw_tp_reg(env, reg);
12268
12223
if ((is_kfunc_trusted_args(meta) || is_kfunc_rcu(meta)) &&
12269
12224
(register_is_null(reg) || type_may_be_null(reg->type)) &&
12270
12225
!is_kfunc_arg_nullable(meta->btf, &args[i])) {
12271
12226
verbose(env, "Possibly NULL pointer passed to trusted arg%d\n", i);
12272
- unmask_raw_tp_reg(reg, mask);
12273
12227
return -EACCES;
12274
12228
}
12275
- unmask_raw_tp_reg(reg, mask);
12276
12229
12277
12230
if (reg->ref_obj_id) {
12278
12231
if (is_kfunc_release(meta) && meta->ref_obj_id) {
@@ -12330,24 +12283,16 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
12330
12283
if (!is_kfunc_trusted_args(meta) && !is_kfunc_rcu(meta))
12331
12284
break;
12332
12285
12333
- /* Allow passing maybe NULL raw_tp arguments to
12334
- * kfuncs for compatibility. Don't apply this to
12335
- * arguments with ref_obj_id > 0.
12336
- */
12337
- mask = mask_raw_tp_reg(env, reg);
12338
12286
if (!is_trusted_reg(reg)) {
12339
12287
if (!is_kfunc_rcu(meta)) {
12340
12288
verbose(env, "R%d must be referenced or trusted\n", regno);
12341
- unmask_raw_tp_reg(reg, mask);
12342
12289
return -EINVAL;
12343
12290
}
12344
12291
if (!is_rcu_reg(reg)) {
12345
12292
verbose(env, "R%d must be a rcu pointer\n", regno);
12346
- unmask_raw_tp_reg(reg, mask);
12347
12293
return -EINVAL;
12348
12294
}
12349
12295
}
12350
- unmask_raw_tp_reg(reg, mask);
12351
12296
fallthrough;
12352
12297
case KF_ARG_PTR_TO_CTX:
12353
12298
case KF_ARG_PTR_TO_DYNPTR:
@@ -12370,9 +12315,7 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
12370
12315
12371
12316
if (is_kfunc_release(meta) && reg->ref_obj_id)
12372
12317
arg_type |= OBJ_RELEASE;
12373
- mask = mask_raw_tp_reg(env, reg);
12374
12318
ret = check_func_arg_reg_off(env, reg, regno, arg_type);
12375
- unmask_raw_tp_reg(reg, mask);
12376
12319
if (ret < 0)
12377
12320
return ret;
12378
12321
@@ -12549,7 +12492,6 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
12549
12492
ref_tname = btf_name_by_offset(btf, ref_t->name_off);
12550
12493
fallthrough;
12551
12494
case KF_ARG_PTR_TO_BTF_ID:
12552
- mask = mask_raw_tp_reg(env, reg);
12553
12495
/* Only base_type is checked, further checks are done here */
12554
12496
if ((base_type(reg->type) != PTR_TO_BTF_ID ||
12555
12497
(bpf_type_has_unsafe_modifiers(reg->type) && !is_rcu_reg(reg))) &&
@@ -12558,11 +12500,9 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
12558
12500
verbose(env, "expected %s or socket\n",
12559
12501
reg_type_str(env, base_type(reg->type) |
12560
12502
(type_flag(reg->type) & BPF_REG_TRUSTED_MODIFIERS)));
12561
- unmask_raw_tp_reg(reg, mask);
12562
12503
return -EINVAL;
12563
12504
}
12564
12505
ret = process_kf_arg_ptr_to_btf_id(env, reg, ref_t, ref_tname, ref_id, meta, i);
12565
- unmask_raw_tp_reg(reg, mask);
12566
12506
if (ret < 0)
12567
12507
return ret;
12568
12508
break;
@@ -13535,7 +13475,7 @@ static int sanitize_check_bounds(struct bpf_verifier_env *env,
13535
13475
*/
13536
13476
static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
13537
13477
struct bpf_insn *insn,
13538
- struct bpf_reg_state *ptr_reg,
13478
+ const struct bpf_reg_state *ptr_reg,
13539
13479
const struct bpf_reg_state *off_reg)
13540
13480
{
13541
13481
struct bpf_verifier_state *vstate = env->cur_state;
@@ -13549,7 +13489,6 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
13549
13489
struct bpf_sanitize_info info = {};
13550
13490
u8 opcode = BPF_OP(insn->code);
13551
13491
u32 dst = insn->dst_reg;
13552
- bool mask;
13553
13492
int ret;
13554
13493
13555
13494
dst_reg = ®s[dst];
@@ -13576,14 +13515,11 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
13576
13515
return -EACCES;
13577
13516
}
13578
13517
13579
- mask = mask_raw_tp_reg(env, ptr_reg);
13580
13518
if (ptr_reg->type & PTR_MAYBE_NULL) {
13581
13519
verbose(env, "R%d pointer arithmetic on %s prohibited, null-check it first\n",
13582
13520
dst, reg_type_str(env, ptr_reg->type));
13583
- unmask_raw_tp_reg(ptr_reg, mask);
13584
13521
return -EACCES;
13585
13522
}
13586
- unmask_raw_tp_reg(ptr_reg, mask);
13587
13523
13588
13524
switch (base_type(ptr_reg->type)) {
13589
13525
case PTR_TO_CTX:
@@ -20126,7 +20062,6 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
20126
20062
* for this case.
20127
20063
*/
20128
20064
case PTR_TO_BTF_ID | MEM_ALLOC | PTR_UNTRUSTED:
20129
- case PTR_TO_BTF_ID | PTR_TRUSTED | PTR_MAYBE_NULL:
20130
20065
if (type == BPF_READ) {
20131
20066
if (BPF_MODE(insn->code) == BPF_MEM)
20132
20067
insn->code = BPF_LDX | BPF_PROBE_MEM |
0 commit comments