Re: [PATCH bpf-next v3 1/6] bpf: Add MEM_UNINIT as a bpf_type_flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 28, 2022 at 2:12 PM Joanne Koong <joannelkoong@xxxxxxxxx> wrote:
>
> Instead of having uninitialized versions of arguments as separate
> bpf_arg_types (eg ARG_PTR_TO_UNINIT_MEM as the uninitialized version
> of ARG_PTR_TO_MEM), we can instead use MEM_UNINIT as a bpf_type_flag
> modifier to denote that the argument is uninitialized.
>
> Doing so cleans up some of the logic in the verifier. We no longer
> need to do two checks against an argument type (eg "if
> (base_type(arg_type) == ARG_PTR_TO_MEM || base_type(arg_type) ==
> ARG_PTR_TO_UNINIT_MEM)"), since uninitialized and initialized
> versions of the same argument type will now share the same base type.
>
> In the near future, MEM_UNINIT will be used by dynptr helper functions
> as well.
>
> Signed-off-by: Joanne Koong <joannelkoong@xxxxxxxxx>
> ---

LGTM, see minor suggestion below

Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx>

>  include/linux/bpf.h   | 17 +++++++++--------
>  kernel/bpf/helpers.c  |  4 ++--
>  kernel/bpf/verifier.c | 26 ++++++++------------------
>  3 files changed, 19 insertions(+), 28 deletions(-)
>

[...]

> @@ -6189,9 +6179,9 @@ static bool check_raw_mode_ok(const struct bpf_func_proto *fn)
>  static bool check_args_pair_invalid(enum bpf_arg_type arg_curr,
>                                     enum bpf_arg_type arg_next)
>  {
> -       return (arg_type_is_mem_ptr(arg_curr) &&
> +       return (base_type(arg_curr) == ARG_PTR_TO_MEM &&
>                 !arg_type_is_mem_size(arg_next)) ||
> -              (!arg_type_is_mem_ptr(arg_curr) &&
> +              (base_type(arg_curr) != ARG_PTR_TO_MEM &&
>                 arg_type_is_mem_size(arg_next));

trying to parse this check I realized that it can be written as !=
(basically it's a XOR, both conditions are either true or both are
false)

return (base_type(arg_curr) == ARG_PTR_TO_MEM) !=
arg_type_is_mem_size(arg_next);


>  }
>
> @@ -6203,7 +6193,7 @@ static bool check_arg_pair_ok(const struct bpf_func_proto *fn)
>          * helper function specification.
>          */
>         if (arg_type_is_mem_size(fn->arg1_type) ||
> -           arg_type_is_mem_ptr(fn->arg5_type)  ||
> +           base_type(fn->arg5_type) == ARG_PTR_TO_MEM ||
>             check_args_pair_invalid(fn->arg1_type, fn->arg2_type) ||
>             check_args_pair_invalid(fn->arg2_type, fn->arg3_type) ||
>             check_args_pair_invalid(fn->arg3_type, fn->arg4_type) ||
> --
> 2.30.2
>



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux