mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hungyu Lin <dennylin0707@gmail.com>
To: almaz.alexandrovich@paragon-software.com
Cc: ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, cel@kernel.org,
	liubaolin@kylinos.cn, dennylin0707@gmail.com,
	stable@vger.kernel.org
Subject: [PATCH v2] fs/ntfs3: accept unchanged read-only fileattr flags
Date: Fri,  4 Dec 2026 08:21:33 +0000	[thread overview]
Message-ID: <20261204082133.58562-1-dennylin0707@gmail.com> (raw)

ntfs_fileattr_get() reports FS_CASEFOLD_FL on nocase mounts and
FS_COMPR_FL or FS_ENCRYPT_FL on compressed or encrypted files, but
ntfs_fileattr_set() only accepts FS_IMMUTABLE_FL, FS_APPEND_FL and
FS_NODUMP_FL.

chattr reads the flags, changes one bit and writes them all back, so
chattr +d, -d, +i, -i, +a and -a all fail with EOPNOTSUPP on a nocase
mount and on compressed or encrypted files. FS_IOC_FSSETXATTR fails
there even when nothing changes, because vfs_fileattr_set() adds the
reported flags back before calling ntfs_fileattr_set().

Fix this by also accepting these flags when ntfs_fileattr_get() would
report them, as hfsplus does for FS_CASEFOLD_FL. They are not changed,
and setting one that is not already reported still fails with
EOPNOTSUPP.

Fixes: 33f29fc7c67e ("fs/ntfs3: add fileattr support")
Cc: stable@vger.kernel.org
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
v2: Describe the full impact, and build an allowed mask the way hfsplus
    does instead of calling ntfs_fileattr_get() from ntfs_fileattr_set().
v1: https://lore.kernel.org/all/20261029220203.80532-1-dennylin0707@gmail.com/

 fs/ntfs3/file.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index a02244e3b532..54d02684f420 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -134,8 +134,10 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 		      struct file_kattr *fa)
 {
 	struct inode *inode = d_inode(dentry);
+	struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info;
 	struct ntfs_inode *ni = ntfs_i(inode);
 	u32 flags = fa->flags;
+	u32 allowed = FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL;
 	unsigned int new_fl = 0;
 
 	/* Avoid any operation if inode is bad. */
@@ -145,7 +147,16 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 	if (fileattr_has_fsx(fa))
 		return -EOPNOTSUPP;
 
-	if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL))
+	if (sbi->options->nocase)
+		allowed |= FS_CASEFOLD_FL;
+
+	if (is_compressed(ni))
+		allowed |= FS_COMPR_FL;
+
+	if (is_encrypted(ni))
+		allowed |= FS_ENCRYPT_FL;
+
+	if (flags & ~allowed)
 		return -EOPNOTSUPP;
 
 	if (flags & FS_IMMUTABLE_FL)
-- 
2.43.0


                 reply	other threads:[~2026-12-04  8:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261204082133.58562-1-dennylin0707@gmail.com \
    --to=dennylin0707@gmail.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=cel@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liubaolin@kylinos.cn \
    --cc=ntfs3@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®