[PATCH v2 25/35] hugetlbfs: zero all hugetlbfs-specific fields of new inodes
From: David Hildenbrand (Arm)
Date: Thu Dec 03 2026 - 06:44:06 EST
hugetlbfs_get_inode() initializes the seals of new hugetlbfs inodes, and
the hugetlbfs inode tracepoints record them.
However, we don't initialize the seals in two cases:
(1) For the root inode through hugetlbfs_get_root()
(2) For an inode that alloc_inode() destroys right away because
inode_init_always() failed.
Consequently, when such an inode is evicted or destroyed with the
tracepoints enabled, we record stale seals, and KMSAN reports an
uninit-value.
Reproduced by closing a hugetlb memfd with seals, and mounting and
unmounting hugetlbfs with the hugetlbfs_evict_inode tracepoint enabled:
the root inode reports the seals of the memfd.
Let's fix it by zeroing all hugetlbfs-specific inode fields when
allocating the inode in hugetlbfs_alloc_inode().
We can now drop the manual initialization of resv_map in
hugetlbfs_get_root().
This has low urgency, as it only affects the tracepoints. No need to CC
stable.
Fixes: 318580ad7f28 ("hugetlbfs: support tracepoint")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
fs/hugetlbfs/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 43d79c9ea8c1b..530c18430cbd0 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -905,7 +905,6 @@ static struct inode *hugetlbfs_get_root(struct super_block *sb,
simple_inode_init_ts(inode);
inode->i_op = &hugetlbfs_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
- HUGETLBFS_I(inode)->resv_map = NULL;
/* directory inodes start off with i_nlink == 2 (for "." entry) */
inc_nlink(inode);
lockdep_annotate_inode_mutex_key(inode);
@@ -1207,6 +1206,7 @@ static struct inode *hugetlbfs_alloc_inode(struct super_block *sb)
hugetlbfs_inc_free_inodes(sbinfo);
return NULL;
}
+ memset_after(p, 0, vfs_inode);
return &p->vfs_inode;
}
--
2.56.1