mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ali Ahmet Memis <ali@iusegentoo.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 05/10] ufs: honour on-disk immutable and append-only flags
Date: Sat,  1 Aug 2026 22:55:25 +0000	[thread overview]
Message-ID: <20260801225530.148386-6-ali@iusegentoo.com> (raw)
In-Reply-To: <20260801225530.148386-1-ali@iusegentoo.com>

ui_flags holds the BSD chflags of the inode. ufs1_read_inode() and
ufs2_read_inode() copy it into ufsi->i_flags and nothing else ever looks
at it. In particular it never reaches inode->i_flags, so IS_IMMUTABLE()
and IS_APPEND() are always false for a UFS inode. The check in
ufs_truncate(),

	if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
		return -EPERM;

can never fire, and neither can the generic ones in the VFS.

A file that FreeBSD marked with chflags schg or uchg is therefore freely
writable and removable once the filesystem is mounted on Linux, and an
sappnd file can be rewritten rather than only appended to.

Map the immutable and append-only bits onto S_IMMUTABLE and S_APPEND
when the inode is read. Only 44BSD and UFS2 are handled: the other
flavours put something else at that offset and their ui_flags is not a
chflags word.

NOUNLINK has no equivalent in inode->i_flags. Mapping it to S_IMMUTABLE
would be wrong, since it is meant to allow modification, so files marked
that way stay removable for now.

Note that Linux offers no way to clear these flags again; UFS has no
FS_IOC_SETFLAGS support. Filesystems carrying them have to be edited
from an operating system that implements chflags.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Ali Ahmet Memis <ali@iusegentoo.com>
---
 fs/ufs/inode.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index 7079285bac2a..029f6771b214 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -517,6 +517,22 @@ const struct address_space_operations ufs_aops = {
 	.bmap = ufs_bmap
 };
 
+// only 44BSD and UFS2 store BSD chflags in ui_flags
+static void ufs_set_inode_flags(struct inode *inode)
+{
+	unsigned int flavour = UFS_SB(inode->i_sb)->s_flavour;
+	unsigned int flags = UFS_I(inode)->i_flags;
+
+	if (flavour != UFS_MOUNT_UFSTYPE_44BSD &&
+	    flavour != UFS_MOUNT_UFSTYPE_UFS2)
+		return;
+
+	if (flags & (UFS_UF_IMMUTABLE | UFS_SF_IMMUTABLE))
+		inode->i_flags |= S_IMMUTABLE;
+	if (flags & (UFS_UF_APPEND | UFS_SF_APPEND))
+		inode->i_flags |= S_APPEND;
+}
+
 // on-disk criterion is i_size < fs_maxsymlinklen, not i_blocks
 static bool ufs_is_fast_symlink(struct inode *inode)
 {
@@ -704,6 +720,7 @@ struct inode *ufs_iget(struct super_block *sb, unsigned long ino)
 	ufsi->i_dir_start_lookup = 0;
 	ufsi->i_osync = 0;
 
+	ufs_set_inode_flags(inode);
 	ufs_set_inode_ops(inode);
 
 	UFSD("EXIT\n");
-- 
2.55.0


  parent reply	other threads:[~2026-08-01 22:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-01 22:55 [PATCH 00/10] ufs: correctness fixes for valid on-disk filesystems Ali Ahmet Memis
2026-08-01 22:55 ` [PATCH 01/10] ufs: name the modern UFS2 superblock fields Ali Ahmet Memis
2026-08-01 22:55 ` [PATCH 02/10] ufs: use i_size to detect fast symlinks Ali Ahmet Memis
2026-08-01 22:55 ` [PATCH 03/10] ufs: free UFS2 external attribute blocks on inode deletion Ali Ahmet Memis
2026-08-01 22:55 ` [PATCH 04/10] ufs: do not inherit file flags from the parent directory Ali Ahmet Memis
2026-08-01 22:55 ` Ali Ahmet Memis [this message]
2026-08-01 22:55 ` [PATCH 06/10] ufs: fix fragment relocation offsets within a folio Ali Ahmet Memis
2026-08-01 22:55 ` [PATCH 07/10] ufs: revalidate filesystem state before remounting read-write Ali Ahmet Memis
2026-08-01 22:55 ` [PATCH 08/10] ufs: refuse read-write mount when fsck or journal replay is needed Ali Ahmet Memis
2026-08-01 22:55 ` [PATCH 09/10] ufs: refuse read-write mount of filesystems with active snapshots Ali Ahmet Memis
2026-08-01 22:55 ` [PATCH 10/10] ufs: refuse read-write mount of check-hashed filesystems Ali Ahmet Memis

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=20260801225530.148386-6-ali@iusegentoo.com \
    --to=ali@iusegentoo.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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®