summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2022-04-06 17:25:35 +0100
committerLuca Boccassi <luca.boccassi@gmail.com>2022-04-07 17:31:04 +0100
commitcedf5b1aef4da2443f00eef2c242c8b005071aca (patch)
tree519a992b7d3ad13df2ac98b968238d8829552053
parent1e582ede3b04d12aae11fc5378a446a392054f1c (diff)
downloadsystemd-cedf5b1aef4da2443f00eef2c242c8b005071aca.tar.gz
core: fix dm-verity auto-discovery in MountImageUnit()
The implementation of MountImageUnit()/systemctl mount-image was changed to use a /proc/self/fd path as the source, but that causes the dm-verity files autodiscovery to fail, as it looks for files in the same directory as the image. Use the original file path when setting up dm-verity.
-rw-r--r--src/core/namespace.c2
-rw-r--r--src/shared/dissect-image.c6
-rw-r--r--src/shared/dissect-image.h2
-rw-r--r--src/shared/mount-util.c6
-rwxr-xr-xtest/units/testsuite-50.sh2
5 files changed, 12 insertions, 6 deletions
diff --git a/src/core/namespace.c b/src/core/namespace.c
index 4ede17788b..e6aa7b6473 100644
--- a/src/core/namespace.c
+++ b/src/core/namespace.c
@@ -1216,7 +1216,7 @@ static int mount_image(const MountEntry *m, const char *root_directory) {
}
r = verity_dissect_and_mount(
- mount_entry_source(m), mount_entry_path(m), m->image_options,
+ /* src_fd= */ -1, mount_entry_source(m), mount_entry_path(m), m->image_options,
host_os_release_id, host_os_release_version_id, host_os_release_sysext_level, NULL);
if (r == -ENOENT && m->ignore)
return 0;
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index e63b168c24..6e287ecac7 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -3448,6 +3448,7 @@ static const char *const partition_designator_table[] = {
};
int verity_dissect_and_mount(
+ int src_fd,
const char *src,
const char *dest,
const MountOptions *options,
@@ -3466,14 +3467,17 @@ int verity_dissect_and_mount(
assert(src);
assert(dest);
+ /* We might get an FD for the image, but we use the original path to look for the dm-verity files */
r = verity_settings_load(&verity, src, NULL, NULL);
if (r < 0)
return log_debug_errno(r, "Failed to load root hash: %m");
dissect_image_flags = verity.data_path ? DISSECT_IMAGE_NO_PARTITION_TABLE : 0;
+ /* Note that we don't use loop_device_make here, as the FD is most likely O_PATH which would not be
+ * accepted by LOOP_CONFIGURE, so just let loop_device_make_by_path reopen it as a regular FD. */
r = loop_device_make_by_path(
- src,
+ src_fd >= 0 ? FORMAT_PROC_FD_PATH(src_fd) : src,
-1,
verity.data_path ? 0 : LO_FLAGS_PARTSCAN,
&loop_device);
diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h
index b74adf5f8d..1bc8d2ef9a 100644
--- a/src/shared/dissect-image.h
+++ b/src/shared/dissect-image.h
@@ -285,4 +285,4 @@ bool dissected_image_verity_sig_ready(const DissectedImage *image, PartitionDesi
int mount_image_privately_interactively(const char *path, DissectImageFlags flags, char **ret_directory, LoopDevice **ret_loop_device, DecryptedImage **ret_decrypted_image);
-int verity_dissect_and_mount(const char *src, const char *dest, const MountOptions *options, const char *required_host_os_release_id, const char *required_host_os_release_version_id, const char *required_host_os_release_sysext_level, const char *required_sysext_scope);
+int verity_dissect_and_mount(int src_fd, const char *src, const char *dest, const MountOptions *options, const char *required_host_os_release_id, const char *required_host_os_release_version_id, const char *required_host_os_release_sysext_level, const char *required_sysext_scope);
diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c
index 78f06b25fe..e76e4a0b38 100644
--- a/src/shared/mount-util.c
+++ b/src/shared/mount-util.c
@@ -789,6 +789,7 @@ static int mount_in_namespace(
bool mount_slave_created = false, mount_slave_mounted = false,
mount_tmp_created = false, mount_tmp_mounted = false,
mount_outside_created = false, mount_outside_mounted = false;
+ _cleanup_free_ char *chased_src_path = NULL;
struct stat st, self_mntns_st;
pid_t child;
int r;
@@ -826,9 +827,10 @@ static int mount_in_namespace(
if (r < 0)
return log_debug_errno(r == -ENOENT ? SYNTHETIC_ERRNO(EOPNOTSUPP) : r, "Target does not allow propagation of mount points");
- r = chase_symlinks(src, NULL, CHASE_TRAIL_SLASH, NULL, &chased_src_fd);
+ r = chase_symlinks(src, NULL, 0, &chased_src_path, &chased_src_fd);
if (r < 0)
return log_debug_errno(r, "Failed to resolve source path of %s: %m", src);
+ log_debug("Chased source path of %s to %s", src, chased_src_path);
if (fstat(chased_src_fd, &st) < 0)
return log_debug_errno(errno, "Failed to stat() resolved source path %s: %m", src);
@@ -873,7 +875,7 @@ static int mount_in_namespace(
mount_tmp_created = true;
if (is_image)
- r = verity_dissect_and_mount(FORMAT_PROC_FD_PATH(chased_src_fd), mount_tmp, options, NULL, NULL, NULL, NULL);
+ r = verity_dissect_and_mount(chased_src_fd, chased_src_path, mount_tmp, options, NULL, NULL, NULL, NULL);
else
r = mount_follow_verbose(LOG_DEBUG, FORMAT_PROC_FD_PATH(chased_src_fd), mount_tmp, NULL, MS_BIND, NULL);
if (r < 0)
diff --git a/test/units/testsuite-50.sh b/test/units/testsuite-50.sh
index 6aabbd139c..2f1844ccf7 100755
--- a/test/units/testsuite-50.sh
+++ b/test/units/testsuite-50.sh
@@ -285,7 +285,7 @@ Type=notify
RemainAfterExit=yes
MountAPIVFS=yes
PrivateTmp=yes
-ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER /tmp/img/usr/lib/os-release; do sleep 0.1; done; mount | grep -F "/tmp/img" | grep -q -F "nosuid"'
+ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER /tmp/img/usr/lib/os-release; do sleep 0.1; done; mount | grep -F "/dev/mapper/${roothash}-verity" | grep -q -F "nosuid"'
EOF
systemctl start testservice-50d.service