mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 02:21:52 +09:00
Revert "bpf: Fix helper writes to read-only maps"
This reverts commit 988e55abcf which is
commit 32556ce93bc45c730829083cb60f95a2728ea48b upstream.
It breaks the Android kernel abi and can be brought back in the future
in an abi-safe way if it is really needed.
Bug: 161946584
Change-Id: Ibd0d120be102c66e57d9d418a5ccd02178022713
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
@@ -471,11 +471,6 @@ enum bpf_type_flag {
|
||||
/* Size is known at compile time. */
|
||||
MEM_FIXED_SIZE = BIT(10 + BPF_BASE_TYPE_BITS),
|
||||
|
||||
/* Memory must be aligned on some architectures, used in combination with
|
||||
* MEM_FIXED_SIZE.
|
||||
*/
|
||||
MEM_ALIGNED = BIT(17 + BPF_BASE_TYPE_BITS),
|
||||
|
||||
__BPF_TYPE_FLAG_MAX,
|
||||
__BPF_TYPE_LAST_FLAG = __BPF_TYPE_FLAG_MAX - 1,
|
||||
};
|
||||
@@ -511,6 +506,8 @@ enum bpf_arg_type {
|
||||
ARG_ANYTHING, /* any (initialized) argument is ok */
|
||||
ARG_PTR_TO_SPIN_LOCK, /* pointer to bpf_spin_lock */
|
||||
ARG_PTR_TO_SOCK_COMMON, /* pointer to sock_common */
|
||||
ARG_PTR_TO_INT, /* pointer to int */
|
||||
ARG_PTR_TO_LONG, /* pointer to long */
|
||||
ARG_PTR_TO_SOCKET, /* pointer to bpf_sock (fullsock) */
|
||||
ARG_PTR_TO_BTF_ID, /* pointer to in-kernel struct */
|
||||
ARG_PTR_TO_ALLOC_MEM, /* pointer to dynamically allocated memory */
|
||||
|
||||
@@ -531,8 +531,7 @@ const struct bpf_func_proto bpf_strtol_proto = {
|
||||
.arg1_type = ARG_PTR_TO_MEM | MEM_RDONLY,
|
||||
.arg2_type = ARG_CONST_SIZE,
|
||||
.arg3_type = ARG_ANYTHING,
|
||||
.arg4_type = ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_ALIGNED,
|
||||
.arg4_size = sizeof(s64),
|
||||
.arg4_type = ARG_PTR_TO_LONG,
|
||||
};
|
||||
|
||||
BPF_CALL_4(bpf_strtoul, const char *, buf, size_t, buf_len, u64, flags,
|
||||
@@ -561,8 +560,7 @@ const struct bpf_func_proto bpf_strtoul_proto = {
|
||||
.arg1_type = ARG_PTR_TO_MEM | MEM_RDONLY,
|
||||
.arg2_type = ARG_CONST_SIZE,
|
||||
.arg3_type = ARG_ANYTHING,
|
||||
.arg4_type = ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_ALIGNED,
|
||||
.arg4_size = sizeof(u64),
|
||||
.arg4_type = ARG_PTR_TO_LONG,
|
||||
};
|
||||
|
||||
BPF_CALL_3(bpf_strncmp, const char *, s1, u32, s1_sz, const char *, s2)
|
||||
|
||||
@@ -5242,8 +5242,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
|
||||
.arg1_type = ARG_PTR_TO_MEM,
|
||||
.arg2_type = ARG_CONST_SIZE_OR_ZERO,
|
||||
.arg3_type = ARG_ANYTHING,
|
||||
.arg4_type = ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_ALIGNED,
|
||||
.arg4_size = sizeof(u64),
|
||||
.arg4_type = ARG_PTR_TO_LONG,
|
||||
};
|
||||
|
||||
static const struct bpf_func_proto *
|
||||
|
||||
@@ -5801,6 +5801,16 @@ static bool arg_type_is_dynptr(enum bpf_arg_type type)
|
||||
return base_type(type) == ARG_PTR_TO_DYNPTR;
|
||||
}
|
||||
|
||||
static int int_ptr_type_to_size(enum bpf_arg_type type)
|
||||
{
|
||||
if (type == ARG_PTR_TO_INT)
|
||||
return sizeof(u32);
|
||||
else if (type == ARG_PTR_TO_LONG)
|
||||
return sizeof(u64);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int resolve_map_arg_type(struct bpf_verifier_env *env,
|
||||
const struct bpf_call_arg_meta *meta,
|
||||
enum bpf_arg_type *arg_type)
|
||||
@@ -5881,6 +5891,16 @@ static const struct bpf_reg_types mem_types = {
|
||||
},
|
||||
};
|
||||
|
||||
static const struct bpf_reg_types int_ptr_types = {
|
||||
.types = {
|
||||
PTR_TO_STACK,
|
||||
PTR_TO_PACKET,
|
||||
PTR_TO_PACKET_META,
|
||||
PTR_TO_MAP_KEY,
|
||||
PTR_TO_MAP_VALUE,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct bpf_reg_types fullsock_types = { .types = { PTR_TO_SOCKET } };
|
||||
static const struct bpf_reg_types scalar_types = { .types = { SCALAR_VALUE } };
|
||||
static const struct bpf_reg_types context_types = { .types = { PTR_TO_CTX } };
|
||||
@@ -5918,6 +5938,8 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
|
||||
[ARG_PTR_TO_SPIN_LOCK] = &spin_lock_types,
|
||||
[ARG_PTR_TO_MEM] = &mem_types,
|
||||
[ARG_PTR_TO_ALLOC_MEM] = &alloc_mem_types,
|
||||
[ARG_PTR_TO_INT] = &int_ptr_types,
|
||||
[ARG_PTR_TO_LONG] = &int_ptr_types,
|
||||
[ARG_PTR_TO_PERCPU_BTF_ID] = &percpu_btf_ptr_types,
|
||||
[ARG_PTR_TO_FUNC] = &func_ptr_types,
|
||||
[ARG_PTR_TO_STACK] = &stack_ptr_types,
|
||||
@@ -6264,11 +6286,9 @@ skip_type_check:
|
||||
*/
|
||||
meta->raw_mode = arg_type & MEM_UNINIT;
|
||||
if (arg_type & MEM_FIXED_SIZE) {
|
||||
err = check_helper_mem_access(env, regno, fn->arg_size[arg], false, meta);
|
||||
if (err)
|
||||
return err;
|
||||
if (arg_type & MEM_ALIGNED)
|
||||
err = check_ptr_alignment(env, reg, 0, fn->arg_size[arg], true);
|
||||
err = check_helper_mem_access(env, regno,
|
||||
fn->arg_size[arg], false,
|
||||
meta);
|
||||
}
|
||||
break;
|
||||
case ARG_CONST_SIZE:
|
||||
@@ -6336,6 +6356,17 @@ skip_type_check:
|
||||
if (err)
|
||||
return err;
|
||||
break;
|
||||
case ARG_PTR_TO_INT:
|
||||
case ARG_PTR_TO_LONG:
|
||||
{
|
||||
int size = int_ptr_type_to_size(arg_type);
|
||||
|
||||
err = check_helper_mem_access(env, regno, size, false, meta);
|
||||
if (err)
|
||||
return err;
|
||||
err = check_ptr_alignment(env, reg, 0, size, true);
|
||||
break;
|
||||
}
|
||||
case ARG_PTR_TO_CONST_STR:
|
||||
{
|
||||
struct bpf_map *map = reg->map_ptr;
|
||||
|
||||
@@ -1192,8 +1192,7 @@ static const struct bpf_func_proto bpf_get_func_arg_proto = {
|
||||
.ret_type = RET_INTEGER,
|
||||
.arg1_type = ARG_PTR_TO_CTX,
|
||||
.arg2_type = ARG_ANYTHING,
|
||||
.arg3_type = ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_ALIGNED,
|
||||
.arg3_size = sizeof(u64),
|
||||
.arg3_type = ARG_PTR_TO_LONG,
|
||||
};
|
||||
|
||||
BPF_CALL_2(get_func_ret, void *, ctx, u64 *, value)
|
||||
@@ -1209,8 +1208,7 @@ static const struct bpf_func_proto bpf_get_func_ret_proto = {
|
||||
.func = get_func_ret,
|
||||
.ret_type = RET_INTEGER,
|
||||
.arg1_type = ARG_PTR_TO_CTX,
|
||||
.arg2_type = ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_ALIGNED,
|
||||
.arg2_size = sizeof(u64),
|
||||
.arg2_type = ARG_PTR_TO_LONG,
|
||||
};
|
||||
|
||||
BPF_CALL_1(get_func_arg_cnt, void *, ctx)
|
||||
|
||||
@@ -6234,8 +6234,7 @@ static const struct bpf_func_proto bpf_skb_check_mtu_proto = {
|
||||
.ret_type = RET_INTEGER,
|
||||
.arg1_type = ARG_PTR_TO_CTX,
|
||||
.arg2_type = ARG_ANYTHING,
|
||||
.arg3_type = ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_ALIGNED,
|
||||
.arg3_size = sizeof(u32),
|
||||
.arg3_type = ARG_PTR_TO_INT,
|
||||
.arg4_type = ARG_ANYTHING,
|
||||
.arg5_type = ARG_ANYTHING,
|
||||
};
|
||||
@@ -6246,8 +6245,7 @@ static const struct bpf_func_proto bpf_xdp_check_mtu_proto = {
|
||||
.ret_type = RET_INTEGER,
|
||||
.arg1_type = ARG_PTR_TO_CTX,
|
||||
.arg2_type = ARG_ANYTHING,
|
||||
.arg3_type = ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_ALIGNED,
|
||||
.arg3_size = sizeof(u32),
|
||||
.arg3_type = ARG_PTR_TO_INT,
|
||||
.arg4_type = ARG_ANYTHING,
|
||||
.arg5_type = ARG_ANYTHING,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user