History:
- Before 331aa7aa15, a symlink creation
requested by a new event replaced an existing symlink with the same
priority.
- With 331aa7aa15 (v254), if an existing symlink
has the same priority with the newly requested one, then the new request
was skipped, and the existing symlink was kept. But this caused #28141.
- With 7ec5ce5673 (v255, and backported to v254.6),
the behavior is restored prior to the 331aa7aa15.
But, it is pointed out that the replacing symlink may be dangerous.
See discussion in https://github.com/systemd/systemd/pull/34482#issuecomment-2362115374.
This introduce .UDEV_REPLACE_SYMLINK_WITH_SAME_PRIORITY flag, and set the flag
for dm devices. Why? We need to consider several points:
- On boot time, devices appear in random order. So, if e.g. sda and sdb
requests the same symlink, then there are no way to guarantee which
device will own the symlink, as these devices will be processed by
udevd in parallel. Since, there are no guarantee, we can change the
logic which device will win to own the symlink, that is, the first
wins (with this PR) or the last wins (the current behavior).
- After the system is booted, e.g. when a USB stick (sdb) is inserted and
it requests a symlink which is currently owned by sda. In that case,
the current behavior makes the new device (sdb) steal the ownership of
the symlink. But, that may be problematic as a user or a program may
assume that the symlink is persistent, and data may be lost or stolen.
We can easily create such hackish USB stick by creating a partition
which has the same partition UUID on the stick.
With this commit, new devices cannot override the ownership of the symlink,
so such the issue will not be triggered anymore.
- As you can see the change in the test code for integrity in this commit,
this commit is also important for dm-integrity. Without this PR, the data
partition and the DM devices both request the same partition UUID symlink,
and the data device gained the ownership, as a synthetic event for the
underlying data device is triggered after the DM device is activated,
and it steels the ownership from the DM device. People may mistakenly
mounts the underlying data device rather than the DM device, and may causes
data loss or corruption. With this PR, the underlying device will not
gain the symlink, and blkid command always returns the DM device.
- Unfortunately, this re-introduce issue #28468, which is triggered for
spurious ISO images. But, it can be easily avoided by reapplying the
'workaround' done by df1dccd255.
Fixes#31448.
Replaces #34482, #33572, #32981.