mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] bpf: defer bpffs symlink inode freeing until RCU grace period
@ 2026-05-30  1:30 hongao
  2026-06-01 20:42 ` Yonghong Song
  0 siblings, 1 reply; 2+ messages in thread
From: hongao @ 2026-05-30  1:30 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, eddyz87, memxor, song,
	yonghong.song, jolsa, kafai.wan, linux-kernel, hongao,
	syzbot+0962e3a1af6d5e26a52c

bpffs currently frees inodes directly from ->destroy_inode(). This can
race with RCU path walk following a bpffs symlink: a lookup reader may
still hold an unstable inode pointer while unlink frees the inode
memory, leading to a KASAN use-after-free in
security_inode_follow_link().

Keep BPF object reference dropping in ->destroy_inode(), where sleeping
cleanup is allowed, but move symlink target and inode memory freeing to
->free_inode() so VFS releases them after an RCU grace period.

Fixes: 4f375ade6aa9 ("bpf: Avoid RCU context warning when unpinning htab with internal structs")
Reported-by: syzbot+0962e3a1af6d5e26a52c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=0962e3a1af6d5e26a52c
Tested-by: syzbot+0962e3a1af6d5e26a52c@syzkaller.appspotmail.com
Signed-off-by: hongao <hongao@uniontech.com>
---
 kernel/bpf/inode.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c
index 25c06a011825..a1e9660f9237 100644
--- a/kernel/bpf/inode.c
+++ b/kernel/bpf/inode.c
@@ -766,10 +766,14 @@ static void bpf_destroy_inode(struct inode *inode)
 {
 	enum bpf_type type;
 
-	if (S_ISLNK(inode->i_mode))
-		kfree(inode->i_link);
 	if (!bpf_inode_type(inode, &type))
 		bpf_any_put(inode->i_private, type);
+}
+
+static void bpf_free_inode(struct inode *inode)
+{
+	if (S_ISLNK(inode->i_mode))
+		kfree(inode->i_link);
 	free_inode_nonrcu(inode);
 }
 
@@ -778,6 +782,7 @@ const struct super_operations bpf_super_ops = {
 	.drop_inode	= inode_just_drop,
 	.show_options	= bpf_show_options,
 	.destroy_inode	= bpf_destroy_inode,
+	.free_inode	= bpf_free_inode,
 };
 
 enum {
-- 
2.51.0

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

* Re: [PATCH] bpf: defer bpffs symlink inode freeing until RCU grace period
  2026-05-30  1:30 [PATCH] bpf: defer bpffs symlink inode freeing until RCU grace period hongao
@ 2026-06-01 20:42 ` Yonghong Song
  0 siblings, 0 replies; 2+ messages in thread
From: Yonghong Song @ 2026-06-01 20:42 UTC (permalink / raw)
  To: hongao, bpf
  Cc: ast, daniel, andrii, martin.lau, eddyz87, memxor, song, jolsa,
	kafai.wan, linux-kernel, syzbot+0962e3a1af6d5e26a52c



On 5/29/26 6:30 PM, hongao wrote:
> bpffs currently frees inodes directly from ->destroy_inode(). This can
> race with RCU path walk following a bpffs symlink: a lookup reader may
> still hold an unstable inode pointer while unlink frees the inode
> memory, leading to a KASAN use-after-free in
> security_inode_follow_link().
>
> Keep BPF object reference dropping in ->destroy_inode(), where sleeping
> cleanup is allowed, but move symlink target and inode memory freeing to
> ->free_inode() so VFS releases them after an RCU grace period.
>
> Fixes: 4f375ade6aa9 ("bpf: Avoid RCU context warning when unpinning htab with internal structs")
> Reported-by: syzbot+0962e3a1af6d5e26a52c@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=0962e3a1af6d5e26a52c
> Tested-by: syzbot+0962e3a1af6d5e26a52c@syzkaller.appspotmail.com
> Signed-off-by: hongao <hongao@uniontech.com>

Please have tag [PATCH bpf] to indicate it is form bpf tree.
Please have proper name instead of hongao. See examples in bpf repo.
Other than the above, the patch LGTM.

Acked-by: Yonghong Song <yonghong.song@linux.dev>

> ---
>   kernel/bpf/inode.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c
> index 25c06a011825..a1e9660f9237 100644
> --- a/kernel/bpf/inode.c
> +++ b/kernel/bpf/inode.c
> @@ -766,10 +766,14 @@ static void bpf_destroy_inode(struct inode *inode)
>   {
>   	enum bpf_type type;
>   
> -	if (S_ISLNK(inode->i_mode))
> -		kfree(inode->i_link);
>   	if (!bpf_inode_type(inode, &type))
>   		bpf_any_put(inode->i_private, type);
> +}
> +
> +static void bpf_free_inode(struct inode *inode)
> +{
> +	if (S_ISLNK(inode->i_mode))
> +		kfree(inode->i_link);
>   	free_inode_nonrcu(inode);
>   }
>   
> @@ -778,6 +782,7 @@ const struct super_operations bpf_super_ops = {
>   	.drop_inode	= inode_just_drop,
>   	.show_options	= bpf_show_options,
>   	.destroy_inode	= bpf_destroy_inode,
> +	.free_inode	= bpf_free_inode,
>   };
>   
>   enum {


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

end of thread, other threads:[~2026-06-01 20:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-30  1:30 [PATCH] bpf: defer bpffs symlink inode freeing until RCU grace period hongao
2026-06-01 20:42 ` Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome