提交 915ece06 编写于 作者: D Dmitrii Banshchikov 提交者: Zheng Zengkai

bpf: Extract nullable reg type conversion into a helper function

mainline inclusion
from mainline-v5.12-rc1
commit 4ddb7416
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4ddb74165ae580b6dcbb5ab1919d994fc8d03c3f

--------------------------------

Extract conversion from a register's nullable type to a type with a
value. The helper will be used in mark_ptr_not_null_reg().
Signed-off-by: NDmitrii Banshchikov <me@ubique.spb.ru>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210212205642.620788-3-me@ubique.spb.ru

Conflicts:
	kernel/bpf/verifier.c
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 ab8f5c9f
...@@ -1081,6 +1081,28 @@ static void mark_reg_known_zero(struct bpf_verifier_env *env, ...@@ -1081,6 +1081,28 @@ static void mark_reg_known_zero(struct bpf_verifier_env *env,
__mark_reg_known_zero(regs + regno); __mark_reg_known_zero(regs + regno);
} }
static void mark_ptr_not_null_reg(struct bpf_reg_state *reg)
{
if (base_type(reg->type) == PTR_TO_MAP_VALUE) {
const struct bpf_map *map = reg->map_ptr;
if (map->inner_map_meta) {
reg->type = CONST_PTR_TO_MAP;
reg->map_ptr = map->inner_map_meta;
} else if (map->map_type == BPF_MAP_TYPE_XSKMAP) {
reg->type = PTR_TO_XDP_SOCK;
} else if (map->map_type == BPF_MAP_TYPE_SOCKMAP ||
map->map_type == BPF_MAP_TYPE_SOCKHASH) {
reg->type = PTR_TO_SOCKET;
} else {
reg->type = PTR_TO_MAP_VALUE;
}
return;
}
reg->type &= ~PTR_MAYBE_NULL;
}
static bool reg_is_pkt_pointer(const struct bpf_reg_state *reg) static bool reg_is_pkt_pointer(const struct bpf_reg_state *reg)
{ {
return type_is_pkt_pointer(reg->type); return type_is_pkt_pointer(reg->type);
...@@ -7849,32 +7871,19 @@ static void mark_ptr_or_null_reg(struct bpf_func_state *state, ...@@ -7849,32 +7871,19 @@ static void mark_ptr_or_null_reg(struct bpf_func_state *state,
} }
if (is_null) { if (is_null) {
reg->type = SCALAR_VALUE; reg->type = SCALAR_VALUE;
} else if (base_type(reg->type) == PTR_TO_MAP_VALUE) {
const struct bpf_map *map = reg->map_ptr;
if (map->inner_map_meta) {
reg->type = CONST_PTR_TO_MAP;
reg->map_ptr = map->inner_map_meta;
} else if (map->map_type == BPF_MAP_TYPE_XSKMAP) {
reg->type = PTR_TO_XDP_SOCK;
} else if (map->map_type == BPF_MAP_TYPE_SOCKMAP ||
map->map_type == BPF_MAP_TYPE_SOCKHASH) {
reg->type = PTR_TO_SOCKET;
} else {
reg->type = PTR_TO_MAP_VALUE;
}
} else {
reg->type &= ~PTR_MAYBE_NULL;
}
if (is_null) {
/* We don't need id and ref_obj_id from this point /* We don't need id and ref_obj_id from this point
* onwards anymore, thus we should better reset it, * onwards anymore, thus we should better reset it,
* so that state pruning has chances to take effect. * so that state pruning has chances to take effect.
*/ */
reg->id = 0; reg->id = 0;
reg->ref_obj_id = 0; reg->ref_obj_id = 0;
} else if (!reg_may_point_to_spin_lock(reg)) {
return;
}
mark_ptr_not_null_reg(reg);
if (!reg_may_point_to_spin_lock(reg)) {
/* For not-NULL ptr, reg->ref_obj_id will be reset /* For not-NULL ptr, reg->ref_obj_id will be reset
* in release_reg_references(). * in release_reg_references().
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册