BPF List
 help / color / mirror / Atom feed
From: thinker.li@gmail.com
To: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev,
	song@kernel.org, kernel-team@meta.com, andrii@kernel.org,
	davemarchevsky@meta.com, dvernet@meta.com
Cc: sinquersw@gmail.com, kuifeng@meta.com,
	Kui-Feng Lee <thinker.li@gmail.com>
Subject: [RFC bpf-next v4 1/6] bpf: Allow PTR_TO_BTF_ID even for pointers to int.
Date: Fri,  2 Feb 2024 14:05:11 -0800	[thread overview]
Message-ID: <20240202220516.1165466-2-thinker.li@gmail.com> (raw)
In-Reply-To: <20240202220516.1165466-1-thinker.li@gmail.com>

From: Kui-Feng Lee <thinker.li@gmail.com>

Pointers to int are always accepted when checking accesses of a context in
btf_ctx_access(). However, we are going to support pointers to scalar types
with PTR_TO_BTF_ID.  Changing the order of checking prog->aux->ctx_arg_info
and checking is_int_ptr() enables the extension in the following patches.

Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
---
 kernel/bpf/btf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index ef380e546952..0847035bba99 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -6252,9 +6252,6 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
 		 */
 		return true;
 
-	if (is_int_ptr(btf, t))
-		return true;
-
 	/* this is a pointer to another type */
 	for (i = 0; i < prog->aux->ctx_arg_info_size; i++) {
 		const struct bpf_ctx_arg_aux *ctx_arg_info = &prog->aux->ctx_arg_info[i];
@@ -6272,6 +6269,9 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
 		}
 	}
 
+	if (is_int_ptr(btf, t))
+		return true;
+
 	info->reg_type = PTR_TO_BTF_ID;
 	if (prog_args_trusted(prog))
 		info->reg_type |= PTR_TRUSTED;
-- 
2.34.1


  reply	other threads:[~2024-02-02 22:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 22:05 [RFC bpf-next v4 0/6] Support PTR_MAYBE_NULL for struct_ops arguments thinker.li
2024-02-02 22:05 ` thinker.li [this message]
2024-02-02 22:05 ` [RFC bpf-next v4 2/6] bpf: Extend PTR_TO_BTF_ID to handle pointers to scalar and array types thinker.li
2024-02-03  0:52   ` Martin KaFai Lau
2024-02-03  1:03     ` Kui-Feng Lee
2024-02-02 22:05 ` [RFC bpf-next v4 3/6] bpf: Remove an unnecessary check thinker.li
2024-02-03  0:46   ` Martin KaFai Lau
2024-02-03  1:03     ` Kui-Feng Lee
2024-02-02 22:05 ` [RFC bpf-next v4 4/6] bpf: add btf pointer to struct bpf_ctx_arg_aux thinker.li
2024-02-02 22:05 ` [RFC bpf-next v4 5/6] bpf: Create argument information for nullable arguments thinker.li
2024-02-03  0:40   ` Martin KaFai Lau
2024-02-03  1:57     ` Kui-Feng Lee
2024-02-04  0:21       ` Kui-Feng Lee
2024-02-05  1:53     ` Kui-Feng Lee
2024-02-02 22:05 ` [RFC bpf-next v4 6/6] selftests/bpf: Test PTR_MAYBE_NULL arguments of struct_ops operators thinker.li

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=20240202220516.1165466-2-thinker.li@gmail.com \
    --to=thinker.li@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=davemarchevsky@meta.com \
    --cc=dvernet@meta.com \
    --cc=kernel-team@meta.com \
    --cc=kuifeng@meta.com \
    --cc=martin.lau@linux.dev \
    --cc=sinquersw@gmail.com \
    --cc=song@kernel.org \
    /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