Commit Graph
2223 Commits
Author SHA1 Message Date
Yu Watanabe f9b3b99017 udev: rename various validate() -> should_reload() for builtin commands
Previously, true by validate() means several configs are outdated and we
need to reload configs. That's not intuitive for me. Let's rename the
functions.
2022-08-17 21:56:46 +09:00
Yu Watanabe 628998ecfa udev/cdrom_id: check last track info
Fixes off-by-one issue.

Fixes #24306.
2022-08-15 12:56:26 +02:00
Yu Watanabe 9d9bc6fc57 Merge pull request #24285 from yuwata/sd-device-new-from-path
sd-device: make sd_device_new_from_path() support symlink outside of /sys
2022-08-13 03:27:26 +09:00
Yu Watanabe 829bb61fb8 udev: use sd_device_new_from_path() and _new_child()
Follow-up for 65c2ad985a.
2022-08-12 21:48:13 +09:00
Yu Watanabe f714ecd450 udev: set description for device monitor 2022-08-12 21:27:14 +09:00
Richard Phibel ead3a3fc87 config-parser: Add list of drop-in files as return argument of config_parse_many
This will be used to save the list of drop-in files for each partition
2022-08-12 12:48:29 +02:00
Sean Anderson 65c2ad985a udev: net_id: Use devicetree aliases when available
Devicetree firmware contains an "aliases" node, containing various
aliases for devices described by the firmware. For ethernet devices,
these are named "ethernet0", "ethernet1", etc. They provide a convenient
means of numbering ethernet devices, especially on systems with no other
stable number other than the address. In particular, U-Boot already uses
these aliases to name its ethernet devices.

Previously, there have been attempts (such as [1]) to add support for
these aliases to Linux. However, these patches have been rejected
because it is the maintainers' view that naming policy be left to
userspace. Well, systemd is userspace, so here we are.

In terms of implementation, apparently there can be multiple device
trees at once. I have decided to dodge this problem for now, and just
use /proc/device-tree. If it is desired to support multiple device trees
later, then the scheme can be modified to include the device tree's
index. For example, /sys/firmware/devicetree/base2/aliases/ethernet3
might be named enb2d3.

For the moment we only support "ethernetX" aliases. Future patches might
want to also handle "canX" and "wifiX".

It is common on boards with only one ethernet device to use an alias of
just "ethernet". In this case, the index is an implicit 0. In case the
author of the firmware made a mistake, we check to ensure that aliases
of "ethernet" and "ethernet0" do not both exist.

[1] https://patchwork.kernel.org/project/linux-arm-kernel/patch/1399390594-1409-1-git-send-email-boris.brezillon@free-electrons.com/

Closes: #17625
2022-08-12 11:15:16 +02:00
Yu Watanabe 59611eb9b8 udev: ignore empty SR-IOV VF suffix
It should not happen. Just for safety.
2022-08-05 21:49:27 +09:00
Yu Watanabe 68a52f5973 sd-device: introduce sd_device_new_child() 2022-08-05 21:49:23 +09:00
Daan De Meyer 26aa4800f8 blockdev-util: Introduce fd_get_whole_disk()
Extracted from find_devno() in udevadm-lock.c.
2022-08-03 20:55:00 +02:00
Yu Watanabe 009b2c3ac1 udev-builtin: logs when needs reloading 2022-07-23 15:05:22 +09:00
Yu Watanabe e9d1fae3bb udev: reload rules and builtins only when mtime of a config changed
This makes udevd reload rules only when the timestamp is updated,
even on SIGHUP or `udevadm control --reload`.
So, we can call `udevadm control --reload` without huge performance
penalty when no rules, .link files, and so on are changed.
2022-07-23 15:05:22 +09:00
Yu Watanabe acfbd71ccc udev: save stats of all udev rules file
The mtime of directory is not updated when an existing rule file is
changed. Hence, paths_check_timestamp() is not reliable.
2022-07-23 15:05:22 +09:00
Yu Watanabe 3f4dfd9d87 conf-parser: add a boolean flag for config_get_stats_by_path() to control if drop-in configs are checked
Preparation for later commits.
2022-07-23 15:03:48 +09:00
Yu Watanabe d7bddfa109 udev: delay to start queued events on udevadm control --start-exec-queue 2022-07-23 14:08:40 +09:00
Yu Watanabe 8e543eb86a udev: use event_reset_time_relative() 2022-07-23 14:08:40 +09:00
Yu Watanabe 6e40ed5325 udev: downgrade error level and mention that the error is ignored 2022-07-23 14:08:40 +09:00
Yu Watanabe 298316ebdf udev: fix error check 2022-07-23 14:08:40 +09:00
Andrey Albershteyn 704116c976 udev: enable BLKID_SUBLKS_FSINFO tags
libblkid gained new tags - FSSIZE, FSLASTBLOCK and FSBLOCKSIZE.
These tags are filesystem related properties probed from superblock.
All of them are enabled by BLKID_SUBLKS_FSINFO flag.

Set the flag to allow these tags to be cached in udev db.
2022-07-22 22:08:47 +02:00
Lennart Poettering 4f80cfca5e pid1: add mechanism for conditionalizing units/network/netdev/link based on credentials passed in
This is useful when provisioning systems via nspawn/qemu and running
specific services only if specific data is passed into the system.
2022-07-15 10:53:45 +02:00
Lennart Poettering 03bc11d1c4 mac: rework labelling code to be simpler, and less racy
This merges the various labelling calls into a single label_fix_full(),
which can operate on paths, on inode fds, and in a dirfd/fname style
(i.e. like openat()). It also systematically separates the path to look
up in the db from the path we actually use to reference the inode to
relabel.

This then ports tmpfiles over to labelling by fd. This should make the
code a bit less racy, as we'll try hard to always operate on the very
same inode, pinning it via an fd.

User-visibly the behaviour should not change.
2022-07-08 17:43:49 +02:00
Yu Watanabe 917c6bb4b3 Merge pull request #23916 from keszybz/assorted-patches
Assorted patches
2022-07-06 14:15:50 +09:00
Zbigniew Jędrzejewski-Szmek 891fc28b45 tree-wide: drop duplicated semicolons 2022-07-05 21:49:12 +02:00
Lennart Poettering a87af99ef1 Merge pull request #23855 from keszybz/drop-list-is-empty
basic/list: drop LIST_IS_EMPTY
2022-07-05 17:29:53 +02:00
Lennart Poettering ff25d3385d tree-wide: add global ascii_isdigit() + ascii_isalpha()
We now have a local implementation in string-util-fundamental.c, but
it's useful at a lot of other places, hence let's give it a more
expressive name and share it across the tree.

Follow-up for: 8d9156660d
2022-07-05 14:25:07 +02:00
Zbigniew Jędrzejewski-Szmek 025f1279c7 Merge pull request #23088 from yuwata/udev-event-blocker
udev: cleanups for event blocker
2022-07-02 17:08:45 +02:00
Zbigniew Jędrzejewski-Szmek d5fe7f7fb1 udev: rename field
When we start, the contents of the variable match the name. But then
in the loop, the variable doesn't point at the old head any more. So let's
rename it to something with a plural.
2022-07-02 12:46:19 +02:00
Zbigniew Jędrzejewski-Szmek 64903d18df basic/list: drop LIST_IS_EMPTY
This was a trivial wrapper that didn't provide any added value. With more
complicated structures like strvs, hashmaps, sets, and arrays, it is possible
to have an empty container. But in case of a list, the list is empty only when
the head is missing.

Also, we generally want the positive condition, so we replace many
if (!LIST_IS_EMPTY(x)) with just if (x).
2022-07-02 12:46:16 +02:00
Yu Watanabe d5548eb618 Merge pull request #23821 from dtardon/ascii-logging
Allow ASCII fallback for Unicode characters in logs
2022-06-29 03:36:35 +09:00
David Tardon 28e5e1e97f tree-wide: allow ASCII fallback for … in logs 2022-06-28 12:50:44 +02:00
David Tardon e2341b6bc3 tree-wide: allow ASCII fallback for → in logs 2022-06-28 12:50:43 +02:00
Yu Watanabe c3613ee51e udev: allow to execute longer command line
Fixes #23607.
2022-06-24 20:09:24 +09:00
Zbigniew Jędrzejewski-Szmek a7b2aa658f Merge pull request #23806 from keszybz/udevadm-info-pager
Pager for udevadm info
2022-06-22 16:50:53 +02:00
Zbigniew Jędrzejewski-Szmek cbef829f80 udevadm info: use pager for all output types
Before we used the pager for --tree, but not e.g. for --export-db.
I don't see any particular reason to limit this.
2022-06-22 14:31:43 +02:00
Zbigniew Jędrzejewski-Szmek b6ec23a01a udevadm info: implement --no-pager 2022-06-22 14:31:42 +02:00
Philipp Gortan 2751ad9c3f add program name to log line 2022-06-18 10:43:03 +09:00
Michael Biebl 5fb225615b meson: install libsystemd-shared into rootpkglibdir
Introduce rootpkglibdir for installing libsystemd-{shared,core}.so.
The benefit over using rootlibexecdir is that this path can be
multiarch aware, i.e. this path can be architecture qualified.

This is something we'd like to make use of in Debian/Ubuntu to make
libsystemd-shared co-installable, e.g. for i386 the path would be
/usr/lib/i386-linux-gnu/systemd/libsystemd-shared-*.so and for amd64
/usr/lib/x86_64-linux-gnu/systemd/libsystemd-shared-*.so.
This will allow for example to install and run systemd-boot/i386 on an
amd64 host. It also simplifies/enables cross-building/bootstrapping.

For more infos about Multi-Arch see https://wiki.debian.org/Multiarch.

See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=990547
2022-06-07 10:04:43 +02:00
Jason A. Donenfeld 87cb1ab676 Simplify random number selection
We currently have a convoluted and complex selection of which random
numbers to use. We can simplify this down to two functions that cover
all of our use cases:

1) Randomness for crypto: this one needs to wait until the RNG is
   initialized. So it uses getrandom(0). If that's not available, it
   polls on /dev/random, and then reads from /dev/urandom. This function
   returns whether or not it was successful, as before.

2) Randomness for other things: this one uses getrandom(GRND_INSECURE).
   If it's not available it uses getrandom(GRND_NONBLOCK). And if that
   would block, then it falls back to /dev/urandom. And if /dev/urandom
   isn't available, it uses the fallback code. It never fails and
   doesn't return a value.

These two cases match all the uses of randomness inside of systemd.

I would prefer to make both of these return void, and get rid of the
fallback code, and simply assert in the incredibly unlikely case that
/dev/urandom doesn't exist. But Luca disagrees, so this commit attempts
to instead keep case (1) returning a return value, which all the callers
already check, and fix the fallback code in (2) to be less bad than
before.

For the less bad fallback code for (2), we now use auxval and some
timestamps, together with various counters representing the invocation,
hash it all together and provide the output. Provided that AT_RANDOM is
secure, this construction is probably okay too, though notably it
doesn't have any forward secrecy. Fortunately, it's only used by
random_bytes() and not by crypto_random_bytes().
2022-05-31 09:20:52 +02:00
Nick Rosbrook beff73f94e hwdb: implement --root option for systemd-hwdb query
Currently, the systemd-hwdb --root flag only has an effect for the
'update' verb. It would be useful to be able to use the --root option
for the 'query' verb too (e.g. for testing a hwdb.bin created with
systemd-hwdb update --root <path>).

Use sd_hwdb_new_from_path to initialize the hwdb if --root is passed to
systemd-hwdb query.

Note that this functionality was not added to 'udevadm hwdb' since that
command is deprecated.
2022-05-27 09:40:54 -04:00
Tomasz Pala d1df0466d9 udev: fixed config_parse_ifalias() logic not to skip setting IFLA_IFALIAS
this flaw was introduced in 6a74900002
2022-05-19 05:04:26 +09:00
Yu Watanabe 618b3642e1 tree-wide: replace AF_LOCAL with AF_UNIX 2022-05-14 10:51:05 +01:00
Zbigniew Jędrzejewski-Szmek c4f883b78e fuzzers: ignore size limits when compiled standalone
This way we can still call fuzzers on old samples, but oss-fuzz will not waste
its and our time finding overly large inputs.
2022-05-12 14:57:07 +02:00
Yu WatanabeandZbigniew Jędrzejewski-Szmek 7593691aad fuzzers: add input size limits, always configure limits in two ways
Without the size limits, oss-fuzz creates huge samples that time out. Usually
this is because some of our code has bad algorithmic complexity. For data like
configuration samples we don't need to care about this: non-rogue configs are
rarely more than a few items, and a bit of a slowdown with a few hundred items
is acceptable. This wouldn't be OK for processing of untrusted data though.

We need to set the limit in two ways: through .options and in the code. The
first because it nicely allows libFuzzer to avoid wasting time, and the second
because fuzzers like hongfuzz and afl don't support .options.

While at it, let's fix an off-by-one (65535 is the largest offset for a
power-of-two size, but we're checking the size here).

Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2022-05-12 13:31:11 +02:00
Zbigniew Jędrzejewski-Szmek 92663a5e5b tree-wide: use LOG_MESSAGE() where possible
Also break some long lines for more uniform formatting. No functional change.

I went over all log_struct, log_struct_errno, log_unit_struct,
log_unit_struct_errno calls, and they seem fine.
2022-05-11 16:47:40 +02:00
Yu Watanabe eba782d59b udev: fix parent token handling
This fixes a bug introduced by 03677889f0.

Fixes #23288.
2022-05-07 02:51:21 +09:00
Yu Watanabe 34458dbbe7 udev: also make uevent blocked by events for the same device node
Even if the device node is the same, devnum (thus, device ID) and
syspath may be different. If a 'remove' and 'add' events for the same
device node but with different devnum and syspath are queued,
previously, we might process them in parallel. And, udev_watch_end() for
the 'remove' event and udev_watch_begin() for the 'add' event may
interfere each other.
2022-05-04 17:16:23 +09:00
Yu Watanabe a1af9668ec udev: make newer event also blocked by DEVPATH_OLD
Previously, a device has DEVPATH_OLD is blocked by a previous event
whose devpath is equivalent to the DEVPATH_OLD.

This extends the condtion.

1. an event has DEVPATH_OLD is blocked by a previous event whose
   devpath is a parent of, child of, or equivalent to the DEVPATH_OLD.

2. an event is blocked by a previous event whose DEVPATH_OLD is a
   parent of, child of, or equivalent to the devpath of the new event.

I am not sure such check is really necessary. But, the cost of the check
is expected to be extremely small, as device renaming does not occur so
frequently. Hence, it should not introduce any significant performance
regression.
2022-05-04 17:16:14 +09:00
Yu Watanabe 29d0245832 udev: use device ID to find blockers
If two devices have the same devnum and subsystem (more specifically,
if the device is block or not), or have the same ifindex, then IDs of
these devices are equivalent.
Hence, the previous conditions are covered by comparing device IDs.

Of course, events with a same ID should be already blocked by the
devpath check. So, this should not change anything.

However, udevd saves many kinds of data under /run/udev named with
the device ID. If multiple workers processes events for the same device
ID, then the database may become corrupted.

Let's explicitly check the device IDs for safety and simplicity.
2022-05-04 16:41:16 +09:00
Yu Watanabe bdb2d3c688 udev: check stats of .link files and their drop-in files
Fixes #23128.
2022-05-03 10:26:22 +02:00
Yu Watanabe b1aca4da60 udevadm: wait: check if specified path not exist on --remove
Even if the corresponding device node or syspath are already removed,
the specified symlink to the device node may still exist.

Fixes #23166.
2022-04-23 08:45:01 +09:00