Re: [PATCH v2] fscrypt: Don't set a policy on immutable or append-only directories
From: Eric Biggers
Date: Tue Nov 24 2026 - 18:08:11 EST
On Fri, Nov 20, 2026 at 04:26:54AM +0000, Suyuan Wang via B4 Relay wrote:
> From: Suyuan Wang <stevewong@xxxxxxxxxxx>
>
> FS_IOC_SET_ENCRYPTION_POLICY stores an encryption context in the
> directory (an xattr on ext4 and f2fs) and marks the inode as encrypted.
> fscrypt_ioctl_set_policy() checks inode_owner_or_capable(), but not the
> immutable or append-only inode flags, so the ioctl also succeeds on a
> directory with one of those flags set. Setting any other xattr on the
> same directory fails with -EPERM in may_write_xattr(), and
> FS_IOC_ENABLE_VERITY refuses such files as well.
>
> For example, on ext4 with the encrypt feature:
>
> mkdir d && chattr +i d
> setfattr -n user.x -v 1 d -> Operation not permitted
> FS_IOC_SET_ENCRYPTION_POLICY on d -> succeeds, d now has a policy
>
> Return -EPERM for an immutable or append-only directory before setting
> the policy, as may_write_xattr() does. Calls that find the same policy
> already set still return 0, since they don't change the inode. Update
> the documented EPERM cases to match.
>
> Found with a static analysis tool and checked by hand.
>
> Fixes: 9bd8212f981e ("ext4 crypto: add encryption policy and password salt support")
> Fixes: f424f664f0e8 ("f2fs crypto: add encryption policy and password salt support")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
> Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
> Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
Applied to https://git.kernel.org/pub/scm/fs/fscrypt/linux.git/log/?h=for-next
- Eric