[PATCH] ecryptfs: fix use-after-free in mount cleanup
From: Jyothi Bommisetty
Date: Thu Nov 19 2026 - 19:15:49 EST
When sget_fc() succeeds, it transfers ownership of fc->s_fs_info
to the superblock and clears the filesystem context pointer.
However, ecryptfs_get_tree() retains a local pointer to the same
ecryptfs_sb_info. If super_setup_bdi() fails, deactivate_locked_super()
can destroy the superblock and free this private data.
The subsequent error cleanup then accesses the stale local pointer,
resulting in a use-after-free.
Clear the local sbi pointer immediately after sget_fc() succeeds,
so the error cleanup does not access memory owned and freed by
the superblock. Also remove the redundant call to
ecryptfs_set_superblock_private(), since sget_fc() already assigns
the superblock's private data.
Fixes: 2ccde7c631f9 ("Clean ecryptfs ->get_sb() up")
Reported-by: syzbot+baa24e4b7e349e388442@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=baa24e4b7e349e388442
Signed-off-by: Jyothi Bommisetty <jyothi.b09052007@xxxxxxxxx>
---
fs/ecryptfs/main.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 5f37cddb9..bfc125462 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -468,14 +468,12 @@ static int ecryptfs_get_tree(struct fs_context *fc)
goto out;
}
+ /* sget_fc() transfers ownership of sbi to the superblock */
+ sbi = NULL;
+
rc = super_setup_bdi(s);
if (rc)
goto out1;
-
- ecryptfs_set_superblock_private(s, sbi);
-
- /* ->kill_sb() will take care of sbi after that point */
- sbi = NULL;
s->s_op = &ecryptfs_sops;
s->s_xattr = ecryptfs_xattr_handlers;
set_default_d_op(s, &ecryptfs_dops);
--
2.56.0