summaryrefslogtreecommitdiffstats
path: root/lib/libdevmapper.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 08:35:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 08:35:41 +0000
commitf7458043ae6a2d2d54b911fac52e50341646bef2 (patch)
tree6c58e084cd8728490fd5bb8eead07db0be0038f4 /lib/libdevmapper.c
parentAdding upstream version 2:2.6.1. (diff)
downloadcryptsetup-f7458043ae6a2d2d54b911fac52e50341646bef2.tar.xz
cryptsetup-f7458043ae6a2d2d54b911fac52e50341646bef2.zip
Adding upstream version 2:2.7.0.upstream/2%2.7.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/libdevmapper.c')
-rw-r--r--lib/libdevmapper.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/lib/libdevmapper.c b/lib/libdevmapper.c
index 9c5fc0c..ebee542 100644
--- a/lib/libdevmapper.c
+++ b/lib/libdevmapper.c
@@ -3,8 +3,8 @@
*
* Copyright (C) 2004 Jana Saout <jana@saout.de>
* Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
- * Copyright (C) 2009-2023 Red Hat, Inc. All rights reserved.
- * Copyright (C) 2009-2023 Milan Broz
+ * Copyright (C) 2009-2024 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2009-2024 Milan Broz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -602,7 +602,8 @@ static char *get_dm_crypt_params(const struct dm_target *tgt, uint32_t flags)
hexkey = crypt_safe_alloc(keystr_len);
if (!hexkey)
goto out;
- r = snprintf(hexkey, keystr_len, ":%zu:logon:%s", tgt->u.crypt.vk->keylength, tgt->u.crypt.vk->key_description);
+ r = snprintf(hexkey, keystr_len, ":%zu:logon:%s", tgt->u.crypt.vk->keylength,
+ tgt->u.crypt.vk->key_description);
if (r < 0 || r >= keystr_len)
goto out;
} else
@@ -1330,7 +1331,15 @@ static int _dm_create_device(struct crypt_device *cd, const char *name, const ch
goto out;
if (!dm_task_run(dmt)) {
- r = dm_status_device(cd, name);;
+
+ r = -dm_task_get_errno(dmt);
+ if (r == -ENOKEY || r == -EKEYREVOKED || r == -EKEYEXPIRED) {
+ /* propagate DM errors around key management as such */
+ r = -ENOKEY;
+ goto out;
+ }
+
+ r = dm_status_device(cd, name);
if (r >= 0)
r = -EEXIST;
if (r != -EEXIST && r != -ENODEV)
@@ -1663,6 +1672,11 @@ int dm_create_device(struct crypt_device *cd, const char *name,
log_err(cd, _("Requested sector_size option is not supported."));
r = -EINVAL;
}
+ if (dmd->segment.u.crypt.sector_size > SECTOR_SIZE &&
+ dmd->size % dmd->segment.u.crypt.sector_size) {
+ log_err(cd, _("The device size is not multiple of the requested sector size."));
+ r = -EINVAL;
+ }
}
if (dmd->segment.type == DM_INTEGRITY && (dmd->flags & CRYPT_ACTIVATE_RECALCULATE) &&
@@ -2829,7 +2843,7 @@ static int _process_deps(struct crypt_device *cd, const char *prefix, struct dm_
int dm_device_deps(struct crypt_device *cd, const char *name, const char *prefix,
char **names, size_t names_length)
{
- struct dm_task *dmt;
+ struct dm_task *dmt = NULL;
struct dm_info dmi;
struct dm_deps *deps;
int r = -EINVAL;
@@ -2989,7 +3003,8 @@ int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
}
if (vk->key_description) {
- r = snprintf(msg, msg_size, "key set :%zu:logon:%s", vk->keylength, vk->key_description);
+ r = snprintf(msg, msg_size, "key set :%zu:logon:%s", vk->keylength,
+ vk->key_description);
} else {
key = crypt_bytes_to_hex(vk->keylength, vk->key);
if (!key) {
@@ -3026,6 +3041,18 @@ const char *dm_get_dir(void)
return dm_dir();
}
+int dm_get_iname(const char *name, char **iname, bool with_path)
+{
+ int r;
+
+ if (with_path)
+ r = asprintf(iname, "%s/%s_dif", dm_get_dir(), name);
+ else
+ r = asprintf(iname, "%s_dif", name);
+
+ return r < 0 ? -ENOMEM : 0;
+}
+
int dm_is_dm_device(int major)
{
return dm_is_dm_major((uint32_t)major);