* [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
* Re: [PATCH] bpf: replace kvfree with kfree for kzalloc memory
2025-08-11 12:39 [PATCH] bpf: replace " Qianfeng Rong
@ 2025-08-11 13:15 ` Qianfeng Rong
2025-08-11 16:47 ` Eduard Zingerman
2025-08-11 13:25 ` Markus Elfring
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Qianfeng Rong @ 2025-08-11 13:15 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
Hi all,
Sorry, please ignore this patch, because I found that there are still a
lot of mixed uses of kfree and kvfree in kernel/bpf/verifier.c. Best
regards, Qianfeng
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] bpf: replace kvfree with kfree for kzalloc memory
2025-08-11 12:39 [PATCH] bpf: replace " Qianfeng Rong
2025-08-11 13:15 ` Qianfeng Rong
@ 2025-08-11 13:25 ` Markus Elfring
2025-08-11 16:46 ` Eduard Zingerman
2025-08-12 23:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2025-08-11 13:25 UTC (permalink / raw)
To: Qianfeng Rong, bpf, Andrii Nakryiko, Alexei Starovoitov,
Daniel Borkmann, Eduard Zingerman, Hao Luo, Jiri Olsa,
John Fastabend, KP Singh, Martin KaFai Lau, Song Liu,
Stanislav Fomichev, Yonghong Song
Cc: LKML
…
> Replace kvfree() with kfree() to avoid unnecessary is_vmalloc_addr()
> check in kvfree().
Under which circumstances would you become interested to apply the attribute “__free”
(also in the affected if branch)?
https://elixir.bootlin.com/linux/v6.16/source/include/linux/slab.h#L476
Regards,
Markus
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] bpf: replace kvfree with kfree for kzalloc memory
2025-08-11 12:39 [PATCH] bpf: replace " Qianfeng Rong
2025-08-11 13:15 ` Qianfeng Rong
2025-08-11 13:25 ` Markus Elfring
@ 2025-08-11 16:46 ` Eduard Zingerman
2025-08-12 23:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 8+ messages in thread
From: Eduard Zingerman @ 2025-08-11 16:46 UTC (permalink / raw)
To: Qianfeng Rong, Alexei Starovoitov, Daniel Borkmann,
John Fastabend, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
bpf, linux-kernel
On Mon, 2025-08-11 at 20:39 +0800, Qianfeng Rong wrote:
> 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>
> ---
Acked-by: Eduard Zingerman <eddyz87@gmail.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);
The backedge encapsulates verifier state, verifier states are
allocated using kzalloc() and freed using kfreed() in other places in
verifier.c => I think this patch is valid.
> return err;
> }
> }
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] bpf: replace kvfree with kfree for kzalloc memory
2025-08-11 13:15 ` Qianfeng Rong
@ 2025-08-11 16:47 ` Eduard Zingerman
0 siblings, 0 replies; 8+ messages in thread
From: Eduard Zingerman @ 2025-08-11 16:47 UTC (permalink / raw)
To: Qianfeng Rong, Alexei Starovoitov, Daniel Borkmann,
John Fastabend, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
bpf, linux-kernel
On Mon, 2025-08-11 at 21:15 +0800, Qianfeng Rong wrote:
> Hi all,
>
> Sorry, please ignore this patch, because I found that there are still a
> lot of mixed uses of kfree and kvfree in kernel/bpf/verifier.c. Best
> regards, Qianfeng
Using kvfree() in this position was sloppy on my side,
thank you for noticing this.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] bpf: replace kvfree with kfree for kzalloc memory
2025-08-11 12:39 [PATCH] bpf: replace " Qianfeng Rong
` (2 preceding siblings ...)
2025-08-11 16:46 ` Eduard Zingerman
@ 2025-08-12 23:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-12 23:00 UTC (permalink / raw)
To: Qianfeng Rong
Cc: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, bpf, linux-kernel
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Mon, 11 Aug 2025 20:39:49 +0800 you wrote:
> 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().
>
> [...]
Here is the summary with links:
- bpf: replace kvfree with kfree for kzalloc memory
https://git.kernel.org/bpf/bpf-next/c/bf0c2a84df9f
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] 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
* Re: [PATCH] bpf: Replace kvfree with kfree for kzalloc memory
2025-08-26 7:39 [PATCH] bpf: Replace kvfree with kfree for kzalloc memory Feng Yang
@ 2025-08-26 11:43 ` Daniel Borkmann
0 siblings, 0 replies; 8+ messages in thread
From: Daniel Borkmann @ 2025-08-26 11:43 UTC (permalink / raw)
To: Feng Yang, ast, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa
Cc: bpf, linux-kernel
On 8/26/25 9:39 AM, Feng Yang wrote:
> From: Feng Yang <yangfeng@kylinos.cn>
>
> Refer to https://lore.kernel.org/bpf/20250811123949.552885-1-rongqianfeng@vivo.com to replace the remaining part.
Please make this a proper commit message instead of just posting a lore link.
$subj should be [PATCH bpf-next].
> 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;
> }
>
^ permalink raw reply [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-26 7:39 [PATCH] bpf: Replace kvfree with kfree for kzalloc memory Feng Yang
2025-08-26 11:43 ` Daniel Borkmann
-- strict thread matches above, loose matches on Subject: below --
2025-08-11 12:39 [PATCH] bpf: replace " 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
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).