bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin KaFai Lau <kafai@fb.com>
To: Hou Tao <houtao1@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>, Yonghong Song <yhs@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, <netdev@vger.kernel.org>,
	<bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v3 2/4] bpf: factor out helpers to check ctx access for BTF function
Date: Fri, 22 Oct 2021 17:18:32 -0700	[thread overview]
Message-ID: <20211023001832.jvz5lbnj33l4y3jb@kafai-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <20211022075511.1682588-3-houtao1@huawei.com>

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@huawei.com>
> ---
>  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@fb.com>

> + */
> +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);
> +}

  reply	other threads:[~2021-10-23  0:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22  7:55 [PATCH bpf-next v3 0/4] introduce dummy BPF STRUCT_OPS Hou Tao
2021-10-22  7:55 ` [PATCH bpf-next v3 1/4] bpf: factor out a helper to prepare trampoline for struct_ops prog Hou Tao
2021-10-23  0:14   ` Martin KaFai Lau
2021-10-22  7:55 ` [PATCH bpf-next v3 2/4] bpf: factor out helpers to check ctx access for BTF function Hou Tao
2021-10-23  0:18   ` Martin KaFai Lau [this message]
2021-10-24  9:27     ` Hou Tao
2021-10-22  7:55 ` [PATCH bpf-next v3 3/4] bpf: add dummy BPF STRUCT_OPS for test purpose Hou Tao
2021-10-23  0:35   ` Martin KaFai Lau
2021-10-24 10:32     ` Hou Tao
2021-10-22  7:55 ` [PATCH bpf-next v3 4/4] selftests/bpf: add test cases for struct_ops prog Hou Tao
2021-10-23  1:00   ` Martin KaFai Lau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211023001832.jvz5lbnj33l4y3jb@kafai-mbp.dhcp.thefacebook.com \
    --to=kafai@fb.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=houtao1@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).