Commit Graph
6954 Commits
Author SHA1 Message Date
Lennart Poettering 97ce55e3e5 dissect: update error code comment a bit 2023-04-05 20:50:47 +02:00
Lennart Poettering 598fd4da1c dissect: disallow empty partition tables
If we don't find a single useful partition table, refusing dissection.

(Except in systemd-dissect, when we are supposed to show DDI
information, in that case allow this to run and show general DDI
information, i.e. size, UUID and name at least)
2023-04-05 20:49:48 +02:00
Lennart Poettering 93a8a85be3 dissect: make returning of DissectedImage object optional
Sometimes, we just want to validate if an image (or image policy) works,
hence let's make the returning optional.
2023-04-05 20:48:25 +02:00
Lennart Poettering 7cd7a19568 dissect: add dissect_image_file_and_warn()
This is to dissect_image_file() what dissect_loop_device_and_warn() is
to dissect_loop_device(), i.e. it dissects the image file and logs an
error string if that fails instead of just returning an error.
2023-04-05 20:47:23 +02:00
Lennart Poettering cd22d8562d dissect: actually enforce policy 2023-04-05 20:46:27 +02:00
Lennart Poettering 84be0c710d tree-wide: hook up image dissection policy logic everywhere 2023-04-05 20:45:30 +02:00
Lennart Poettering d452335aa4 dissect: add image dissection policy framework 2023-04-05 20:44:36 +02:00
Yu Watanabe 78ebf8bfb6 Merge pull request #27137 from yuwata/id128-get-machine
sd-id128: introduce id128_get_machine() and _at()
2023-04-05 15:24:45 +09:00
William Roberts 96181b7a89 tpm2: fix nits from PR #26185
Fixes:
  - Comment style
  - Alignment style
  - cleanup macro usage
  - incorrect error message[1]

1. Thanks to tempusfugit991@gmail.com for pointing out the error
message mistake.

Signed-off-by: William Roberts <william.c.roberts@intel.com>
2023-04-04 20:41:11 +01:00
Yu Watanabe a9f48db5f6 machine-id-setup: do not read host's machine ID when root directory is specified
If a root directory is specified, and e.g. /var under the root directory
is a symlink to the host's /var, then we wrongly read host's machine ID,
even if O_NOFOLLOW is set.

Let's chase the path with CHASE_NOFOLLOW to refuse such case.

Also, refuse null ID, otherwise we may setup machine ID with NULL.
2023-04-05 00:52:56 +09:00
Yu Watanabe f7b5f39934 discover-image: use id128_get_machine() at one more place 2023-04-05 00:52:56 +09:00
Yu Watanabe edd595f760 specifier: always convert missing machine-id file to EUNATCH
Then, use id128_get_machine().
2023-04-05 00:52:56 +09:00
Yu Watanabe e212f42279 fd-util: introduce dir_fd_is_root_or_cwd() 2023-04-05 00:52:56 +09:00
Zbigniew Jędrzejewski-Szmek 73ed4874e9 shared/exec-util: reduce scope of iterator variables 2023-04-03 15:28:53 +02:00
William Roberts acbb504eaf tpm2: add support for a trusted SRK
Prevent attackers from spoofing the tpmKey portion of the AuthSession by
adding a trusted key to the LUKS header metadata. Also, use a persistent
object rather than a transient object.

This provides the following benifits:
1. No way to MITM the tpmKey portion of the session, see [1] for
details.

2. Strengthens the encrypted sessions, note that the bindKey could be
   dropped now.

3. Speed, once it's created we just use it.

4. Owner Auth is needed to call create primary, so using the SRK
   creates a scratch space for normal users.

This is a "first to set" model, in where the first person to set the key
in the LUKS header wins. Thus, setup should be done in a known good
state. If an SRK, which is a primary key at a special persistent
address, is found, it will use whatever is there. If not, it creates an
SRK. The SRK follows the convetions used through the tpm2-software
organization code on GitHub [2], however, a split has occured between
Windows and Linux with respect to SRK templates. The Linux SRK is
generated with the unique field size set to 0, in Windows, it properly
sets the size to key size in bytes and the unique data to all 0's of that
size. Note the proper templates for SRKs is covered in spec [3].
However, the most important thing, is that both SRKs are passwordless,
and thus they should be interchangable. If Windows is the first to make
the SRK, systemd will gladly accept it and vice-versa.

1. Without the bindKey being utilized, an attacker was able to intercept
this and fake a key, thus being able to decrypt and encrypt traffic as
needed. Introduction of the bindKey strengthened this, but allows for
the attacker to brute force AES128CFB using pin guesses. Introduction of
the salt increases the difficulty of this attack as well as DA attacks
on the TPM objects itself.

2. https://github.com/tpm2-software

3. https://trustedcomputinggroup.org/wp-content/uploads/TCG-TPM-v2.0-Provisioning-Guidance-Published-v1r1.pdf

Fixes: #20668
Fixes: #22637

Signed-off-by: William Roberts <william.c.roberts@intel.com>
2023-04-03 13:10:49 +02:00
Lennart Poettering 6b868766eb Merge pull request #27044 from bluca/sysext_recursive_dir
Ensure sysexts do not contain an os-release file, do not load sysexts from /usr[/local]/lib/extensions/
2023-04-03 12:38:48 +02:00
Zbigniew Jędrzejewski-Szmek a78413baae user-sessions: do not remove /etc/nologin
pam_nologin looks for /etc/nologin and /run/nologin.
user-sessions creates (and removes) /run/nologin, but also removes
/etc/nologin. (This behaviour is unchanged since the introduction
of the binary in e92787416c691c3f34f47349e5eae3fa68eae856.)

By not removing pam_nologin we fully drop compatibility with PAM < 1.1.
This has the advantage that now /etc/nologin can be used by administrator to
disable user logins, e.g. for extended maintanance. We already specified
PAM >= 1.1.2 as dependency, so this was already covered.

The makes the code match the man page.

Fixes #26965.
2023-04-03 12:32:56 +02:00
Daan De Meyer 63105f33ed find-esp: Add openat() like helpers that operate on fds
We also rework the internals of find-esp to work on directory file
descriptors instead of absolute paths and do a lot of general cleanups.

By passing the parent directory file descriptor to verify_fsroot_dir()
along with the name of the directory we're operating on, we can get rid
of the fallback that goes via path to open the parent directory if '..'
fails due to permission errors.
2023-04-01 14:29:29 +02:00
Daan De Meyer 05c423adc9 find-esp: Drop explicit automount trigger
We call statx_fallback() which calls either statx() or fstatat(),
both of which automount by default, so we don't need the explicit
trigger.
2023-04-01 14:25:30 +02:00
Daan De Meyer c706b27f40 btrfs-util: Add btrfs_get_block_device_at()
Let's make btrfs_get_block_device_fd() more generic by renaming it
to btrfs_get_block_device_at() so it can operate on only paths, dir_fd
and path, or only on fd by using xopenat().
2023-04-01 14:25:30 +02:00
Yu Watanabe 7be9657706 rm-rf: also chmod() directory if it cannot be opened
Otherwise, directory with zero access mode cannot be removed.

This is a revised version of 808c8b25ee,
- dropped O_NOFOLLOW from fd_reopen()
- fixed error handling on opening path in rm_rf().
2023-03-31 11:52:03 +09:00
Luca Boccassi cfe9d45207 Revert "rm-rf: also chmod() directory if it cannot be opened"
This reverts commit 808c8b25ee.
2023-03-30 16:48:22 +01:00
Zbigniew Jędrzejewski-Szmek e61bab2b55 Merge pull request #26883 from yuwata/rm-rf
rm-rf: also chmod directory if cannot be opened
2023-03-30 14:54:59 +02:00
Luca Boccassi 6afa5d862e sysext: validate that they do not contain os-release
sysexts are not supposed to ship os-release files, enforce this
when loading them
2023-03-30 11:28:12 +01:00
Luca Boccassi de862276ed sysext: stop storing under /usr/lib[/local]/extensions/
sysexts are meant to extend /usr. All extension images and directories are opened and merged in a
single, read-only overlayfs layer, mounted on /usr.
So far, we had fallback storage directories in /usr/lib/extensions and /usr/local/lib/extensions.
This is problematic for three reasons.

Firstly, technically, for directory-based extensions the kernel will reject
creating such an overlay, as there is a recursion problem. It actively
validates that a lowerdir is not a child of another lowerdir, and fails with
-ELOOP if it is. So having a sysext /usr/lib/extensions/myextdir/ would result
in an overlayfs config lowerdir=/usr/lib/extensions/myextdir/usr/:/usr which is
not allowed, as indicated by Christian the kernel performs this check:

/*
 * Check if this layer root is a descendant of:
 * - another layer of this overlayfs instance
 * - upper/work dir of any overlayfs instance
 */

<...>

/* Walk back ancestors to root (inclusive) looking for traps */
while (!err && parent != next) {
        if (is_lower && ovl_lookup_trap_inode(sb, parent)) {
                err = -ELOOP;
                pr_err("overlapping %s path\n", name);

Secondly, there's a confusing aspect to this recursive storage. If you
have /usr/lib/extensions/myext.raw which contains /usr/lib/extensions/mynested.raw
'systemd-sysext merge' will only pick up the first one, but both will appear in
the merged root under /usr/lib/extensions/. So you have two extension images, both
appear in your merged filesystem, but only one is actually in use.

Finally, there's a conceptual aspect: the idea behind sysexts and hermetic /usr
is that the /usr tree is not modified locally, but owned by the vendor. Dropping
extensions in /usr thus goes contrary to this foundational concept.
2023-03-30 11:25:17 +01:00
Luca Boccassi d51f8eb366 rename extension-release.[c|h] -> extension-util.[c|h]
It will be used for other extension DDI validation, not just for extension-release
validation
2023-03-30 11:25:17 +01:00
Lennart Poettering e829f28c1b fdset: add new fdset_consume() helper 2023-03-29 19:09:10 +02:00
Lennart Poettering bdcad22e8e fdset: add new helper to convert an fdset to an array 2023-03-29 19:09:10 +02:00
Lennart Poettering 08a0ebc6be fdset: minor modernizations
Let's use more _cleanup_ expressions. Various other modernizations. No
actual code changes, except for maybe a conversion to use heap memory
when generating an array of fds, instead of stack as before. Given that
fdstores are typically user controlled, that should be a wise idea.
2023-03-29 19:09:10 +02:00
Lennart Poettering 522f12224c format-table: add new cell type for displaying major/minor devnums 2023-03-29 18:27:05 +02:00
Lennart Poettering bd33207bb1 format-table: add inode type cell type 2023-03-29 18:27:05 +02:00
Zbigniew Jędrzejewski-Szmek 7d0c47dad0 shared/exec-util: null_or_empty_path() does not return boolean
We shouldn't report that the file is empty if the stating fails. Let's do the
same as in other places, and just ignore the error and let the subsequent
operation fail.
2023-03-28 18:50:31 +02:00
Yu Watanabe 1d4f517bba Merge pull request #26993 from mrc0mmand/TEST-46-tweaks
test: explicitly pull in systemd-userdbd.service
2023-03-28 13:39:08 +09:00
Frantisek Sumsal 13c2d0b15f userdb: rename the destructor to follow our coding style 2023-03-27 13:29:49 +02:00
Frantisek Sumsal d31706384d userdb: fix a memory leak
[   49.275617] testsuite-46.sh[1862]: =================================================================
[   49.275870] testsuite-46.sh[1862]: ==1862==ERROR: LeakSanitizer: detected memory leaks
[   49.276039] testsuite-46.sh[1862]: Direct leak of 103 byte(s) in 14 object(s) allocated from:
[   49.276515] testsuite-46.sh[1862]:     #0 0x7f4dbc07243b in strdup (/lib64/libasan.so.8+0x7243b)
[   49.276707] testsuite-46.sh[1862]:     #1 0x7f4dbb3900d5 in free_and_strdup ../src/basic/string-util.c:952
[   49.276931] testsuite-46.sh[1862]:     #2 0x7f4dbb15c67d in json_dispatch_user_group_name ../src/shared/json.c:4699
[   49.277134] testsuite-46.sh[1862]:     #3 0x7f4dbb16da9b in json_dispatch ../src/shared/json.c:4395
[   49.277352] testsuite-46.sh[1862]:     #4 0x7f4dbb25b28e in userdb_on_query_reply ../src/shared/userdb.c:305
[   49.277603] testsuite-46.sh[1862]:     #5 0x7f4dbb2748b9 in varlink_dispatch_reply ../src/shared/varlink.c:760
[   49.277766] testsuite-46.sh[1862]:     #6 0x7f4dbb2748b9 in varlink_process ../src/shared/varlink.c:951
[   49.277975] testsuite-46.sh[1862]:     #7 0x7f4dbb27a001 in defer_callback ../src/shared/varlink.c:1897
[   49.278197] testsuite-46.sh[1862]:     #8 0x7f4dbb5d57dd in source_dispatch ../src/libsystemd/sd-event/sd-event.c:4191
[   49.278421] testsuite-46.sh[1862]:     #9 0x7f4dbb5d685d in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:4780
[   49.278675] testsuite-46.sh[1862]:     #10 0x7f4dbb5d70bf in sd_event_run ../src/libsystemd/sd-event/sd-event.c:4841
[   49.278873] testsuite-46.sh[1862]:     #11 0x7f4dbb257e7c in userdb_process ../src/shared/userdb.c:591
[   49.279048] testsuite-46.sh[1862]:     #12 0x7f4dbb25f78f in membershipdb_iterator_get ../src/shared/userdb.c:1411
[   49.279280] testsuite-46.sh[1862]:     #13 0x7f4dbb23a98c in user_record_show ../src/shared/user-record-show.c:187
[   49.279504] testsuite-46.sh[1862]:     #14 0x404ae3 in show_user ../src/userdb/userdbctl.c:93
[   49.279710] testsuite-46.sh[1862]:     #15 0x40b4f5 in display_user ../src/userdb/userdbctl.c:418
[   49.279961] testsuite-46.sh[1862]:     #16 0x7f4dbb2804d2 in dispatch_verb ../src/shared/verbs.c:110
[   49.280233] testsuite-46.sh[1862]:     #17 0x40dcf3 in run ../src/userdb/userdbctl.c:1327
[   49.280434] testsuite-46.sh[1862]:     #18 0x40dcf3 in main ../src/userdb/userdbctl.c:1330
[   49.280657] testsuite-46.sh[1862]:     #19 0x7f4db9e4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
[   49.280907] testsuite-46.sh[1862]: SUMMARY: AddressSanitizer: 103 byte(s) leaked in 14 allocation(s).
2023-03-27 13:29:49 +02:00
Yu Watanabe 9e43296fd2 bootctl: split-out entry token related definitions into boot-entry.[ch]
No functional change, just preparation for later commits.
These can be used in kernel-install later.

Note, unlike the our usual coding style, the arguments for
boot_entry_token_ensure() and parse_boot_entry_token_type() are
referenced, updated, and may freed, hence, always pass initialized
values. That's why they are not named as 'ret_xyz'.
2023-03-27 09:51:18 +02:00
Yu Watanabe 363ed18730 Merge pull request #26960 from poettering/syscall-catchup
syscall filter group updates
2023-03-25 13:39:27 +09:00
Yu Watanabe 808c8b25ee rm-rf: also chmod() directory if it cannot be opened
Otherwise, directory with zero access mode cannot be removed.
2023-03-25 05:55:38 +09:00
Yu Watanabe da19c07198 rm-rf: mask file mode with 07777 when passed to chmod()
No functional change hopefully, just for safety.
2023-03-25 04:50:27 +09:00
Yu Watanabe cd2cd095db rm-rf: fix errno handling 2023-03-25 04:50:27 +09:00
Lennart Poettering 50ed5cbf5f tree-wide: port various places to find_line_startswith() 2023-03-24 18:30:20 +01:00
Daan De Meyer f461a28da7 chase-symlinks: Rename chase_symlinks() to chase()
Chasing symlinks is a core function that's used in a lot of places
so it deservers a less verbose names so let's rename it to chase()
and chaseat().

We also slightly change the pattern used for the chaseat() helpers
so we get chase_and_openat() and similar.
2023-03-24 13:43:51 +01:00
Lennart Poettering 50524bd887 seccomp-util: enforce group ordering
So far we asked via a comment that @default should stay the first group
and @known the last group in the list. Let's enforce that statically, in
code, too.
2023-03-24 12:28:46 +01:00
Lennart Poettering 76e86b8dd8 seccomp-util: add some newer syscalls to existing groups
These three new syscalls are mostly just new flavours or extensions of
existing syscalls, hence add them to the same groups.
2023-03-24 12:28:03 +01:00
Lennart Poettering d12632a861 seccomp-util: add new @sandbox syscall group with landlock/seccomp
Let's group these 4 syscalls, as they offer similar things and I guess
might be used in conjunction quite often, as they offer unprivileged
sandboxing.

Fixes: #26913
2023-03-24 12:27:23 +01:00
Luca Boccassi 2a775d5faf Merge pull request #26935 from keszybz/test-parse_aux
Add test for auxv parsing
2023-03-23 23:13:42 +00:00
Luca Boccassi d024c4d0e1 Merge pull request #26949 from DaanDeMeyer/xopenat-reopen
loop-util: Add loop_device_make_by_path_at()
2023-03-23 23:08:21 +00:00
Zbigniew Jędrzejewski-Szmek cb38fdbedb coredump: split out parse_auxv() to src/shared/
No functional change. (We already checked for ELFCLASS32 or ELFCLASS64 before,
so even though there's a new check for other architectures, the only caller
only passes ELFCLASS32 or ELFCLASS64.)
2023-03-23 18:04:22 +01:00
Daan De Meyer 972c8db589 loop-util: Add loop_device_make_by_path_at()
On top of taking a directory file descriptor, we use xopenat() so
that the function can also be used to work on existing file
descriptors to image files including all the logic to use O_DIRECT
and fallback to O_RDONLY if needed.
2023-03-23 17:36:17 +01:00
наб ed89819f8f find-esp: don't silently error bootctl install if presumed XBOOTLDR part is stx_dev_major=0 but not btrfs
btrfs_get_block_device_fd() returns -ENOTTY if fstatfs().f_type !=
BTRFS_SUPER_MAGIC

btrfs_get_block_device_fd() is run by verify_fsroot_dir() by
verify_xbootldr() by find_xbootldr_and_warn() if
statx($presumed-XBOOTLDR).stx_dev_major == 0 ("maybe a btrfs device")

Every bootctl verb_install() runs find_xbootldr_and_warn(), by default
with /boot

If your /boot .stx_dev_major=0 but /not/ btrfs, bootctl install/update
quietly exits 1 with no note so as to what exactly failed (debug also
empty, and the strace isn't exactly clear since no syscall actually
failed)

This is the case on ZFS and the Debian filesystem layout: /boot/efi is
the ESP, and everything else under / is ZFS:
  $ sudo env SYSTEMD_LOG_LEVEL=debug bootctl update
  Found cgroup2 on /sys/fs/cgroup/, full unified hierarchy
  Found container virtualization none.
  File system "/boot" is not a FAT EFI System Partition (ESP) file system.
  Using EFI System Partition at /boot/efi.
  Checking whether /boot/efi/EFI/systemd/ contains any files…
  $ echo $?
  1
and funnier still:
  $ sudo bootctl update --graceful
  $ echo $?
  1

Which is great, and also breaks postinst, which runs precisely the
latter, with no feedback at all

By checking for -ENOTTY we accept that the path being investigated
"is not it" if it's on ZFS (and any other filesystem that returns
.stx_dev_major == 0 but isn't btrfs)
2023-03-23 13:35:25 +01:00