Skip to content

Commit 18752d7

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: Improve check_raw_mode_ok test for MEM_UNINIT-tagged types
When checking malformed helper function signatures, also take other argument types into account aside from just ARG_PTR_TO_UNINIT_MEM. This concerns (formerly) ARG_PTR_TO_{INT,LONG} given uninitialized memory can be passed there, too. The func proto sanity check goes back to commit 435faee ("bpf, verifier: add ARG_PTR_TO_RAW_STACK type"), and its purpose was to detect wrong func protos which had more than just one MEM_UNINIT-tagged type as arguments. The reason more than one is currently not supported is as we mark stack slots with STACK_MISC in check_helper_call() in case of raw mode based on meta.access_size to allow uninitialized stack memory to be passed to helpers when they just write into the buffer. Probing for base type as well as MEM_UNINIT tagging ensures that other types do not get missed (as it used to be the case for ARG_PTR_TO_{INT,LONG}). Fixes: 57c3bb7 ("bpf: Introduce ARG_PTR_TO_{INT,LONG} arg types") Reported-by: Shung-Hsi Yu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Shung-Hsi Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 32556ce commit 18752d7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

kernel/bpf/verifier.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8291,6 +8291,12 @@ static bool arg_type_is_mem_size(enum bpf_arg_type type)
82918291
type == ARG_CONST_SIZE_OR_ZERO;
82928292
}
82938293

8294+
static bool arg_type_is_raw_mem(enum bpf_arg_type type)
8295+
{
8296+
return base_type(type) == ARG_PTR_TO_MEM &&
8297+
type & MEM_UNINIT;
8298+
}
8299+
82948300
static bool arg_type_is_release(enum bpf_arg_type type)
82958301
{
82968302
return type & OBJ_RELEASE;
@@ -9340,15 +9346,15 @@ static bool check_raw_mode_ok(const struct bpf_func_proto *fn)
93409346
{
93419347
int count = 0;
93429348

9343-
if (fn->arg1_type == ARG_PTR_TO_UNINIT_MEM)
9349+
if (arg_type_is_raw_mem(fn->arg1_type))
93449350
count++;
9345-
if (fn->arg2_type == ARG_PTR_TO_UNINIT_MEM)
9351+
if (arg_type_is_raw_mem(fn->arg2_type))
93469352
count++;
9347-
if (fn->arg3_type == ARG_PTR_TO_UNINIT_MEM)
9353+
if (arg_type_is_raw_mem(fn->arg3_type))
93489354
count++;
9349-
if (fn->arg4_type == ARG_PTR_TO_UNINIT_MEM)
9355+
if (arg_type_is_raw_mem(fn->arg4_type))
93509356
count++;
9351-
if (fn->arg5_type == ARG_PTR_TO_UNINIT_MEM)
9357+
if (arg_type_is_raw_mem(fn->arg5_type))
93529358
count++;
93539359

93549360
/* We only support one arg being in raw mode at the moment,

0 commit comments

Comments
 (0)