Commit Graph

13 Commits

Author SHA1 Message Date
Jelle van der Waa
8b67ed854f validatefs: correct argument comments
These functions come from util-linux and can't be renamed.
2025-05-24 17:13:39 +02:00
Daan De Meyer
8857aa74e5 tree-wide: Clean up includes
This commit cleans up the includes for all the small tools across
the tree.

A few cases of returning EXIT_SUCCESS are replaced with returning
0 to avoid including <stdlib.h>.

Split out of #37344.
2025-05-14 22:34:02 +02:00
Yu Watanabe
f78e89b018 validatefs: split out validating gpt label and type
No functional change, just refactoring.
This addresses https://github.com/systemd/systemd/pull/37434#discussion_r2088950725.
2025-05-15 02:58:05 +09:00
Yu Watanabe
e4db2c9b83 validatefs: drop unnecessary empty lines 2025-05-15 02:57:57 +09:00
Lennart Poettering
f7d3262844 validatefs: properly authenticate all subordinate devices of DM devices
Previously, we'd only authenticate "one" of the subordinate devices of a
DM device, and which one was somewhat undefined, it would be what we
find in slaves/ first. This is in particular a problem with dm-verity
which generally has two subordinate devices: the data device and the
hash device.

Let's fix this properly. This means two things:

1. iterate through *all* subordinate devices of a DM device (i.e.
   iterate through the sysfs slaves/ subdir), not just
   one

2. permit configuring a list of gpt labels and gpt type uuids in the
   xattrs of mount points, so that all valid combinations can be listed.

This only updates the validation like this. The generation of xattrs
that carry multiple type uuids/labels in systemd-repart will follow in a
later commit.

This extends the syntax of the two gpt-related xattrs, to allow lists of
things. This is a true extension, without breaking compat (but even if
it was, it wouldn't matter given that validatefs was added post v257,
i.e. is not included in a stable release.

Fixes: #37157
2025-05-14 15:44:54 +02:00
Lennart Poettering
510e966677 validatefs: split out validate_fields_check() into three functions
Just some basic refactoring, no actual code changes
2025-05-14 13:04:20 +02:00
Daan De Meyer
decad4826d static-destruct: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Daan De Meyer
e548ca38b9 device-util: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Daan De Meyer
fda652117e fs-util: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Mike Yuan
f361fad245 validatefs: use fgetxattr_malloc() where appropriate 2025-03-31 19:23:50 +02:00
Mike Yuan
8950f7651e validatefs: do not use EXIT_* in run()
The plain DEFINE_MAIN_FUNCTION is used, i.e. all >= 0 retvals
are treated as success. No need for EXIT_* annotations.
2025-03-31 19:23:50 +02:00
Mike Yuan
7b8d6fc836 validatefs: insert empty line after short description in help() text
As per our usual coding style.
2025-03-31 19:23:50 +02:00
Lennart Poettering
0bdd5ccc81 validatefs: add new tool that enforces mount constraints
This new tool looks for a three xattr on the root inode of a file system
that encode mount constraints of the file system. The tool is supposed
to be hooke into the mount logic and is supposed to protect against
misappropriating trusted file systems in unintended ways.

Consider the following scenario: we boot up on first boot and create a
tpm-locked pair of /var/ and /srv/ partitions via systemd-repart. An
attacker then offline modifies the partition table, exchanging the
metadata of the /var/ and /srv/ partition. So far we'd happily accept
that, honour the modified metadata and boot up. This could be used to
revert changes to /var/ or similar. And all that even though both
partitions are encrypted and locked to TPM!

With this new mechanism we can encode in the protected contents of the
file systems the ways it can be used: the partition type uuid, the
partition label and the intended mount point can be stored in xattrs,
and we can check them automatically on mount, and take action on
mismatch. (action would typically be immediate reboot).
2025-03-31 15:14:13 +02:00