Re: [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in check_stack_range_initialized
From: Edward Adam Davis
Date: Wed Mar 20 2024 - 19:57:19 EST
please test oob in check_stack_range_initialized
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git master
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1dd3b99d1bb9..7ba5b4131929 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -7177,6 +7177,11 @@ static int check_stack_range_initialized(
return 0;
}
+ if (INT_MIN - access_size > max_off) {
+ verbose(env, "invalid access size\n");
+ return -EACCES;
+ }
+
for (i = min_off; i < max_off + access_size; i++) {
u8 *stype;
@@ -8589,6 +8594,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
return 0;
}
+ printk("1meta:%p, maptr:%p, ks:%d, kv:%d,%s\n",
+ meta, meta->map_ptr, meta->map_ptr->key_size, meta->map_ptr->value_size, __func__);
if (type_is_pkt_pointer(type) &&
!may_access_direct_pkt_data(env, meta, BPF_READ)) {
verbose(env, "helper access to the packet is not allowed\n");
@@ -8704,6 +8711,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
verbose(env, "invalid map_ptr to access map->key\n");
return -EACCES;
}
+ printk("meta:%p, maptr:%p, ks:%d, reg->map_ptr:%p, %s\n",
+ meta, meta->map_ptr, meta->map_ptr->key_size, reg->map_ptr, __func__);
err = check_helper_mem_access(env, regno,
meta->map_ptr->key_size, false,
NULL);
@@ -8721,6 +8730,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
return -EACCES;
}
meta->raw_mode = arg_type & MEM_UNINIT;
+ printk("meta:%p, maptr:%p, vs:%d, reg->map_ptr:%p, %s\n",
+ meta, meta->map_ptr, meta->map_ptr->value_size, reg->map_ptr, __func__);
err = check_helper_mem_access(env, regno,
meta->map_ptr->value_size, false,
meta);
@@ -10248,6 +10259,8 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
meta.func_id = func_id;
/* check args */
+ printk("meta:%p, maptr:%p, ks:%d, kv:%d,%s\n",
+ &meta, meta.map_ptr, meta.map_ptr->key_size, meta.map_ptr->value_size, __func__);
for (i = 0; i < MAX_BPF_FUNC_REG_ARGS; i++) {
err = check_func_arg(env, i, &meta, fn, insn_idx);
if (err)