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 09/10] ufs: refuse read-write mount of filesystems with active snapshots
Date: Sat,  1 Aug 2026 22:55:29 +0000	[thread overview]
Message-ID: <20260801225530.148386-10-ali@iusegentoo.com> (raw)
In-Reply-To: <20260801225530.148386-1-ali@iusegentoo.com>

A UFS2 filesystem can hold up to FSMAXSNAP snapshots, recorded in
fs_snapinum[]. A snapshot is an inode whose block pointers describe the
state of the filesystem at the moment it was taken, using the reserved
values BLK_NOCOPY and BLK_SNAP alongside ordinary block numbers.
Keeping one valid requires copy on write: before a block that the
snapshot references is overwritten or freed, its old contents have to be
copied into the snapshot.

Linux implements none of this. It does not read fs_snapinum[], does not
know the SF_SNAPSHOT inode flag, and treats the reserved block pointer
values 1 and 2 as ordinary fragment addresses. Mounting such a
filesystem read-write and changing a single file is enough for every
snapshot on it to stop describing the point in time it was taken at, and
there is no way to notice afterwards.

Refuse the read-write mount while any snapshot is recorded. Read-only
access is unaffected.

Signed-off-by: Ali Ahmet Memis <ali@iusegentoo.com>
---
 fs/ufs/super.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index df95502e039e..6132c28c4308 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -776,6 +776,7 @@ static bool ufs_features_allow_write(struct super_block *sb)
 {
 	struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
 	struct ufs_super_block_third *usb3 = ubh_get_usb_third(uspi);
+	unsigned int i;
 	u32 fsflags;
 
 	if (uspi->fs_magic != UFS2_MAGIC)
@@ -792,6 +793,12 @@ static bool ufs_features_allow_write(struct super_block *sb)
 		       __func__);
 		return false;
 	}
+	for (i = 0; i < UFS_FSMAXSNAP; i++) {
+		if (usb3->fs_un2.fs_44.fs_snapinum[i]) {
+			pr_err("%s(): fs has active snapshots\n", __func__);
+			return false;
+		}
+	}
 	return true;
 }
 
-- 
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 ` [PATCH 05/10] ufs: honour on-disk immutable and append-only flags Ali Ahmet Memis
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 ` Ali Ahmet Memis [this message]
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-10-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®