The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: shyckless@gmail.com
Cc: jaegeuk@kernel.org, tytso@mit.edu, linux-kernel@vger.kernel.org,
	linux-fscrypt@vger.kernel.org
Subject: Re: [PATCH] fscrypt: Don't set a policy on immutable or append-only directories
Date: Thu, 19 Nov 2026 14:08:00 -0800	[thread overview]
Message-ID: <20261119220800.GA1894@quark> (raw)
In-Reply-To: <20261119-fscrypt-v1-1-c07e1dd93644@gmail.com>

On Thu, Nov 19, 2026 at 12:57:20PM +0000, Suyuan Wang via B4 Relay wrote:
> From: Suyuan Wang <stevewong@hust.edu.cn>
> 
> 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.
> 
> Found with a static analysis tool and checked by hand.
> 
> Fixes: 0b81d0779072 ("fs crypto: move per-file encryption from f2fs tree to fs/crypto")
> Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>

I guess so.  Could you correct the Fixes tag and add 'Cc stable'?  It
should be:

    Fixes: 9bd8212f981e ("ext4 crypto: add encryption policy and password salt support")
    Fixes: f424f664f0e8 ("f2fs crypto: add encryption policy and password salt support")
    Cc: stable@vger.kernel.org

Also, the documentation should be updated too, e.g.:

diff --git a/Documentation/filesystems/fscrypt.rst b/Documentation/filesystems/fscrypt.rst
index 6e2e511a70bb5..188295f09b213 100644
--- a/Documentation/filesystems/fscrypt.rst
+++ b/Documentation/filesystems/fscrypt.rst
@@ -736,7 +736,7 @@ FS_IOC_SET_ENCRYPTION_POLICY can fail with the following errors:
   feature flag enabled using ``tune2fs -O encrypt`` or ``mkfs.ext4 -O
   encrypt``.)
 - ``EPERM``: this directory may not be encrypted, e.g. because it is
-  the root directory of an ext4 filesystem
+  the root directory of an ext4 filesystem or is immutable or append-only
 - ``EROFS``: the filesystem is readonly
 
 Getting an encryption policy

      reply	other threads:[~2026-11-19 22:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 12:57 [PATCH] fscrypt: Don't set a policy on immutable or append-only directories Suyuan Wang via B4 Relay
2026-11-19 22:08 ` Eric Biggers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119220800.GA1894@quark \
    --to=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shyckless@gmail.com \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox