core: deduplicate identical dm-verity ExtensionImages=
authorLuca Boccassi <bluca@debian.org>
Tue, 4 Jun 2024 15:00:03 +0000 (16:00 +0100)
committerLuca Boccassi <bluca@debian.org>
Fri, 28 Jun 2024 13:37:58 +0000 (14:37 +0100)
commita1a40297dbfa5bcd926d1a19320deb73c033c6f5
tree5170b3d7b0c134d68ea823604fc5b18028ab0b80
parentb268a71069786a45460807967e669d505ba3c5a2
core: deduplicate identical dm-verity ExtensionImages=

It turns out OverlayFS doesn't handle gracefully when the same source is
specified multiple times in lowerdir= and it fails with ELOOP:

Failed to mount overlay (type overlay) on /run/systemd/mount-rootfs/opt (MS_RDONLY "lowerdir=/run/systemd/unit-extensions/1/opt:/run/systemd/unit-extensions/0/opt:/run/systemd/mount-rootfs/opt"): Too many levels of symbolic links

This happens even if we mount each image in a different internal mount
path, as OverlayFS will resolve it and look for the backing device, which
will be the same device mapper entity, and return a hard error.
This error does not appear if dm-verity is not used, so it is very
confusing for users, and unnecessary.

When mounting ExtensionImages, check if an image is dm-veritied,
and drop duplicates if the root hashes match, to avoid this user-unfriendly
hard error.
src/core/namespace.c
src/shared/dissect-image.c
src/shared/dissect-image.h
src/shared/mount-util.c
test/TEST-50-DISSECT/test.sh
test/units/TEST-50-DISSECT.dissect.sh