mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-19 14:50:09 +01:00
Remove json_object argument from area size checks.
These functions are internal to LUKS2 implementation.
This commit is contained in:
@@ -178,10 +178,9 @@ int LUKS2_hdr_restore(struct crypt_device *cd,
|
|||||||
struct luks2_hdr *hdr,
|
struct luks2_hdr *hdr,
|
||||||
const char *backup_file);
|
const char *backup_file);
|
||||||
|
|
||||||
/* FIXME: json object remove */
|
uint64_t LUKS2_hdr_and_areas_size(struct luks2_hdr *hdr);
|
||||||
uint64_t LUKS2_hdr_and_areas_size(struct json_object *jobj);
|
uint64_t LUKS2_keyslots_size(struct luks2_hdr *hdr);
|
||||||
uint64_t LUKS2_keyslots_size(struct json_object *jobj);
|
uint64_t LUKS2_metadata_size(struct luks2_hdr *hdr);
|
||||||
uint64_t LUKS2_metadata_size(struct json_object *jobj);
|
|
||||||
|
|
||||||
int LUKS2_keyslot_cipher_incompatible(struct crypt_device *cd, const char *cipher_spec);
|
int LUKS2_keyslot_cipher_incompatible(struct crypt_device *cd, const char *cipher_spec);
|
||||||
|
|
||||||
|
|||||||
@@ -413,7 +413,7 @@ int LUKS2_disk_hdr_write(struct crypt_device *cd, struct luks2_hdr *hdr, struct
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = device_check_size(cd, crypt_metadata_device(cd), LUKS2_hdr_and_areas_size(hdr->jobj), 1);
|
r = device_check_size(cd, crypt_metadata_device(cd), LUKS2_hdr_and_areas_size(hdr), 1);
|
||||||
if (r)
|
if (r)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@@ -669,9 +669,9 @@ int LUKS2_disk_hdr_read(struct crypt_device *cd, struct luks2_hdr *hdr,
|
|||||||
|
|
||||||
/* check header with keyslots to fit the device */
|
/* check header with keyslots to fit the device */
|
||||||
if (state_hdr1 == HDR_OK)
|
if (state_hdr1 == HDR_OK)
|
||||||
hdr_size = LUKS2_hdr_and_areas_size(jobj_hdr1);
|
hdr_size = LUKS2_hdr_and_areas_size_jobj(jobj_hdr1);
|
||||||
else if (state_hdr2 == HDR_OK)
|
else if (state_hdr2 == HDR_OK)
|
||||||
hdr_size = LUKS2_hdr_and_areas_size(jobj_hdr2);
|
hdr_size = LUKS2_hdr_and_areas_size_jobj(jobj_hdr2);
|
||||||
else {
|
else {
|
||||||
r = (state_hdr1 == HDR_FAIL_IO && state_hdr2 == HDR_FAIL_IO) ? -EIO : -EINVAL;
|
r = (state_hdr1 == HDR_FAIL_IO && state_hdr2 == HDR_FAIL_IO) ? -EIO : -EINVAL;
|
||||||
goto err;
|
goto err;
|
||||||
|
|||||||
@@ -186,6 +186,8 @@ int LUKS2_find_area_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
|||||||
int LUKS2_find_area_max_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
int LUKS2_find_area_max_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||||
uint64_t *area_offset, uint64_t *area_length);
|
uint64_t *area_offset, uint64_t *area_length);
|
||||||
|
|
||||||
|
uint64_t LUKS2_hdr_and_areas_size_jobj(json_object *jobj);
|
||||||
|
|
||||||
int LUKS2_check_cipher(struct crypt_device *cd,
|
int LUKS2_check_cipher(struct crypt_device *cd,
|
||||||
size_t keylength,
|
size_t keylength,
|
||||||
const char *cipher,
|
const char *cipher,
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ static size_t get_min_offset(struct luks2_hdr *hdr)
|
|||||||
|
|
||||||
static size_t get_max_offset(struct luks2_hdr *hdr)
|
static size_t get_max_offset(struct luks2_hdr *hdr)
|
||||||
{
|
{
|
||||||
return LUKS2_hdr_and_areas_size(hdr->jobj);
|
return LUKS2_hdr_and_areas_size(hdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LUKS2_find_area_max_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
int LUKS2_find_area_max_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||||
@@ -371,7 +371,7 @@ int LUKS2_wipe_header_areas(struct crypt_device *cd,
|
|||||||
/* Wipe keyslot area */
|
/* Wipe keyslot area */
|
||||||
wipe_block = 1024 * 1024;
|
wipe_block = 1024 * 1024;
|
||||||
offset = get_min_offset(hdr);
|
offset = get_min_offset(hdr);
|
||||||
length = LUKS2_keyslots_size(hdr->jobj);
|
length = LUKS2_keyslots_size(hdr);
|
||||||
|
|
||||||
log_dbg(cd, "Wiping keyslots area (0x%06" PRIx64 " - 0x%06" PRIx64") with random data.",
|
log_dbg(cd, "Wiping keyslots area (0x%06" PRIx64 " - 0x%06" PRIx64") with random data.",
|
||||||
offset, length + offset);
|
offset, length + offset);
|
||||||
|
|||||||
@@ -720,7 +720,7 @@ static int hdr_validate_segments(struct crypt_device *cd, json_object *hdr_jobj)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t LUKS2_metadata_size(json_object *jobj)
|
static uint64_t LUKS2_metadata_size_jobj(json_object *jobj)
|
||||||
{
|
{
|
||||||
json_object *jobj1, *jobj2;
|
json_object *jobj1, *jobj2;
|
||||||
uint64_t json_size;
|
uint64_t json_size;
|
||||||
@@ -732,6 +732,11 @@ uint64_t LUKS2_metadata_size(json_object *jobj)
|
|||||||
return json_size + LUKS2_HDR_BIN_LEN;
|
return json_size + LUKS2_HDR_BIN_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t LUKS2_metadata_size(struct luks2_hdr *hdr)
|
||||||
|
{
|
||||||
|
return LUKS2_metadata_size_jobj(hdr->jobj);
|
||||||
|
}
|
||||||
|
|
||||||
static int hdr_validate_areas(struct crypt_device *cd, json_object *hdr_jobj)
|
static int hdr_validate_areas(struct crypt_device *cd, json_object *hdr_jobj)
|
||||||
{
|
{
|
||||||
struct interval *intervals;
|
struct interval *intervals;
|
||||||
@@ -747,7 +752,7 @@ static int hdr_validate_areas(struct crypt_device *cd, json_object *hdr_jobj)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* config is already validated */
|
/* config is already validated */
|
||||||
metadata_size = LUKS2_metadata_size(hdr_jobj);
|
metadata_size = LUKS2_metadata_size_jobj(hdr_jobj);
|
||||||
|
|
||||||
length = json_object_object_length(jobj_keyslots);
|
length = json_object_object_length(jobj_keyslots);
|
||||||
|
|
||||||
@@ -793,7 +798,7 @@ static int hdr_validate_areas(struct crypt_device *cd, json_object *hdr_jobj)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = validate_intervals(cd, length, intervals, metadata_size, LUKS2_hdr_and_areas_size(hdr_jobj)) ? 0 : 1;
|
ret = validate_intervals(cd, length, intervals, metadata_size, LUKS2_hdr_and_areas_size_jobj(hdr_jobj)) ? 0 : 1;
|
||||||
|
|
||||||
free(intervals);
|
free(intervals);
|
||||||
|
|
||||||
@@ -1041,7 +1046,7 @@ void LUKS2_hdr_free(struct crypt_device *cd, struct luks2_hdr *hdr)
|
|||||||
log_dbg(cd, "LUKS2 header still in use");
|
log_dbg(cd, "LUKS2 header still in use");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t LUKS2_keyslots_size(json_object *jobj)
|
static uint64_t LUKS2_keyslots_size_jobj(json_object *jobj)
|
||||||
{
|
{
|
||||||
json_object *jobj1, *jobj2;
|
json_object *jobj1, *jobj2;
|
||||||
uint64_t keyslots_size;
|
uint64_t keyslots_size;
|
||||||
@@ -1053,9 +1058,19 @@ uint64_t LUKS2_keyslots_size(json_object *jobj)
|
|||||||
return keyslots_size;
|
return keyslots_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t LUKS2_hdr_and_areas_size(json_object *jobj)
|
uint64_t LUKS2_keyslots_size(struct luks2_hdr *hdr)
|
||||||
{
|
{
|
||||||
return 2 * LUKS2_metadata_size(jobj) + LUKS2_keyslots_size(jobj);
|
return LUKS2_keyslots_size_jobj(hdr->jobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t LUKS2_hdr_and_areas_size_jobj(json_object *jobj)
|
||||||
|
{
|
||||||
|
return 2 * LUKS2_metadata_size_jobj(jobj) + LUKS2_keyslots_size_jobj(jobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t LUKS2_hdr_and_areas_size(struct luks2_hdr *hdr)
|
||||||
|
{
|
||||||
|
return LUKS2_hdr_and_areas_size_jobj(hdr->jobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LUKS2_hdr_backup(struct crypt_device *cd, struct luks2_hdr *hdr,
|
int LUKS2_hdr_backup(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||||
@@ -1067,7 +1082,7 @@ int LUKS2_hdr_backup(struct crypt_device *cd, struct luks2_hdr *hdr,
|
|||||||
ssize_t ret, buffer_size;
|
ssize_t ret, buffer_size;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
|
|
||||||
hdr_size = LUKS2_hdr_and_areas_size(hdr->jobj);
|
hdr_size = LUKS2_hdr_and_areas_size(hdr);
|
||||||
buffer_size = size_round_up(hdr_size, crypt_getpagesize());
|
buffer_size = size_round_up(hdr_size, crypt_getpagesize());
|
||||||
|
|
||||||
buffer = crypt_safe_alloc(buffer_size);
|
buffer = crypt_safe_alloc(buffer_size);
|
||||||
@@ -1178,7 +1193,7 @@ int LUKS2_hdr_restore(struct crypt_device *cd, struct luks2_hdr *hdr,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_size = LUKS2_hdr_and_areas_size(hdr_file.jobj);
|
buffer_size = LUKS2_hdr_and_areas_size(&hdr_file);
|
||||||
buffer = crypt_safe_alloc(buffer_size);
|
buffer = crypt_safe_alloc(buffer_size);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
r = -ENOMEM;
|
r = -ENOMEM;
|
||||||
@@ -1218,7 +1233,7 @@ int LUKS2_hdr_restore(struct crypt_device *cd, struct luks2_hdr *hdr,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
/* FIXME: what could go wrong? Erase if we're fine with consequences */
|
/* FIXME: what could go wrong? Erase if we're fine with consequences */
|
||||||
if (buffer_size != (ssize_t) LUKS2_hdr_and_areas_size(tmp_hdr.jobj)) {
|
if (buffer_size != (ssize_t) LUKS2_hdr_and_areas_size(&tmp_hdr)) {
|
||||||
log_err(cd, _("Binary header with keyslot areas size differ on device and backup, restore failed."));
|
log_err(cd, _("Binary header with keyslot areas size differ on device and backup, restore failed."));
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -1714,8 +1729,8 @@ int LUKS2_hdr_dump(struct crypt_device *cd, struct luks2_hdr *hdr)
|
|||||||
log_std(cd, "LUKS header information\n");
|
log_std(cd, "LUKS header information\n");
|
||||||
log_std(cd, "Version: \t%u\n", hdr->version);
|
log_std(cd, "Version: \t%u\n", hdr->version);
|
||||||
log_std(cd, "Epoch: \t%" PRIu64 "\n", hdr->seqid);
|
log_std(cd, "Epoch: \t%" PRIu64 "\n", hdr->seqid);
|
||||||
log_std(cd, "Metadata area: \t%" PRIu64 " [bytes]\n", LUKS2_metadata_size(hdr->jobj));
|
log_std(cd, "Metadata area: \t%" PRIu64 " [bytes]\n", LUKS2_metadata_size(hdr));
|
||||||
log_std(cd, "Keyslots area: \t%" PRIu64 " [bytes]\n", LUKS2_keyslots_size(hdr->jobj));
|
log_std(cd, "Keyslots area: \t%" PRIu64 " [bytes]\n", LUKS2_keyslots_size(hdr));
|
||||||
log_std(cd, "UUID: \t%s\n", *hdr->uuid ? hdr->uuid : "(no UUID)");
|
log_std(cd, "UUID: \t%s\n", *hdr->uuid ? hdr->uuid : "(no UUID)");
|
||||||
log_std(cd, "Label: \t%s\n", *hdr->label ? hdr->label : "(no label)");
|
log_std(cd, "Label: \t%s\n", *hdr->label ? hdr->label : "(no label)");
|
||||||
log_std(cd, "Subsystem: \t%s\n", *hdr->subsystem ? hdr->subsystem : "(no subsystem)");
|
log_std(cd, "Subsystem: \t%s\n", *hdr->subsystem ? hdr->subsystem : "(no subsystem)");
|
||||||
|
|||||||
@@ -573,7 +573,7 @@ int LUKS2_luks1_to_luks2(struct crypt_device *cd, struct luks_phdr *hdr1, struct
|
|||||||
* It duplicates check in LUKS2_hdr_write() but we don't want to move
|
* It duplicates check in LUKS2_hdr_write() but we don't want to move
|
||||||
* keyslot areas in case it would fail later
|
* keyslot areas in case it would fail later
|
||||||
*/
|
*/
|
||||||
if (max_size < LUKS2_hdr_and_areas_size(hdr2->jobj)) {
|
if (max_size < LUKS2_hdr_and_areas_size(hdr2)) {
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -595,7 +595,7 @@ int LUKS2_luks1_to_luks2(struct crypt_device *cd, struct luks_phdr *hdr1, struct
|
|||||||
buf_size = luks1_size - LUKS_ALIGN_KEYSLOTS;
|
buf_size = luks1_size - LUKS_ALIGN_KEYSLOTS;
|
||||||
|
|
||||||
/* check future LUKS2 keyslots area is at least as large as LUKS1 keyslots area */
|
/* check future LUKS2 keyslots area is at least as large as LUKS1 keyslots area */
|
||||||
if (buf_size > LUKS2_keyslots_size(hdr2->jobj)) {
|
if (buf_size > LUKS2_keyslots_size(hdr2)) {
|
||||||
log_err(cd, _("Unable to move keyslot area. LUKS2 keyslots area too small."));
|
log_err(cd, _("Unable to move keyslot area. LUKS2 keyslots area too small."));
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -883,7 +883,7 @@ int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct
|
|||||||
|
|
||||||
// move keyslots 32k -> 4k offset
|
// move keyslots 32k -> 4k offset
|
||||||
buf_offset = 2 * LUKS2_HDR_16K_LEN;
|
buf_offset = 2 * LUKS2_HDR_16K_LEN;
|
||||||
buf_size = LUKS2_keyslots_size(hdr2->jobj);
|
buf_size = LUKS2_keyslots_size(hdr2);
|
||||||
r = move_keyslot_areas(cd, buf_offset, 8 * SECTOR_SIZE, buf_size);
|
r = move_keyslot_areas(cd, buf_offset, 8 * SECTOR_SIZE, buf_size);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_err(cd, _("Unable to move keyslot area."));
|
log_err(cd, _("Unable to move keyslot area."));
|
||||||
|
|||||||
14
lib/setup.c
14
lib/setup.c
@@ -1850,13 +1850,13 @@ static int _crypt_format_luks2(struct crypt_device *cd,
|
|||||||
if (dev_size < (crypt_get_data_offset(cd) * SECTOR_SIZE))
|
if (dev_size < (crypt_get_data_offset(cd) * SECTOR_SIZE))
|
||||||
log_std(cd, _("WARNING: Data offset is outside of currently available data device.\n"));
|
log_std(cd, _("WARNING: Data offset is outside of currently available data device.\n"));
|
||||||
|
|
||||||
if (cd->metadata_size && (cd->metadata_size != LUKS2_metadata_size(cd->u.luks2.hdr.jobj)))
|
if (cd->metadata_size && (cd->metadata_size != LUKS2_metadata_size(&cd->u.luks2.hdr)))
|
||||||
log_std(cd, _("WARNING: LUKS2 metadata size changed to %" PRIu64 " bytes.\n"),
|
log_std(cd, _("WARNING: LUKS2 metadata size changed to %" PRIu64 " bytes.\n"),
|
||||||
LUKS2_metadata_size(cd->u.luks2.hdr.jobj));
|
LUKS2_metadata_size(&cd->u.luks2.hdr));
|
||||||
|
|
||||||
if (cd->keyslots_size && (cd->keyslots_size != LUKS2_keyslots_size(cd->u.luks2.hdr.jobj)))
|
if (cd->keyslots_size && (cd->keyslots_size != LUKS2_keyslots_size(&cd->u.luks2.hdr)))
|
||||||
log_std(cd, _("WARNING: LUKS2 keyslots area size changed to %" PRIu64 " bytes.\n"),
|
log_std(cd, _("WARNING: LUKS2 keyslots area size changed to %" PRIu64 " bytes.\n"),
|
||||||
LUKS2_keyslots_size(cd->u.luks2.hdr.jobj));
|
LUKS2_keyslots_size(&cd->u.luks2.hdr));
|
||||||
|
|
||||||
if (!integrity && sector_size > SECTOR_SIZE) {
|
if (!integrity && sector_size > SECTOR_SIZE) {
|
||||||
dev_size -= (crypt_get_data_offset(cd) * SECTOR_SIZE);
|
dev_size -= (crypt_get_data_offset(cd) * SECTOR_SIZE);
|
||||||
@@ -1878,7 +1878,7 @@ static int _crypt_format_luks2(struct crypt_device *cd,
|
|||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_err(cd, _("Cannot wipe header on device %s."),
|
log_err(cd, _("Cannot wipe header on device %s."),
|
||||||
mdata_device_path(cd));
|
mdata_device_path(cd));
|
||||||
if (dev_size < LUKS2_hdr_and_areas_size(cd->u.luks2.hdr.jobj))
|
if (dev_size < LUKS2_hdr_and_areas_size(&cd->u.luks2.hdr))
|
||||||
log_err(cd, _("Device %s is too small."), device_path(crypt_metadata_device(cd)));
|
log_err(cd, _("Device %s is too small."), device_path(crypt_metadata_device(cd)));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -5258,8 +5258,8 @@ int crypt_get_metadata_size(struct crypt_device *cd,
|
|||||||
msize = LUKS_ALIGN_KEYSLOTS;
|
msize = LUKS_ALIGN_KEYSLOTS;
|
||||||
ksize = LUKS_device_sectors(&cd->u.luks1.hdr) * SECTOR_SIZE - msize;
|
ksize = LUKS_device_sectors(&cd->u.luks1.hdr) * SECTOR_SIZE - msize;
|
||||||
} else if (isLUKS2(cd->type)) {
|
} else if (isLUKS2(cd->type)) {
|
||||||
msize = LUKS2_metadata_size(cd->u.luks2.hdr.jobj);
|
msize = LUKS2_metadata_size(&cd->u.luks2.hdr);
|
||||||
ksize = LUKS2_keyslots_size(cd->u.luks2.hdr.jobj);
|
ksize = LUKS2_keyslots_size(&cd->u.luks2.hdr);
|
||||||
} else
|
} else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user