All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: replace open code with for allocated object check
@ 2023-05-27 12:27 Daniel T. Lee
  2023-06-05 21:40 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel T. Lee @ 2023-05-27 12:27 UTC (permalink / raw)
  To: Daniel Borkmann, Alexei Starovoitov, Andrii Nakryiko,
	John Fastabend, Stanislav Fomichev, KP Singh, Yonghong Song,
	Song Liu, Martin KaFai Lau, Hao Luo, Jiri Olsa
  Cc: bpf, linux-kernel

From commit 282de143ead9 ("bpf: Introduce allocated objects support"),
With this allocated object with BPF program, (PTR_TO_BTF_ID | MEM_ALLOC)
has been a way of indicating to check the type is the allocated object.

commit d8939cb0a03c ("bpf: Loosen alloc obj test in verifier's
reg_btf_record")
From the commit, there has been helper function for checking this, named
type_is_ptr_alloc_obj(). But still, some of the code use open code to
retrieve this info. This commit replaces the open code with the
type_is_alloc(), and the type_is_ptr_alloc_obj() function.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
---
 kernel/bpf/verifier.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 086b2a14905b..97c714e8a8bf 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5891,7 +5891,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
 		 * program allocated objects (which always have ref_obj_id > 0),
 		 * but not for untrusted PTR_TO_BTF_ID | MEM_ALLOC.
 		 */
-		if (atype != BPF_READ && reg->type != (PTR_TO_BTF_ID | MEM_ALLOC)) {
+		if (atype != BPF_READ && !type_is_ptr_alloc_obj(reg->type)) {
 			verbose(env, "only read is supported\n");
 			return -EACCES;
 		}
@@ -7511,7 +7511,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
 	if (base_type(arg_type) == ARG_PTR_TO_MEM)
 		type &= ~DYNPTR_TYPE_FLAG_MASK;
 
-	if (meta->func_id == BPF_FUNC_kptr_xchg && type & MEM_ALLOC)
+	if (meta->func_id == BPF_FUNC_kptr_xchg && type_is_alloc(type))
 		type &= ~MEM_ALLOC;
 
 	for (i = 0; i < ARRAY_SIZE(compatible->types); i++) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] bpf: replace open code with for allocated object check
  2023-05-27 12:27 [PATCH bpf-next] bpf: replace open code with for allocated object check Daniel T. Lee
@ 2023-06-05 21:40 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-05 21:40 UTC (permalink / raw)
  To: Daniel T. Lee
  Cc: daniel, ast, andrii.nakryiko, john.fastabend, sdf, kpsingh, yhs,
	song, martin.lau, haoluo, jolsa, bpf, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Sat, 27 May 2023 21:27:06 +0900 you wrote:
> From commit 282de143ead9 ("bpf: Introduce allocated objects support"),
> With this allocated object with BPF program, (PTR_TO_BTF_ID | MEM_ALLOC)
> has been a way of indicating to check the type is the allocated object.
> 
> commit d8939cb0a03c ("bpf: Loosen alloc obj test in verifier's
> reg_btf_record")
> From the commit, there has been helper function for checking this, named
> type_is_ptr_alloc_obj(). But still, some of the code use open code to
> retrieve this info. This commit replaces the open code with the
> type_is_alloc(), and the type_is_ptr_alloc_obj() function.
> 
> [...]

Here is the summary with links:
  - [bpf-next] bpf: replace open code with for allocated object check
    https://git.kernel.org/bpf/bpf-next/c/503e4def5414

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-05 21:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-27 12:27 [PATCH bpf-next] bpf: replace open code with for allocated object check Daniel T. Lee
2023-06-05 21:40 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.