Commit Graph

47177 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
320ff93265 journal-remote: use macro wrapper instead of alloca to extend string
We would use alloca to extend the format string with "\n". We do this
automatically in order to not forget appending the newline everywhere.
We can simplify the whole thing by using a macro to append the newline instead,
which means that we don't need to copy the string.

Because we concatenate the string argument with another literal string, we know
it must a literal string. Thus it's not a problem that it is "evaluated" two
times.

Quoting Hristo Venev:
> Since commit f5e757f1ce, mhd_respond() adds a
> newline to its argument before passing it on to mhd_respond_internal(). This
> is done via an alloca()-allocated buffer. However, MHD_RESPMEM_PERSISTENT is
> given as a flag to MHD_create_response_from_buffer(), leading to a
> use-after-free later when the response is sent. Replacing
> MHD_RESPMEM_PERSISTENT with MHD_RESPMEM_MUST_COPY appears to fix the issue.

MHD_RESPMEM_MUST_COPY would work, but we also use mhd_respond() for mhd_oom(),
and we don't want to allocate in an oom scenario in order to maximize the
possibility that an answer will be delivered. Using the macro magic makes this
nicer and we get rid of the code doing alloca.

Fixes an issue reported by Hristo Venev.
Fixes https://github.com/systemd/systemd/issues/9858.
2024-01-15 18:04:23 +01:00
chenjiayi
204594ecf1 udev: distinguish host-managed zoned block in scsi_id
According to SPC4, the value of 0x14 is reserved to distinguish
host managed zoned block, e.g., some SMR (Shingled Magnetic Recording)
disks.

Other utilities such as sg3_utils can successfully recognize such
kind of disks. This patch implements the same ability.
2024-01-12 15:52:38 +00:00
Luca Boccassi
ffcb8647ca Merge pull request #30904 from YHNdnzj/no-selinux-reload
core/execute: don't reload selinux before spawning executor
2024-01-12 15:51:54 +00:00
Yu Watanabe
be89a76a46 network/ndisc: do not try to set too large value for ICMP ratelimting
Follow-up for 6197db53ba.

When we set too large value, the kernel just refuse it. So, this does
not change the net behavior.

Prompted by https://github.com/systemd/systemd/pull/30490#discussion_r1449477125.
2024-01-12 14:38:30 +00:00
Lennart Poettering
f4220d8c05 json: downgrade extension log message to LOG_DEBUG
This is not supposed to be something we should complain about loudly
after all.

Follow-up for: a617fd9047
2024-01-12 14:37:17 +00:00
Daan De Meyer
50cc0ee647 Add --root= support for list and prepare add-all for --root= support
Let's make sure these follow the rest of kernel-install and always
operate on the given root directory, even if the verb itself can't
support --root= just yet.
2024-01-12 14:37:00 +00:00
Mike Yuan
73090a38b0 core/execute: don't reload selinux before spawning executor
With the introduction of sd-executor, SELinux needs to be re-initialized
after execve() anyway.
2024-01-12 17:17:37 +08:00
Mike Yuan
a399804225 selinux-util: reorder functions 2024-01-12 17:17:37 +08:00
Lennart Poettering
64b74c86d0 homed: add helpers for checking reference status of homes
Just some refactoring to make things more readable.
2024-01-12 09:25:17 +09:00
Yu Watanabe
967cd1712c Merge pull request #30867 from dtardon/udev-conf-dropins
Allow dropins for udev.conf
2024-01-12 06:37:23 +09:00
Yu Watanabe
fa552ea1b1 Merge pull request #30893 from yuwata/add-trailing-NUL
json,netlink: add trailing NUL byte when we read binary data
2024-01-12 06:36:46 +09:00
Lennart Poettering
28795e4dca Merge pull request #30777 from poettering/ssh-generator
ssh-generator which makes VMs and containers accessible to ssh via AF_UNIX and AF_VSOCK
2024-01-11 21:31:28 +01:00
Lennart Poettering
25f8d3856a Merge pull request #30884 from poettering/logind-background-light
logind: add "background-light" + "manager" session classes
2024-01-11 21:20:01 +01:00
David Tardon
09dd8e77fc udev: factor out config parser call into function
... which is then called from both places. This makes sure that the
configuration is parsed by udevd and other tools in exactly the same
way.
2024-01-12 05:12:42 +09:00
David Tardon
a1c7dc7d16 udev-util: drop unused function 2024-01-12 05:11:18 +09:00
David Tardon
07f5e35fe7 udev-util: use config. parser to parse udev.conf 2024-01-12 05:11:14 +09:00
David Tardon
343c8514c1 udevd: use config. parser to parse udev.conf
This adds support for the usual config. file hierarchy (including
dropins).

Fixes #30460.
2024-01-12 05:08:18 +09:00
Yu Watanabe
70c24d0d9f sd-netlink: add trailing NUL byte for safety in sd_netlink_message_read_data()
Then, drop sd_netlink_message_read_data_suffix0().
2024-01-12 04:48:26 +09:00
Yu Watanabe
1f179b37f2 json: add trailing NUL byte in json_dispatch_byte_array_iovec()
For safety.

Addresses https://github.com/systemd/systemd/pull/30879#discussion_r1448518226.
2024-01-12 04:44:51 +09:00
Lennart Poettering
68fbd9a09c logind: also restrict on which session classes one cange the session type 2024-01-11 18:24:44 +01:00
Lennart Poettering
87dc8bbd86 logind: allow taking control of devices only in some session types
Let's restrict the logic a bit, so that "manage" session types are not
misused.
2024-01-11 18:24:44 +01:00
Lennart Poettering
a50666e376 id128: add --no-pager, --no-legend, --json=/-j switches to systemd-id128 tool 2024-01-11 17:54:19 +01:00
Lennart Poettering
ad23439eae logind: tighten for which classes of sessions we do stop-on-idle
We only want to do this for fully set up, interactive sessions, i.e.
user and user-early, but not for any others, hence restrict the rules a
bit.

Follow-up for: 508b4786e8
2024-01-11 17:23:48 +01:00
Lennart Poettering
d2a4c37972 logind: rework GC logic
In logind we generally want to stop user@.service for a user once they
log out. So the usual rule is that whenever a User object is around that
has no pinning sessions we should close it.

Except that it isn't that easy. We allow that user@.service is also
manually started, in which case the User object is created but not
pinned by any session.

Let's rework how this is handled: we define two different GC modes. In
one GC mode we'll keep the User object around whenever *any* session
exists (thus: including the user@.service session), and one where we
only keep it around whenever a *pinning* session exists (i.e. when a
user actually logs in, but the user@.service session doesn't count like
that).

And the trick is now that we start out in the *any* GC mode, and switch
to the *pinning* GC mode once the first user session logs in.

This should make things more robust as we know exactly in which state we
are and when to GC a user.
2024-01-11 17:23:48 +01:00
Lennart Poettering
b4f01bc1df logind: rework logic to decide whether lock + idle + display applies to a session
Let's streamline the logic that decides whether the screen lock, idle
timeout or display election mechanism applies to a session class. Let's
add explicitly SESSION_CLASS_IS_XYZ() macros for each, and then resue
them at all suitable places, and refuse any attempts to use the
functionality on the wrong clases with a friendly error message.
2024-01-11 17:23:47 +01:00
Lennart Poettering
b5100c736f logind: add "background-light" session class
This is the same as the "background" class, but does *not* pull in a
service manager. It might be useful for things like select cron jobs
that do not intend to call per-user IPC calls.

Replaces: #23569
Fixes: #23978
2024-01-11 17:23:47 +01:00
Lennart Poettering
4cb4e6cf6d pam_systemd: register systemd user service manager as class='manager'
Now that we have thew new class, start making us of it in pam_systemd.so
when running for user@.service.
2024-01-11 17:23:47 +01:00
Lennart Poettering
5099a50d43 logind: track user service managers as 'manager' session class
Previously, all user code was part of a session except for the code run
as part of user@.service, which wasn't. This tries to make this more
uniform: we'll track the user@.service runtime also as a session, but of
the special type "manager".

This means we have a really good overview finally of all user code that
is running and can make decisions on what to start when and how long to
keep it around. The pam_systemd client side will now be reasonably
uniform: it just calls the CreateSession() bus call with the right
class, and we'll return any data it needs. This means the weird
"side-channel" we previously used to initialize XDG_RUNTIME_DIR for the
user@.service goes away (see next commit).

This conditionalizes various behaviours now cleanly depending on the
session class:

1. SESSION_CLASS_WANTS_SCOPE() will be true for all classes except for
   the manager class. It declares whther the client shall be migrated
   into their own scope, which we generally want for sessions but not
   for the manager, since it already has its own service unit.

2. SESSION_CLASS_WANTS_SERVICE_MANAGER() will be true for all classes
   except for the manager class. It declares whether we shall start the
   service manager if a session of this class is around. Of course, this
   is off for the service manager, since this would always pin itself.

3. SESSION_CLASS_PIN_USER() will be true for all classes except for the
   manager class. It declares whether the we shall keep the User
   structure around for a user as long as the session is around.

Now you might wonder why have these as three functions, even though they
mostly give the same answers?

That's because this all is preparation to add further session classes
later that will return different answers for the three calls. (For
example, a later patch adds "background-light" which will return true
for SESSION_CLASS_WANTS_SCOPE() and SESSION_CLASS_PIN_USER(), but false
for SESSION_CLASS_WANTS_SERVICE_MANAGER(). i.e. it will get a scope, and
pin user tracking, but not start a service manager.
2024-01-11 17:23:47 +01:00
Lennart Poettering
613fb4b601 nspawn: expose a dir in the container where it can bind AF_UNIX sockets that will appear on the host 2024-01-11 16:05:20 +01:00
Lennart Poettering
0abd510f7f ssh-proxy: add ssh ProxyCommand tool that can connect to AF_UNIX + AF_VSOCK sockets
This adds a tiny binary that is hooked into SSH client config via
ProxyCommand and which simply connects to an AF_UNIX or AF_VSOCK socket
of choice.

The syntax is as simple as this:

     ssh unix/some/path     # (this connects to AF_UNIX socket /some/path)

or:

     ssh vsock/4711

I used "/" as separator of the protocol ID and the value since ":" is
already taken by SSH itself when doing sftp. And "@" is already taken
for separating the user name.
2024-01-11 16:05:20 +01:00
Lennart Poettering
0e3220684c ssh-generator: add simple new generator 2024-01-11 16:05:20 +01:00
Lennart Poettering
045f7b8fe4 iovec-util: add helper for a single NUL byte iovec 2024-01-11 16:05:20 +01:00
Lennart Poettering
e09c255d2e install: optionally return discovered unit file path in unit_file_exists() 2024-01-11 16:05:20 +01:00
Lennart Poettering
3392079e4b generator: teach generator_add_symlink_full() to optionally make alias symlinks rather than just .wants/ style symlinks 2024-01-11 16:05:20 +01:00
Lennart Poettering
7ceb76b63c generator: optionally return resulting unit file path in generator_open_unit_file_full()
This is useful if we want to make symlinks to it later.
2024-01-11 16:05:20 +01:00
Antonio Alvarez Feijoo
5e16328506 analyze: clarify that security --offline=true requires an argument
Without `--root` or `--image`, the `security` command inspects all currently
loaded service units if no unit name is specified. But with `--root` or
`--image` with `--offline=true`, the `security` command exits silently if no
unit name is specified.

Also, fixed description of `--root` and `--image` in the man page, and added
missing `--unit` option to help text.
2024-01-11 12:19:20 +00:00
Yu Watanabe
0705e05c3d sd-dhcp-client-id: introduce json_dispatch_client_id() 2024-01-11 17:03:25 +09:00
Yu Watanabe
72278e62d9 json: introduce json_dispatch_byte_array_iovec() and json_dispatch_in_addr() 2024-01-11 17:03:25 +09:00
Yu Watanabe
cf9b425749 sd-dhcp-client-id/duid: do not trigger assertion when invalid size is passed
The data may be from user input or file. We usually use assertion for
programming error. Hence, using assert is not a good choise there.

Preparation for later commits.
2024-01-11 17:03:25 +09:00
Rose
ed0cf4171f boot/efi: use Header field of hd directly instead of casting to EFI_DEVICE_PATH
The header of EFI_DEVICE_PATH is the first member of hd, which means that we can use that directly instead of casting one struct to another.
2024-01-11 14:03:13 +09:00
Rose
aa9ff6c28d tree-wide: replace string functions with fundamental functions 2024-01-11 13:36:25 +09:00
David Tardon
5656cdfeea conf-parser: generalize config_parse_config_file() 2024-01-11 13:24:32 +09:00
Luca Boccassi
d6b39152a9 Merge pull request #30717 from yuwata/network-ref-unref
network: introduce address_ref() and friends
2024-01-10 19:34:48 +00:00
Luca Boccassi
3df2b718b2 Merge pull request #30716 from yuwata/network-cancel-request
network: also remove configuration on cancelling request
2024-01-10 19:33:16 +00:00
Carlos Garnacho
501d8b8bc6 logind: Mark LidClosed property as "emits change"
It may be useful for DEs to follow changes on this property, esp. now that
recent UPower has removed its own lid handling code.

Related: 07565ef6a1
2024-01-10 19:31:06 +00:00
Luca Boccassi
09263532b6 Merge pull request #30720 from yuwata/dhcp-server-address-verification
dhcp-server: several fixlets for address verification
2024-01-10 19:29:25 +00:00
Luca Boccassi
311f80cee2 Merge pull request #30764 from yuwata/network-queue-fix-assertion
network/queue: exit from loop of processing request when a new request is queued
2024-01-10 19:27:57 +00:00
Luca Boccassi
31056154dd Merge pull request #30811 from yuwata/network-route-metric
network/route-metric: introduce RouteMetric to unify route metric handling
2024-01-10 19:25:52 +00:00
Luca Boccassi
dadd7d46d9 Merge pull request #30809 from yuwata/resolve-fix-EDE-handling
resolve: fix EDE handling
2024-01-10 19:21:55 +00:00
Holger Assmann
f681046ede watchdog: ensure configured timeout is used instead of USEC_INFINITY
In some rare cases, a watchdog driver might neither be able to change
the watchdog timeout value, nor read it from the hardware at runtime.

With an otherwise functional watchdog setup, this constellation worked
until systemd v249. Since then, systemd ends up ignoring the timeout
defined by the system.conf and rather uses USEC_INFINITY. Consequently,
the watchdog is not pinged anymore and eventually resets the system.

We therefore want to ensure that the system keeps running with the
originally configured timeout.
2024-01-10 19:14:38 +00:00