Skip to content

Commit d008960

Browse files
dmantipovbrauner
authored andcommitted
fs: prefer kfree_rcu() in fasync_remove_entry()
In 'fasync_remove_entry()', prefer 'kfree_rcu()' over 'call_rcu()' with dummy 'fasync_free_rcu()' callback. This is mostly intended in attempt to fix weird https://syzkaller.appspot.com/bug?id=6a64ad907e361e49e92d1c4c114128a1bda2ed7f, where kmemleak may consider 'fa' as unreferenced during RCU grace period. See https://lore.kernel.org/stable/20230930174657.800551-1-joel@joelfernandes.org as well. Comments are highly appreciated. Ever since ae65a52 ("mm/slab: document kfree() as allowed for kmem_cache_alloc() objects") kfree() can be used for both kmalloc() and kmem_cache_alloc() so this is no safe. Do not backport this to stable, please. Link ae65a52 ("mm/slab: document kfree() as > allowed for kmem_cache_alloc() objects") Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Link: https://lore.kernel.org/r/20240209125220.330383-1-dmantipov@yandex.ru Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent ef56038 commit d008960

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

fs/fcntl.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -846,12 +846,6 @@ int send_sigurg(struct fown_struct *fown)
846846
static DEFINE_SPINLOCK(fasync_lock);
847847
static struct kmem_cache *fasync_cache __ro_after_init;
848848

849-
static void fasync_free_rcu(struct rcu_head *head)
850-
{
851-
kmem_cache_free(fasync_cache,
852-
container_of(head, struct fasync_struct, fa_rcu));
853-
}
854-
855849
/*
856850
* Remove a fasync entry. If successfully removed, return
857851
* positive and clear the FASYNC flag. If no entry exists,
@@ -877,7 +871,7 @@ int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
877871
write_unlock_irq(&fa->fa_lock);
878872

879873
*fp = fa->fa_next;
880-
call_rcu(&fa->fa_rcu, fasync_free_rcu);
874+
kfree_rcu(fa, fa_rcu);
881875
filp->f_flags &= ~FASYNC;
882876
result = 1;
883877
break;

0 commit comments

Comments
 (0)