From: Feng Yang <yangfeng59949@163.com>
To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org,
sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] bpf: Replace (arg_type & MEM_RDONLY) with type_is_rdonly_mem
Date: Tue, 7 Jan 2025 17:02:22 +0800 [thread overview]
Message-ID: <20250107090222.310778-1-yangfeng59949@163.com> (raw)
From: Feng Yang <yangfeng@kylinos.cn>
The existing 'type_is_rdonly_mem' function is more formal in linux source
Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
kernel/bpf/verifier.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index d8520095ca03..d1b6b587a146 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -7779,7 +7779,7 @@ static int process_dynptr_func(struct bpf_verifier_env *env, int regno, int insn
err = mark_stack_slots_dynptr(env, reg, arg_type, insn_idx, clone_ref_obj_id);
} else /* MEM_RDONLY and None case from above */ {
/* For the reg->type == PTR_TO_STACK case, bpf_dynptr is never const */
- if (reg->type == CONST_PTR_TO_DYNPTR && !(arg_type & MEM_RDONLY)) {
+ if (reg->type == CONST_PTR_TO_DYNPTR && !type_is_rdonly_mem(arg_type)) {
verbose(env, "cannot pass pointer to const bpf_dynptr, the helper mutates it\n");
return -EINVAL;
}
@@ -8324,7 +8324,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
*
* Therefore we fold these flags depending on the arg_type before comparison.
*/
- if (arg_type & MEM_RDONLY)
+ if (type_is_rdonly_mem(arg_type))
type &= ~MEM_RDONLY;
if (arg_type & PTR_MAYBE_NULL)
type &= ~PTR_MAYBE_NULL;
@@ -8356,7 +8356,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
return 0;
if (compatible == &mem_types) {
- if (!(arg_type & MEM_RDONLY)) {
+ if (!type_is_rdonly_mem(arg_type)) {
verbose(env,
"%s() may write into memory pointed by R%d type=%s\n",
func_id_name(meta->func_id),
--
2.27.0
next reply other threads:[~2025-01-07 9:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-07 9:02 Feng Yang [this message]
2025-01-07 23:02 ` Stanislav Fomichev
2025-01-08 17:53 ` Alexei Starovoitov
2025-01-09 8:23 ` Feng Yang
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=20250107090222.310778-1-yangfeng59949@163.com \
--to=yangfeng59949@163.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®