ecryptfs: the lower filesystem gets modified while it is frozen

From: Christian Brauner

Date: Sat Nov 14 2026 - 04:37:11 EST


I'm working on freeze protection fixes in the tree and this is the part
that affects ecryptfs.

A syscall on an ecryptfs mount only takes freeze protection for the
ecryptfs superblock. ecryptfs then modifies the lower filesystem
without any freeze protection for the lower superblock. So with the
lower filesystem frozen it gets modified anyway. On ext4 that trips the
WARN_ON() in ext4_journal_check_start().

Affected are all the lower namespace operations, setattr, truncate,
xattrs, ACLs and fileattr:

- ecryptfs_create(), ecryptfs_mkdir(), ecryptfs_mknod(),
ecryptfs_symlink(), ecryptfs_link(), ecryptfs_do_unlink(),
ecryptfs_rmdir() and ecryptfs_rename() call vfs_create(),
vfs_mkdir(), ... on the lower dentries
- ecryptfs_setattr() and __ecryptfs_truncate() call notify_change()
- ecryptfs_setxattr() and ecryptfs_removexattr() call
__vfs_setxattr_locked() and __vfs_removexattr(), and with
ecryptfs_xattr_metadata ecryptfs_write_metadata_to_xattr() and
ecryptfs_write_inode_size_to_xattr() call __vfs_setxattr()
- ecryptfs_set_acl() and ecryptfs_fileattr_set() call vfs_set_acl()
and vfs_fileattr_set()

Only data writes are protected because they go through kernel_write().

I triggered create, mkdir, unlink, rename, chmod and setxattr below.
The rest is from reading the code.

Reproduced on v7.4-rc1:

mount /dev/vdb /lower; mkdir /lower/enc /ecr
keyctl link @u @s
keyctl add user kmk 0123456789abcdef0123456789abcdef @u
keyctl add encrypted 1000100010001000 "new ecryptfs user:kmk 64" @u
mount -t ecryptfs /lower/enc /ecr -o ecryptfs_sig=1000100010001000,ecryptfs_cipher=aes,ecryptfs_key_bytes=32
cd /ecr; echo x > a; echo x > b; echo x > f; mkdir d1 d2; cd /; sync
fsfreeze -f /lower
touch /ecr/d1/new; mkdir /ecr/d2/nd; rm /ecr/a; mv /ecr/b /ecr/c
chmod 600 /ecr/f; setfattr -n user.x -v 1 /ecr/f

Each of these warns, the mkdir, rename, chmod and setxattr complete
right away and "a" is gone from the frozen lower filesystem. The append
in

echo y >> /ecr/f

waits for the thaw as it should. The create and the mkdir:

WARNING: fs/ext4/ext4_jbd2.c:90 at ext4_journal_check_start+0x1f6/0x2d0, CPU#3: touch/309
Call Trace:
__ext4_journal_start_sb+0x7a/0x470
__ext4_new_inode+0x23da/0x45d0
ext4_create+0x286/0x530
vfs_create+0x2a6/0x6a0
ecryptfs_create+0xf8/0x4c0
lookup_open+0xa80/0x1b20
path_openat+0xd2b/0x2300
do_file_open+0x209/0x480
do_sys_openat2+0x128/0x180
__x64_sys_openat+0x10e/0x210
do_syscall_64+0x10e/0x5e0

WARNING: fs/ext4/ext4_jbd2.c:90 at ext4_journal_check_start+0x1f6/0x2d0, CPU#3: mkdir/322
Call Trace:
__ext4_journal_start_sb+0x7a/0x470
__ext4_new_inode+0x23da/0x45d0
ext4_mkdir+0x249/0xb10
vfs_mkdir+0x2bb/0x760
ecryptfs_mkdir+0x11c/0x570
vfs_mkdir+0x2bb/0x760
filename_mkdirat+0x417/0x590
__x64_sys_mkdir+0x68/0x90
do_syscall_64+0x10e/0x5e0

The way overlayfs deals with this is ovl_want_write(), i.e.
mnt_want_write() on the upper mount around every modification of the
upper layer, taken before the upper inode locks. ecryptfs needs the same
for its lower mount. It must not wrap a region that later calls
kernel_write() on the same superblock though, as that nests
sb_start_write() and deadlocks against a pending freeze.

This predates freeze protection in the callers which came with
5accdf82ba25 ("fs: Improve filesystem freezing handling").