Skip to content

eBPF-based security platform

image: fail closed on the paths that could not

Daniel Borkmann093628bd9d16
diff --git a/util/dm_verity.c b/util/dm_verity.c
index 958f7700..dce53bed 100644
--- a/util/dm_verity.c
+++ b/util/dm_verity.c
@@ -203,7 +203,8 @@ static int device_path(struct shirudo_dm_verity *device, __u64 dev)
if (lstat(device->path, &st)) {
if (errno != ENOENT)
return -errno;
- if (mknod(device->path, S_IFBLK | 0600, device->device))
+ if (mknod(device->path, S_IFBLK | 0600, device->device) &&
+ errno != EEXIST)
return -errno;
if (lstat(device->path, &st))
return -errno;
diff --git a/util/image_bootstrap.c b/util/image_bootstrap.c
index 4df0692d..a8fcdeb4 100644
--- a/util/image_bootstrap.c
+++ b/util/image_bootstrap.c
@@ -75,20 +75,23 @@ int shirudo_image_bootstrap_read(const char *path,
if (!shirudo_image_path_valid(value) ||
boot->runtime[0])
rc = -EINVAL;
- else
- strscpy(boot->runtime, value, sizeof(boot->runtime));
+ else if (strscpy(boot->runtime, value,
+ sizeof(boot->runtime)) < 0)
+ rc = -ENAMETOOLONG;
} else if (!strcmp(key, "config.image")) {
if (!shirudo_image_path_valid(value))
rc = -EINVAL;
- else
- strscpy(boot->config, value, sizeof(boot->config));
+ else if (strscpy(boot->config, value,
+ sizeof(boot->config)) < 0)
+ rc = -ENAMETOOLONG;
} else if (!strcmp(key, "config.verification_key")) {
if (strncmp(value, SHIRUDO_RUNTIME_DIR "/",
sizeof(SHIRUDO_RUNTIME_DIR)) ||
!shirudo_image_path_valid(value))
rc = -EPERM;
- else
- strscpy(boot->certificate, value, sizeof(boot->certificate));
+ else if (strscpy(boot->certificate, value,
+ sizeof(boot->certificate)) < 0)
+ rc = -ENAMETOOLONG;
} else if (!strcmp(key, "config.pcr")) {
__u64 pcr;
diff --git a/util/image_runtime.c b/util/image_runtime.c
index 0415616f..d7f2413a 100644
--- a/util/image_runtime.c
+++ b/util/image_runtime.c
@@ -376,6 +376,9 @@ static int mount_runtime(bool trusted_boot)
if (!rc) {
step = "load runtime config";
rc = load_runtime_config(trusted_boot);
+ if (rc && umount2(SHIRUDO_RUNTIME_DIR, MNT_DETACH))
+ pr_warn("image: cannot unmount the runtime: %s",
+ strerror(errno));
}
if (rc)
pr_err("image: %s: %s", step, strerror(-rc));