Skip to content

Commit 2ea864c

Browse files
mauriciovasquezbernalAlexei Starovoitov
authored andcommitted
bpf/verifier: add ARG_PTR_TO_UNINIT_MAP_VALUE
ARG_PTR_TO_UNINIT_MAP_VALUE argument is a pointer to a memory zone used to save the value of a map. Basically the same as ARG_PTR_TO_UNINIT_MEM, but the size has not be passed as an extra argument. This will be used in the following patch that implements some new helpers that receive a pointer to be filled with a map value. Signed-off-by: Mauricio Vasquez B <[email protected]> Acked-by: Song Liu <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent c9d29f4 commit 2ea864c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

include/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ enum bpf_arg_type {
138138
ARG_CONST_MAP_PTR, /* const argument used as pointer to bpf_map */
139139
ARG_PTR_TO_MAP_KEY, /* pointer to stack used as map key */
140140
ARG_PTR_TO_MAP_VALUE, /* pointer to stack used as map value */
141+
ARG_PTR_TO_UNINIT_MAP_VALUE, /* pointer to valid memory used to store a map value */
141142

142143
/* the following constraints used to prototype bpf_memcmp() and other
143144
* functions that access data on eBPF program stack

kernel/bpf/verifier.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 regno,
21172117
}
21182118

21192119
if (arg_type == ARG_PTR_TO_MAP_KEY ||
2120-
arg_type == ARG_PTR_TO_MAP_VALUE) {
2120+
arg_type == ARG_PTR_TO_MAP_VALUE ||
2121+
arg_type == ARG_PTR_TO_UNINIT_MAP_VALUE) {
21212122
expected_type = PTR_TO_STACK;
21222123
if (!type_is_pkt_pointer(type) && type != PTR_TO_MAP_VALUE &&
21232124
type != expected_type)
@@ -2187,7 +2188,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 regno,
21872188
err = check_helper_mem_access(env, regno,
21882189
meta->map_ptr->key_size, false,
21892190
NULL);
2190-
} else if (arg_type == ARG_PTR_TO_MAP_VALUE) {
2191+
} else if (arg_type == ARG_PTR_TO_MAP_VALUE ||
2192+
arg_type == ARG_PTR_TO_UNINIT_MAP_VALUE) {
21912193
/* bpf_map_xxx(..., map_ptr, ..., value) call:
21922194
* check [value, value + map->value_size) validity
21932195
*/
@@ -2196,9 +2198,10 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 regno,
21962198
verbose(env, "invalid map_ptr to access map->value\n");
21972199
return -EACCES;
21982200
}
2201+
meta->raw_mode = (arg_type == ARG_PTR_TO_UNINIT_MAP_VALUE);
21992202
err = check_helper_mem_access(env, regno,
22002203
meta->map_ptr->value_size, false,
2201-
NULL);
2204+
meta);
22022205
} else if (arg_type_is_mem_size(arg_type)) {
22032206
bool zero_size_allowed = (arg_type == ARG_CONST_SIZE_OR_ZERO);
22042207

0 commit comments

Comments
 (0)