Re: [PATCH bpf-next v3 2/4] bpf: factor out helpers to check ctx access for BTF function

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

 



On Fri, Oct 22, 2021 at 03:55:09PM +0800, Hou Tao wrote:
> Factor out two helpers to check the read access of ctx for BTF
> function. bpf_tracing_ctx_access() is used to check the
> read access to argument is valid, and bpf_tracing_btf_ctx_access()
> checks whether the btf type of argument is valid besides
> the checking of argument read. bpf_tracing_btf_ctx_access()
> will be used by the following patch.
> 
> Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx>
> ---
>  include/linux/bpf.h      | 27 +++++++++++++++++++++++++++
>  kernel/trace/bpf_trace.c | 16 ++--------------
>  net/ipv4/bpf_tcp_ca.c    |  9 +--------
>  3 files changed, 30 insertions(+), 22 deletions(-)
> 
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 3d2cf94a72ce..0dd2de9eeed3 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1649,6 +1649,33 @@ bool bpf_prog_test_check_kfunc_call(u32 kfunc_id, struct module *owner);
>  bool btf_ctx_access(int off, int size, enum bpf_access_type type,
>  		    const struct bpf_prog *prog,
>  		    struct bpf_insn_access_aux *info);
> +
> +/*
> + * The maximum number of BTF function arguments is MAX_BPF_FUNC_ARGS.
> + * And only aligned read is allowed.
It is not always 'BTF' function arguments.  Lets remove this comment.
The function is short and its intention is clear.

Others lgtm.

Acked-by: Martin KaFai Lau <kafai@xxxxxx>

> + */
> +static inline bool bpf_tracing_ctx_access(int off, int size,
> +					  enum bpf_access_type type)
> +{
> +	if (off < 0 || off >= sizeof(__u64) * MAX_BPF_FUNC_ARGS)
> +		return false;
> +	if (type != BPF_READ)
> +		return false;
> +	if (off % size != 0)
> +		return false;
> +	return true;
> +}
> +
> +static inline bool bpf_tracing_btf_ctx_access(int off, int size,
> +					      enum bpf_access_type type,
> +					      const struct bpf_prog *prog,
> +					      struct bpf_insn_access_aux *info)
> +{
> +	if (!bpf_tracing_ctx_access(off, size, type))
> +		return false;
> +	return btf_ctx_access(off, size, type, prog, info);
> +}



[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