bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: replace kvfree with kfree for kzalloc memory
@ 2025-08-11 12:39 Qianfeng Rong
  2025-08-11 13:15 ` Qianfeng Rong
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Qianfeng Rong @ 2025-08-11 12:39 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	bpf, linux-kernel
  Cc: Qianfeng Rong

The 'backedge' pointer is allocated with kzalloc(), which returns
physically contiguous memory. Using kvfree() to deallocate such
memory is functionally safe but semantically incorrect.

Replace kvfree() with kfree() to avoid unnecessary is_vmalloc_addr()
check in kvfree().

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 kernel/bpf/verifier.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index c4f69a9e9af6..4e5de1ff7e30 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -19553,7 +19553,7 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx)
 				err = err ?: add_scc_backedge(env, &sl->state, backedge);
 				if (err) {
 					free_verifier_state(&backedge->state, false);
-					kvfree(backedge);
+					kfree(backedge);
 					return err;
 				}
 			}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH] bpf: Replace kvfree with kfree for kzalloc memory
@ 2025-08-26  7:39 Feng Yang
  2025-08-26 11:43 ` Daniel Borkmann
  0 siblings, 1 reply; 8+ messages in thread
From: Feng Yang @ 2025-08-26  7:39 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel

From: Feng Yang <yangfeng@kylinos.cn>

Refer to https://lore.kernel.org/bpf/20250811123949.552885-1-rongqianfeng@vivo.com to replace the remaining part.

Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
 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 5c9dd16b2c56..b9394f8fac0e 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2021,7 +2021,7 @@ static void free_backedges(struct bpf_scc_visit *visit)
 	for (backedge = visit->backedges; backedge; backedge = next) {
 		free_verifier_state(&backedge->state, false);
 		next = backedge->next;
-		kvfree(backedge);
+		kfree(backedge);
 	}
 	visit->backedges = NULL;
 }
@@ -19651,7 +19651,7 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx)
 	err = maybe_enter_scc(env, new);
 	if (err) {
 		free_verifier_state(new, false);
-		kvfree(new_sl);
+		kfree(new_sl);
 		return err;
 	}
 
-- 
2.43.0


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

end of thread, other threads:[~2025-08-26 11:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 12:39 [PATCH] bpf: replace kvfree with kfree for kzalloc memory Qianfeng Rong
2025-08-11 13:15 ` Qianfeng Rong
2025-08-11 16:47   ` Eduard Zingerman
2025-08-11 13:25 ` Markus Elfring
2025-08-11 16:46 ` Eduard Zingerman
2025-08-12 23:00 ` patchwork-bot+netdevbpf
  -- strict thread matches above, loose matches on Subject: below --
2025-08-26  7:39 [PATCH] bpf: Replace " Feng Yang
2025-08-26 11:43 ` Daniel Borkmann

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).