hugetlbfs: move hugetlbfs_free_inode tracepoint to ->destroy_inode()

hugetlbfs_free_inode() calls trace_hugetlbfs_free_inode(), and the
hugetlbfs__inode event class records inode->i_sb->s_dev.  ->free_inode()
runs from an RCU callback (destroy_inode() queues i_callback() with
call_rcu()), and Documentation/filesystems/porting.rst says that this
callback "is *NOT* ordered wrt superblock destruction; as the matter of
fact, the superblock and all associated structures might be already gone".
put_super() frees the superblock with call_rcu() followed by a workqueue
item (destroy_super_rcu() -> destroy_super_work()).  syzbot hit this with
the event enabled:

  BUG: KASAN: slab-use-after-free in trace_event_raw_event_hugetlbfs__inode+0x45b/0x4c0 include/trace/events/hugetlbfs.h:36
  Read of size 4 at addr ffff888038850010 by task syz-executor952/6134
   hugetlbfs_free_inode+0x15e/0x1f0 fs/hugetlbfs/inode.c:1182
   i_callback+0x46/0x80 fs/inode.c:317
   rcu_do_batch kernel/rcu/tree.c:2650 [inline]
   rcu_core+0x5f0/0x1220 kernel/rcu/tree.c:2919
  Allocated by task 6134:
   alloc_super fs/super.c:326 [inline]
   sget_fc+0x1ba/0x1f60 fs/super.c:874
   hugetlbfs_get_tree+0x1e7/0x2b0 fs/hugetlbfs/inode.c:1431
  Freed by task 855:
   kfree+0x22b/0x6d0 mm/slub.c:6923
   process_one_work+0xac7/0x1b10 kernel/workqueue.c:3495

Emit the event from hugetlbfs_destroy_inode() instead.  destroy_inode()
calls ->destroy_inode() synchronously, before it queues the RCU callback,
while the superblock is still alive; hugetlbfs_destroy_inode() already
dereferences inode->i_sb there.  ->free_inode() is left with only the
kmem_cache_free().

Since the event no longer fires from ->free_inode(), rename it to
hugetlbfs_destroy_inode so that its name matches where it is emitted, as
suggested by David and Muchun.

Found by syzbot; analysed and tested with the syzbot C reproducer on an
arm64 KASAN kernel.

Link: https://lore.kernel.org/[email protected]
Fixes: 014ad7c42a ("hugetlbfs: use tracepoints in hugetlbfs functions.")
Signed-off-by: Joas Antonio dos Santos <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reported-by: <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Suggested-by: David Hildenbrand <[email protected]>
Suggested-by: Muchun Song <[email protected]>
Reviewed-by: Muchun Song <[email protected]>
Acked-by: David Hildenbrand (Arm) <[email protected]>
Cc: Oscar Salvador <[email protected]>
Cc: Hongbo Li <[email protected]>
Cc: <[email protected]>
This commit is contained in:
Joas Antonio dos Santos
2026-11-09 22:44:30 -08:00
committed by Andrew Morton
parent c8c47f4072
commit ccf8bda05b
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -1187,12 +1187,12 @@ static struct inode *hugetlbfs_alloc_inode(struct super_block *sb)
static void hugetlbfs_free_inode(struct inode *inode)
{
trace_hugetlbfs_free_inode(inode);
kmem_cache_free(hugetlbfs_inode_cachep, HUGETLBFS_I(inode));
}
static void hugetlbfs_destroy_inode(struct inode *inode)
{
trace_hugetlbfs_destroy_inode(inode);
hugetlbfs_inc_free_inodes(HUGETLBFS_SB(inode->i_sb));
}
+1 -1
View File
@@ -72,7 +72,7 @@ DEFINE_EVENT(hugetlbfs__inode, hugetlbfs_evict_inode,
TP_ARGS(inode)
);
DEFINE_EVENT(hugetlbfs__inode, hugetlbfs_free_inode,
DEFINE_EVENT(hugetlbfs__inode, hugetlbfs_destroy_inode,
TP_PROTO(struct inode *inode),