Page MenuHomeFreeBSD

makefs: allow to create a immutable ffs (eg. rootfs)
Needs ReviewPublic

Authored by fbsd_paepcke.de on Feb 26 2023, 9:07 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 5, 5:11 AM
Unknown Object (File)
Thu, Mar 28, 3:34 AM
Unknown Object (File)
Mar 18 2024, 4:37 PM
Unknown Object (File)
Mar 7 2024, 7:52 PM
Unknown Object (File)
Dec 23 2023, 12:05 PM
Unknown Object (File)
Dec 13 2023, 8:05 AM
Unknown Object (File)
Nov 15 2023, 11:38 AM
Unknown Object (File)
Oct 14 2023, 10:39 AM
Subscribers

Details

Reviewers
mckusick
markj
Summary

This patch adds to makefs a new -r [read-only] command line switch. This option allows to manage the ffs superblock int8_t 'ronly' flag during fs creation.

At the moment a mount / mount -o ro actively manages (toggle) the *on-disk-state* (!?) of the attribute, but ignores the existing state. And sys/ufs seems to mange a rdonly but not ronly to figure out the existing state.

Target is to have a real working os based immutable ufs/ffs protection for rootfs/bootfs partitions, not only for (compressed) images. And Im not sure if I stumbled across a bug, missing feature or just doing something the wrong way.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

fbsd_paepcke.de edited the summary of this revision. (Show Details)

As you note, the existing value of the ronly flag is ignored when a filesystem is mounted. Rather it is set to reflect how the filesystem has been mounted. So presetting it to a value when creating the filesystem is pointless. If you want a filesystem in which the files and directories cannot be changed then you should set the SF_IMMUTABLE and SF_NOUNLINK flags (see chflags(2) for details) in every inode in the filesystem when you create it.

But the flags are all reversible via common base userland tools (runlevel/offline) similar to a simple r/w re-mount. So its no a bug, the on-disk written flag tracks only the last known r/w state, but does not enforces a state?

As fare as I can see we currently have in ffs 21 x int32_t to burn.

/* reserved for future constants */
int32_t fs_sparecon32[21];

Is there a small chance to burn one of the 21 spares
into a generic future proof mount-restrictions bit-matrix
and use the first bit as a (backwards compatible) future
real fs_read-only lock bool?

But the flags are all reversible via common base userland tools (runlevel/offline) similar to a simple r/w re-mount. So its no a bug, the on-disk written flag tracks only the last known r/w state, but does not enforces a state?

As far as I can see we currently have in ffs 21 x int32_t to burn.

/* reserved for future constants */
int32_t fs_sparecon32[21];

Is there a small chance to burn one of the 21 spares
into a generic future proof mount-restrictions bit-matrix
and use the first bit as a (backwards compatible) future
real fs_read-only lock bool?

Those flags can only be unset by the super-user (root) and if you enable secure mode they can only be reset by the super-user when the system is running in single-user mode.
It would be possible to add another flag to the existing um_flags word with the semantic that the filesystem can be mounted only as read-only (UM_READONLY). Of course it would still be possible for the superuser to clear this flag but it takes slightly more effort.

[...] It would be possible to add another flag to the existing um_flags word with the semantic that the filesystem can be mounted only as read-only (UM_READONLY). Of course it would still be possible for the superuser to clear this flag but it takes slightly more effort.

Yes, that is a great approach!
I will look into it / make a proposal.

In a second step, we could guard the UM_READONLY flag via the
existing FFS superblock checksum logic in way that fsck will detect
and refuse to auto-repair a manual flag clean attempt.

Thank you!

[...] It would be possible to add another flag to the existing um_flags word with the semantic that the filesystem can be mounted only as read-only (UM_READONLY). Of course it would still be possible for the superuser to clear this flag but it takes slightly more effort.

Yes, that is a great approach!
I will look into it / make a proposal.

In a second step, we could guard the UM_READONLY flag via the
existing FFS superblock checksum logic in way that fsck will detect
and refuse to auto-repair a manual flag clean attempt.

Thank you!

Have you made any progress on this issue? If not then you may want to abandon this review request.