Commit Graph

1666 Commits

Author SHA1 Message Date
Lennart Poettering 56e577c62f tree-wide: use DISABLE_WARNING_FORMAT_NONLITERAL where appropriate 2020-05-25 18:25:05 +02:00
Lidong Zhong 9b3278d907 udev: rename the persistent link for ATA devices
ATA devices should use the ATA ids like port number and (possibly)
master/slave or multiplier id, not the generic SCSI ID.
Currently only port number is included in the link. With this patch
the link would be able to support more cases, which are a) when the
device is behind a port multiplexer b) the distinction between master
and slave (distinguished by target id).

I tried to verify scenario a) with this patch, but I failed to find a
machine with PMP SATA devices attached. But the link below
https://github.com/systemd/systemd/issues/3943
could show what's the difference. Here is my test for scenario b)

Current version:
linux-ql21:~ # ll /sys/class/block/sd[ab]
lrwxrwxrwx 1 root root 0 May  8 20:46 /sys/class/block/sda ->
../../devices/pci0000:00/0000:00:01.1/ata4/host3/target3:0:0/3:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 May  8 20:46 /sys/class/block/sdb ->
../../devices/pci0000:00/0000:00:01.1/ata4/host3/target3:0:1/3:0:1:0/block/sdb
linux-ql21:~ # ll /dev/disk/by-path/pci-0000\:00\:01.1-ata-1
lrwxrwxrwx 1 root root 9 May  8 20:44
/dev/disk/by-path/pci-0000:00:01.1-ata-1 -> ../../sdb
linux-ql21:~ # udevadm info /sys/class/block/sda |grep by-path
S: disk/by-path/pci-0000:00:01.1-ata-1
E: DEVLINKS=/dev/disk/by-id/ata-VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-id/scsi-0ATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-id/scsi-1ATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-path/pci-0000:00:01.1-ata-1
/dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
linux-ql21:~ # udevadm info /sys/class/block/sdb |grep by-path
S: disk/by-path/pci-0000:00:01.1-ata-1
E: DEVLINKS=/dev/disk/by-id/ata-VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-1ATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-0ATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-path/pci-0000:00:01.1-ata-1

After patch applied:
linux-ql21:~ # ll /sys/class/block/sd[ab]
lrwxrwxrwx 1 root root 0 May  8 21:07 /sys/class/block/sda ->
../../devices/pci0000:00/0000:00:01.1/ata4/host3/target3:0:0/3:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 May  8 21:07 /sys/class/block/sdb ->
../../devices/pci0000:00/0000:00:01.1/ata4/host3/target3:0:1/3:0:1:0/block/sdb
linux-ql21:~ # ll /dev/disk/by-path/pci-0000\:00\:01.1-ata-*
lrwxrwxrwx 1 root root  9 May  8 21:07
/dev/disk/by-path/pci-0000:00:01.1-ata-1.0 -> ../../sda
lrwxrwxrwx 1 root root  9 May  8 21:07
/dev/disk/by-path/pci-0000:00:01.1-ata-1.1 -> ../../sdb
linux-ql21:~ # udevadm info /sys/class/block/sda |grep by-path
S: disk/by-path/pci-0000:00:01.1-ata-1.0
E: DEVLINKS=/dev/disk/by-id/scsi-1ATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-id/scsi-0ATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-id/ata-VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-path/pci-0000:00:01.1-ata-1.0
/dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
linux-ql21:~ # udevadm info /sys/class/block/sdb |grep by-path
S: disk/by-path/pci-0000:00:01.1-ata-1.1
E: DEVLINKS=/dev/disk/by-id/scsi-0ATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/ata-VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-1ATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-path/pci-0000:00:01.1-ata-1.1

Changelog:
v5: add another parameter compat_link in handle_scsi()
v4: comment for ID_PATH_ATA_COMPAT
    get string length with pointer difference
    (suggested by Franck Bui<fbui@suse.com>)
v3: creating compatible link from env
    variables type change
v2: remove udev rules modification for compatible link
    setup a test scenario of master/slave ATA devices
v1: initial patch
2020-05-21 09:58:06 +02:00
Lennart Poettering 09835de3cc proc-cmdline: make checking of EFI options variable optional
And do not use it in the IMPORT{cmdline} udev code. Wherever we expose
direct interfaces to check the kernel cmdline, let's not consult our
systemd-specific EFI variable, but strictly use the actual kernel
variable, because that's what we claim we do. i.e. it's fine to use the
EFI variable for our own settings, but for the generic APIs to the
kernel cmdline we should not use it.

Specifically, this applies to IMPORT{cmdline} and
ConditionKernelCommandLine=. In the latter case we weren#t checking the
EFI variable anyway, hence let's do the same for the udev case, too.

Fixes: #15739
2020-05-20 19:22:09 +02:00
Lennart Poettering 550c8784c5 udev: when random MACs are requested, generate them with genuine randomness
This is a security feature, and we thus shouldn't derive the random MACs
from a potentially guessable source. MAC addresses are after all facing
to the outside, and can be interacted with from untrusted environments.
Hence, let's generate them the same way as we generate UUIDs: from
getrandom() or /dev/urandom, and optionally with RDRAND if that's
supported.

RDRAND should be fine, since this is not cryptographic key material, but
ultimately public information. We just want to make sure conflicts are
not likely.

Previously we'd generate the MACs via rand(), which means given the
short seed they are a little bit too guessable, making collisions too
likely. See #14355 in particular.

Fixes: #14355

(Note that #14355 was already fixed by
a0f11d1d11, but I think we should do
better even, and not rely on rand() and uninitialized random pools)
2020-05-20 08:25:18 +02:00
Lennart Poettering 18fbb567a8
Merge pull request #15817 from poettering/more-conditions
Add ConditionEnvironment= and ConditionIsEncrypted=
2020-05-15 20:25:34 +02:00
Lennart Poettering cb1277fa3b udev: get rid of "Could not set flow control of" message on "lo" interface
When setting flow control attributes of an interface we first acquire
the current settings and then add in the new settings before applying
them again. This only works on interfaces that implement the ethtool
ioctls. on others we'll see an ugly "Could not set flow control of"
message, simply because we issue the SIOCETHTOOL ioctl once, for getting
the data. In particular we'll get it for the "lo" interface all the
time, which sucks hard. Let's get rid of it.
2020-05-15 17:58:53 +02:00
Lennart Poettering a0b191b705 condition: add ConditionEnvironment=
Prompted by the discussions in #15180.

This is a bit more complex than I hoped, since for PID 1 we need to pass
in the synethetic environment block in we generate on demand.
2020-05-15 16:05:33 +02:00
Benjamin Robin b9c54c4665 tree-wide: Initialize _cleanup_ variables if needed 2020-05-13 22:56:42 +02:00
Zbigniew Jędrzejewski-Szmek 8acb7780df
Merge pull request #15623 from poettering/cmsg-cleanup
various CMSG_xyz clean-ups, split out of #15571
2020-05-08 11:05:06 +02:00
Lennart Poettering fb29cdbef2 tree-wide: make sure our control buffers are properly aligned
We always need to make them unions with a "struct cmsghdr" in them, so
that things properly aligned. Otherwise we might end up at an unaligned
address and the counting goes all wrong, possibly making the kernel
refuse our buffers.

Also, let's make sure we initialize the control buffers to zero when
sending, but leave them uninitialized when reading.

Both the alignment and the initialization thing is mentioned in the
cmsg(3) man page.
2020-05-07 14:39:44 +02:00
Zbigniew Jędrzejewski-Szmek be32732168 basic/set: let set_put_strdup() create the set with string hash ops
If we're using a set with _put_strdup(), most of the time we want to use
string hash ops on the set, and free the strings when done. This defines
the appropriate a new string_hash_ops_free structure to automatically free
the keys when removing the set, and makes set_put_strdup() and set_put_strdupv()
instantiate the set with those hash ops.

hashmap_put_strdup() was already doing something similar.

(It is OK to instantiate the set earlier, possibly with a different hash ops
structure. set_put_strdup() will then use the existing set. It is also OK
to call set_free_free() instead of set_free() on a set with
string_hash_ops_free, the effect is the same, we're just overriding the
override of the cleanup function.)

No functional change intended.
2020-05-06 16:54:06 +02:00
nabijaczleweli e81f5fc4e8
link: Allow configuring RX mini and jumbo ring sizes, too
This now covers all ethtool_ringparam configurables (as of v5.6;
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/ethtool.h?h=v5.6#n488)
2020-04-29 18:57:13 +02:00
Zbigniew Jędrzejewski-Szmek 11f9379866
Merge pull request #15570 from poettering/cmsg-find
CMSG_FIND_DATA() and cmsg_find() work
2020-04-24 07:45:07 +02:00
Lennart Poettering 08508c4862
Merge pull request #15561 from poettering/udev-memdup-fix
udev: nulstr NUL termination fix
2020-04-23 19:50:12 +02:00
Lennart Poettering 371d72e05b socket-util: introduce type-safe, dereferencing wrapper CMSG_FIND_DATA around cmsg_find()
let's take this once step further, and add type-safety to cmsg_find(),
and imply the CMSG_DATA() macro for finding the cmsg payload.
2020-04-23 19:41:15 +02:00
Lennart Poettering 9663ed378e udev: use STR_IN_SET() wher eit makes sense 2020-04-23 13:56:21 +02:00
Lennart Poettering cd3c8a117c udev: prepare memory for extra NUL termination for NULSTR
Fixes: #15162
2020-04-23 13:56:21 +02:00
Lennart Poettering 3691bcf3c5 tree-wide: use recvmsg_safe() at various places
Let's be extra careful whenever we return from recvmsg() and see
MSG_CTRUNC set. This generally means we ran into a programming error, as
we didn't size the control buffer large enough. It's an error condition
we should at least log about, or propagate up. Hence do that.

This is particularly important when receiving fds, since for those the
control data can be of any size. In particular on stream sockets that's
nasty, because if we miss an fd because of control data truncation we
cannot recover, we might not even realize that we are one off.

(Also, when failing early, if there's any chance the socket might be
AF_UNIX let's close all received fds, all the time. We got this right
most of the time, but there were a few cases missing. God, UNIX is hard
to use)
2020-04-23 09:41:47 +02:00
Zbigniew Jędrzejewski-Szmek 162392b75a tree-wide: spellcheck using codespell
Fixes #15436.
2020-04-16 18:00:40 +02:00
Zbigniew Jędrzejewski-Szmek 38cd55b007 Remove unneded {}s
$ perl -i -0pe 's|\s+{\n([^\n]*;)\n\s+}\n|\n\1\n|gms' **/*.c

Inspired by ea7cbf5bdd.
2020-04-13 09:31:49 +02:00
Lénaïc Huard 61fd7d6720 udev: Fix SIGSEGV in AlternativeNamesPolicy handling
The function sd_device_get_property_value has some paths where it exits without
touching the n pointer. In those cases, n remained uninitialized until it was
eventually read inside isempty where it caused the segmentation fault.

Fixes #15078
2020-04-02 10:18:56 +02:00
Zbigniew Jędrzejewski-Szmek b0c8219260 network: move NETWORK_DIRS to path-lookup.h
In preparation for future changes...
2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek 4908de44b0 {systemd,udev}.pc: add names with underscores, deprecate the old ones
The names with multiple lowercase words run together are hard to read.  We
started that way with very short names like rootprefix, but then same pattern
was applied to longer and longer names. Looking at the body of .pc files
available on my machine, many packages use underscores; let's do the same. Old
names are kept for compatiblity, so this is backwards compatible.
2020-03-27 20:12:44 +01:00
Uwe Kleine-König 7600dbb870 udev: add debug logs for delaying and delegation of events
Up to now each uevent logs the following things at debug level:

 - Device is queued
 - Processing device
 - Device processed

However when the device is queued it might still have to wait for
earlier devices to be processed before being able to start being
processed itself. When analysing logs this dependency information is
quite cruicial, so add respective debug log calls.
2020-03-11 08:44:32 +01:00
Valery0xff 0335d110af
udev: fix SECLABEL{selinux} issue (#15064)
Add SECLABEL{selinux}="some value" cause udevadm crash
systemd-udevd[x]: Worker [x] terminated by signal 11 (SEGV)

It happens since 25de7aa7b9 (Yu Watanabe 2019-04-25 01:21:11 +0200)
when udev rules processing changed to token model. Yu forgot store
attr to SECLABEL token so fix it.
2020-03-11 09:20:36 +09:00
Yu Watanabe a34811e4ef udev: support to update flow control parameter
Closes #14770.
2020-03-07 01:43:26 +09:00
Zbigniew Jędrzejewski-Szmek 105a1a36cd tree-wide: fix spelling of lookup and setup verbs
"set up" and "look up" are the verbs, "setup" and "lookup" are the nouns.
2020-03-03 15:02:53 +01:00
Yu Watanabe ef62949a23 network: make Type=ether match based on iftype
This makes Type= can match the type shown in networkctl.

Closes #14952.
2020-03-02 08:52:18 +01:00
Yu Watanabe df5a4889fe udevadm: show more error message during exporting database
Closes #14959.
2020-02-27 22:27:16 +09:00
Peter Hutterer 3d7ac1c655 udev-builtin-input_id: any i2c mouse is a pointing stick
Where we have a device that looks like a mouse and is connected over i2c, tag
it as pointing stick. There is no such thing as a i2c mouse.

Even touchpads that aren't recognized by the kernel will not show up as i2c
mouse - either the touchpad follows the Win8.1 specs in which case the kernel
switches it to multitouch mode and it shows up like a touchpad. The built-in
trackpoint, if any, is then the i2c mouse device.

Where the touchpad doesn't follow the spec, the kernel will not handle it and
the touchpad remains on the PS/2 legacy bus - not i2c. Hence we can assume
that any i2c mouse device is really a pointing stick.
2020-02-27 19:53:46 +09:00
Ryan Attard 06654d1225
ata_id: Add support for host managed zone block devices (#14933)
If the peripheral device type is that of a host managed zone block device (0x14),
the device supports the same identification mechanisms as conventional disks (0x00).
2020-02-27 16:29:41 +09:00
Yu Watanabe 91e50467f5
Merge pull request #14761 from keszybz/link-network-no-match
Refuse .network and .link files with no matches
2020-02-04 20:26:37 +09:00
Zbigniew Jędrzejewski-Szmek dade734917 network,udev: refuse .link and .network settings with no matches
Two releases ago we started warning about this, and I think it is now to turn
this into a hard error. People get bitten by this every once in a while, and
there doesn't see to be any legitimate use case where the same .link or
.network files should be applied to _all_ interfaces, since in particular that
configuration would apply both to lo and any other interfaces. And if for
whatever reason that is actually desired, OriginalName=* or Name=* can be
easily added to silence the warning and achieve the effect.

(The case described in #12098 is particularly nasty: 'echo -n >foo.network'
creates a mask file, 'echo >foo.network' creates a "match all" file.)

Fixes #717, #12098 for realz now.
2020-02-04 08:45:52 +01:00
Yu Watanabe bf2334c054 udev: add {Receive,Transmit}ChecksumOffload= settings
Closes #14661.
2020-02-03 12:31:31 +09:00
Franck Bui 1ffadeaae3 udev: assume that the recv buffer size of the netlink socket is already configured when the socket is passed in
This makes ReceiveBuffer= option in systemd-udevd-kernel.socket unit useful.
2020-01-28 22:35:08 +01:00
Yu Watanabe 5029912157 network,udev: use uint64_t for bit rate
Fixes #14620.
2020-01-21 16:51:19 +01:00
Lennart Poettering 0aa9bffe10
Merge pull request #14448 from yuwata/network-permanent-mac-address
network, udev: support permanent mac address
2020-01-08 15:36:27 +01:00
Yu Watanabe 4bb7cc8287 network, udev: introduce PermanentMACAddress= setting in [Match] section
Closes #13983.
2020-01-08 17:54:54 +09:00
Lennart Poettering 3ce252d0e0 udev: use dot_or_dot_dot() where appropriate 2020-01-07 18:02:53 +01:00
Yu Watanabe 7a182f1034 udev: do not use exact match of file permission
This partially reverts 25de7aa7b9.

Fixes #14473.
2020-01-07 15:16:52 +01:00
Lennart Poettering b355d0c9af udev: move naming-scheme.[ch] into src/shared/
That way we can use it from non-udev code too, for example nspawn.
2020-01-02 19:34:00 +01:00
Yu Watanabe 4d016e965b udev: sort alternative names
Kernel preserves the order of alternative names. So, for user
visibility, let's sort the alternative names.
2019-12-18 00:05:50 +09:00
Yu Watanabe ef1d2c07f9 udev: introduce AlternativeNamesPolicy= setting 2019-12-17 15:44:43 +09:00
Yu Watanabe bb181dd4a6 udev: do not fail if kernel does not support alternative names 2019-12-17 15:43:50 +09:00
Yu Watanabe 78f8849f84 udev: extend the length of ID_NET_NAME_XXX= to ALTIFNAMSIZ 2019-12-17 11:04:11 +09:00
Yu Watanabe 572b21d96c network: make Name= in [Match] support alternative names of interfaces 2019-12-16 10:55:56 +09:00
Yu Watanabe a5053a158b udev: support AlternativeName= setting in .link file 2019-12-16 10:52:22 +09:00
Lennart Poettering 335498ca57 docs: direct to systemd.io version of naming scheme docs
The document was imported back in
f9e6d49904. Let's make sure we actually
point to that version rather than the old one on freedesktop.
2019-12-11 12:09:02 +01:00
Paul Davey 9f537ae310 udev: Ensure udev_event_spawn reads stdout
When running the program with udev_event_spawn it is possible to miss
output in stdout when the program exits causing the result to be empty
which can cause rules using the result to not function correctly.

This is due to the on_spawn_sigchld callback being processed while IO is
still pending and causing the event loop to exit.

To correct this the sigchld event source is made a lower priority than
the other event sources to ensure it is processed after IO.  This
requires changing the IO event source to oneshot and re-enabling it when
valid data is read but not for EOF, this prevents the empty pipes
constantly generating IO events.
2019-12-04 10:31:37 +01:00
Martin Wilck 030f457167 udevd: don't use monitor after manager_exit()
If udevd receives an exit signal, it releases its reference on the udev
monitor in manager_exit(). If at this time a worker is hanging, and if
the event timeout for this worker expires before udevd exits, udevd
crashes in on_sigchld()->udev_monitor_send_device(), because the monitor
has already been freed.

Fix this by testing the validity of manager->monitor in on_sigchld().
2019-11-26 20:38:28 +01:00