Commit Graph

47826 Commits

Author SHA1 Message Date
Adrian Vovk
d0aef638ac keyring-util: Use reported key size to resize buf
According to keyctl(2), the return value for KEYCTL_READ is:

    The amount of data that is available in the key,
    irrespective of the provided buffer size

So, we could pass in a NULL buffer to query the size, then allocate the
exact right amount of space, then call keyctl again to get the key data.
However, we must still keep the for loop to avoid TOCTOU issues: the key
might have been replaced with something bigger while we're busy
allocating the buffer to store it.

Thus, we can actually save a syscall by picking some reasonable default
buffer size and skipping the NULL call to keyctl. If our default is big
enough, we're done and have saved a syscall! If not, then the first call
behaves essentially the same as the NULL call, and we use the size it
returns to reallocate the buffer appropriately.
2024-02-15 11:13:34 +00:00
Benjamin Franzke
614d09a37d nspawn: add support for owneridmap bind option
owneridmap bind option will map the target directory owner from inside the
container to the owner of the directory bound from the host filesystem.
This will ensure files and directories created in the container will be owned
by the directory owner of the host filesystem. All other users will remain
unmapped. Files to be written as other users in the container will not be
allowed.

Resolves: #27037
2024-02-15 11:49:54 +01:00
Yu Watanabe
4dcfdd210c log: reorder arguments of internal macro
To make the order matches with log_internal().

No functional change. Hopefully silence coverity issues like
CID#1534478, CID#1534479, CID#1534480, CID#1534482.
2024-02-15 18:16:33 +09:00
Adrian Vovk
058a84d113 homed: Pass in username and uid as Polkit details
This lets the Javascript polkit policies to decide whether to
allow/deny/authenticate based on the user that's being operated on.
2024-02-15 09:12:37 +01:00
Yu Watanabe
8c3f988880 vmspawn: fix alignment of merged initrd
Follow-up for 811ad9e6b2.

Fixes CID#1534481.
2024-02-15 09:11:55 +01:00
Daan De Meyer
9a07df3bcd Merge pull request #31330 from yuwata/sd-journal-trivial-cleanups
sd-journal: trivial cleanups
2024-02-15 08:56:56 +01:00
Yu Watanabe
0984c3d021 copy: rebreak comment and fix typo 2024-02-15 10:19:02 +09:00
Yu Watanabe
a9c2e0f426 sd-journal: fix potential memory leak
Though, hopefully, the memory leak is hypothetical, as we always close
journal file with the timer by journal_file_offline_close().
2024-02-15 09:50:18 +09:00
Yu Watanabe
da96afcd6c journal-file-util: drop unused template argument for journal_file_open_reliably()
I understand that the original motivation to introduce the template
argument here is to make journal_file_open() and _reliabrly() take the
same arguments. But, yeah, that's completely unused, not necessary to
complicate the code even the difference is not big.
2024-02-15 09:50:18 +09:00
Yu Watanabe
36c6b26c37 sd-journal: use -EBADF for journal_file_open() 2024-02-15 09:50:18 +09:00
Yu Watanabe
3f6c529cde sd-journal: shorten code a bit 2024-02-15 09:50:18 +09:00
Yu Watanabe
d5ff4b6d4c Merge pull request #31173 from yuwata/network-route-check-conflict
network/route: check if existing route can be updated
2024-02-15 08:12:42 +09:00
Yu Watanabe
4931b8e471 login: fix typo
Follow-up for 6e9bf0ad29.
2024-02-15 05:38:47 +09:00
Luca Boccassi
76995e7dc4 Merge pull request #31286 from poettering/bootctl-varlink
bootctl: add simple varlink IPC interface
2024-02-14 18:59:33 +00:00
Mike Yuan
3725766266 systemctl: don't warn unit needs reload if --no-warn 2024-02-15 00:37:19 +08:00
Matt Muggeridge
b15ed2be2f network/ndisc: also set sysctl hop_limit value
Otherwise, the hop limit set to the routes may not be used in some
situations.

Fixes #28437.

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2024-02-15 00:43:12 +09:00
Yu Watanabe
972f1d17ab network/ndisc: remove conflicting routes on configuring routes based on newly received RA
The linux kernel does not update several parameters, e.g. RTA_PREF.
Hence, when we configure routes based on a RA, we need to remove
existing conflicting routes.

Fixes #28426 and #28439.
2024-02-15 00:43:12 +09:00
Yu Watanabe
7027cdbd79 network/route: remove existing route if some property conflict with requested ones
Fixes #28853.
2024-02-15 00:43:12 +09:00
Yu Watanabe
e09b758876 network: rename link_drop_managed_xyz() -> link_drop_static_xyz()
As networkd does not configure nexthops, neighbors, or routing policy rules
dynamically, this only changes link_drop_managed_addresses(). Previously
it also removed dynamic addresses, but with this commit, now it only
removes static addresses. Note, link_drop_managed_routes() has removed
only static routes, so this commit only changes its name.

Note. as commented in the code, the dynamic addresses will be removed
on lease expiration or stopping client, and link_drop_managed_xyz() are
called on reconfiguration or so, and at that time, all dynamic
addressing clients are stopped or restarted, so this should not
effective behavior change.
2024-02-15 00:43:12 +09:00
Yu Watanabe
a86763c70b network/ndisc: also drop SLAAC addresses and routes on reconfiguring
Especially, this is important for routes, as link_drop_managed_routes()
removes only static routes, rather than non-foreign routes.
2024-02-15 00:43:12 +09:00
Lennart Poettering
79ec39958d bootctl: add a Varlink interface
For now, just super basic functionality: return the list of boot menu
entries, and read/write the reboot to firmware flag
2024-02-14 16:15:19 +01:00
Lennart Poettering
f892954ba2 bootspec: split out helper that turns BootEntry into a JSON object
We can use that later for returning the boot loader entry list as JSON
via Varlink.
2024-02-14 16:12:43 +01:00
Lennart Poettering
2cda44c23e efi-loader: make efi_loader_get_entries() handling missing NUL termination gracefully
Our function so far assumed that the LoaderEntries's last string is or
is not NUL terminated. But if it was, then we'd debug log about this,
claiming there was an invalid id. sd-boot actually ends the list in a
properly NUL-terminated string, hence we should just accept that. Handle
that case gracefully, and add comments explaining why we have two ways
why we exit the loop.

This is cosmetic only, just suppresses a misleading debug log message.
2024-02-14 15:35:52 +01:00
Lennart Poettering
5c29111337 pam_systemd_home: make sure we handle RefUnit() returning HomeBusy properly
RefUnit() only succeeds it a home dir is fully up. We already dealt with
it not being up at all, but let's also cover the case where it is
currently busy with changing state, and in that case fall back to
RefUnrestricted(), with the usual implications.

This has the effect that two subsequent ssh logins one-after-the-other
will work correctly.
2024-02-14 15:08:55 +01:00
Lennart Poettering
5fb7b15133 homed: generate fallback data in user record, for inactive homes 2024-02-14 15:07:11 +01:00
Lennart Poettering
2518230d33 pam_systemd_home: in ssh logins and similar, ask via fallback shall for home password
ssh runs PAM session hooks before they allocate a pty for the session.
(That's because they allow multiplexed connections, and hence might run
multiple ptys over the same same session). This means PAM modules cannot
interactively ask the user for additional information as they deem fit.
That's a problem for us, since generally during an SSH login no
authentication token (aka "password") is supplied to us which we could
use to unlock the user's home dir.

With this commit we implement a way out: we allow the login to proceed,
but without the home dir activated, and then override the user's shell
with our fallback shell, which will ask for the user's password and then
chainload the actual shell.

This will of course only work if the login actually involves invoking
the configured interactive shell of the user. For other logins (such as
sftp or so), this cannot work, and they'll see an empty home dir
instead.
2024-02-14 15:06:20 +01:00
Lennart Poettering
49493a7478 homectl: implement fallback shell stub 2024-02-14 15:05:18 +01:00
Lennart Poettering
336b1f1936 homed: add a ActivateHomeIfReferenced() bus call
This is very similar to ActivateHome() but will fail if the home
directory is not referenced yet. Or in other words, this doesn't add any
new reference, but simply is the other side of RefUnrestricted(): if we
allowed a home dir to be referenced without it actually being active,
then this can catch up with things and activated what was previously
referenced already.

This also relaxes access rights to that users can always activate their
own home dirs. This is useful once we allow user code to run without the
home dir being activated.
2024-02-14 15:04:15 +01:00
Lennart Poettering
508d344e0e homed: add bus call that allows referencing a home without activating it
This is useful for allowing users to login without the ability to unlock
their home dir. Usecase is ssh: ssh might grant access without giving
us the chance to unlock the home dir for the user (because it doesn't
allow us asking questions during authentication), hence with this call
we can pin the home dir, but not activate it and then allow the
activation to be delayed until later.
2024-02-14 15:03:23 +01:00
Lennart Poettering
2f4aa81440 user-record-show: show if fallback data is used 2024-02-14 15:02:31 +01:00
Lennart Poettering
46c60f7216 user-record: add fields for a fallback home dir + shell
This adds fields to the user record logic to allow a "fallback" home
directory and shell to be set as part of the "status" section of the
user record, i.e. supplied by the manager of the user record.

The idea is that if the fallback homedir/shell is set it will take
precedence over the real one in most ways.

Usecase: let's try to make ssh logins into homed directories work.
systemd-homed would set a fallback shell/homedir for inactive home dirs.
Thus, when ssh logins take place via key auth, we can allow them, and
these fallback session params would be used because the real home cannot
be activated just yet becasue we cannot acquire any password for it from
the user.
2024-02-14 15:01:38 +01:00
Lennart Poettering
6e9bf0ad29 logind: add ability to upgrade session class from 'user-incomplete' to 'user' 2024-02-14 15:00:46 +01:00
Lennart Poettering
249067d178 pam-systemd: automatically enable "incomplete" user session if XDG_SESSION_INCOMPLETE env var is set
This allows earlier PAM modules (i.e. pam_systemd_home) to inform
pam_systemd that the session is not "complete" yet (i.e. doesn't have
the home dir set up properly yet).
2024-02-14 14:59:53 +01:00
Lennart Poettering
53ebde6db4 logind: add new 'user-incomplete' session class 2024-02-14 14:58:37 +01:00
Luca Boccassi
37c6c2035e Merge pull request #28761 from esposem/cmdline_manager
bootctl: handle UKI cmdline addons
2024-02-14 13:56:31 +00:00
Luca Boccassi
25d80c2203 Merge pull request #31283 from CodethinkLabs/vmspawn/start_from_template
vmspawn: Support being invoked from a template unit
2024-02-14 13:55:04 +00:00
Lennart Poettering
63091fa38c Merge pull request #31319 from poettering/journal-tighten-memfd-flags
journald: tighten checks on incoming memfds a bit
2024-02-14 14:40:46 +01:00
Yu Watanabe
489326e25b Merge pull request #31314 from yuwata/network-ndisc-check-conflicting-address
network/ndisc: check conflicting address
2024-02-14 22:19:05 +09:00
Lennart Poettering
296de3867c journald: rebreak some comments 2024-02-14 11:00:18 +01:00
Lennart Poettering
1f47e27a29 journald: when getting journal data via memfd, check flags are valid
Add some extra safety checks: refuse weird open flags.

And while we are at it, also use stat_verify_regular()
2024-02-14 11:00:08 +01:00
Emanuele Giuseppe Esposito
01fd84111f bootctl: discover and pring global UKI PE addons
An UKI final command line is not just made of the content of .cmdline,
but also from the addons that are inserted in
/boot/efi/EFI/Linux/<UKI_NAME>.efi.extra.d (local addons) and /boot/efi/loader/addons
(global addons).

Therefore bootclt "status" and "list" should also include these addons
when printing the UKI command line.

Support for /boot/efi/EFI/Linux/<UKI_NAME>.efi.extra.d is already present,
so now cover addons present in /boot/efi/loader/addons (global addons).

Example (assume UKI_NAME=devel):
$ bootctl
ukiCmdline: console=tty0 console=ttyS0
  globalAddon: loader/addons/global.addon.efi
      cmdline: └─quiet
   localAddon: devel.efi.extra.d/rpm_addon.addon.efi
      cmdline: └─this is a normal addon
 finalCmdline: console=tty0 console=ttyS0 quiet this is a normal addon
2024-02-14 04:58:28 -05:00
Emanuele Giuseppe Esposito
122650b4a0 bootctl: discover local UKI PE addons
An UKI final command line is not just made of the content of .cmdline,
but also from the addons that are inserted in
/boot/efi/EFI/Linux/<UKI_NAME>.efi.extra.d (local addons) and
/boot/efi/loader/addons (global addons).

Therefore bootclt "status" and "list" should also include these addons
when printing the UKI command line.

Right now, discover addons present in
/boot/efi/EFI/Linux/<UKI_NAME>.efi.extra.d.

Example output (assume UKI_NAME=devel):
$ bootctl
ukiCmdline: console=tty0 console=ttyS0
   localAddon: devel.efi.extra.d/rpm_addon.addon.efi
      cmdline: └─this is a normal addon
 finalCmdline: console=tty0 console=ttyS0 this is a normal addon
2024-02-14 04:58:20 -05:00
Emanuele Giuseppe Esposito
ebd1a30093 bootspec: refactor find_sections
Prepare for the incoming changes that introduce PE addons support.
Addons will contain a .cmdline section, but not .osrel.
2024-02-14 04:56:42 -05:00
Adrian Vovk
c425c8854f hashmap: Add helper to dump sorted keys
Currently, hashmap_dump_sorted sorts by key and then returns the values
in order sorted by key. This commit adds another helper that does the
same but returns the sorted keys instead
2024-02-14 09:35:36 +01:00
Yu Watanabe
d1cde7f051 sd-journal: drop unused function prototype
Follow-up for 8b4fbbb0a1.

The function was renamed and moved by
035b0f8fe8.
Maybe the prototype is mistakenly re-introduced on rebase.
2024-02-14 09:31:13 +01:00
Mike Yuan
872ffc8a82 core/load-fragment: modernize config_parse_socket_listen
Prompted by #31304
2024-02-14 09:23:07 +01:00
Lennart Poettering
64e18af731 Merge pull request #31206 from AdrianVovk/user-record-fields
Added some more user record fields
2024-02-14 09:22:23 +01:00
Adrian Vovk
83b4576195 env-util: Add helper to store current log level
This is useful after a fork but before an exec into a binary that uses
systemd's logging utilities. For example, this should be used in dbus
services that fork off worker processes: currently, the log level set by
the LogControl dbus API will be lost because of the exec, and the worker
process will not have the correct log level set.
2024-02-14 09:21:45 +01:00
Lennart Poettering
2fe27f966f Merge pull request #31297 from AdrianVovk/sha256-util-lib
basic: Add some sha256 helper functions
2024-02-14 09:19:56 +01:00
Yu Watanabe
8bd473ff25 core: allow to specify /dev/rfkill for ListenSpecial=
Follow-up for 8049bce619.

Fixes #31294.
2024-02-14 09:14:59 +01:00