"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/luks2/luks2_disk_metadata.c" between
cryptsetup-2.3.6.tar.xz and cryptsetup-2.4.0.tar.xz

About: cryptsetup is a utility used to conveniently setup disk encryption based on the dm-crypt kernel module. These include plain dm-crypt volumes, LUKS volumes, loop-AES and TrueCrypt compatible format.

luks2_disk_metadata.c  (cryptsetup-2.3.6.tar.xz):luks2_disk_metadata.c  (cryptsetup-2.4.0.tar.xz)
skipping to change at line 304 skipping to change at line 304
const char *json_area, int secondary) const char *json_area, int secondary)
{ {
struct luks2_hdr_disk hdr_disk; struct luks2_hdr_disk hdr_disk;
uint64_t offset = secondary ? hdr->hdr_size : 0; uint64_t offset = secondary ? hdr->hdr_size : 0;
size_t hdr_json_len; size_t hdr_json_len;
int devfd, r; int devfd, r;
log_dbg(cd, "Trying to write LUKS2 header (%zu bytes) at offset %" PRIu64 ".", log_dbg(cd, "Trying to write LUKS2 header (%zu bytes) at offset %" PRIu64 ".",
hdr->hdr_size, offset); hdr->hdr_size, offset);
/* FIXME: read-only device silent fail? */
devfd = device_open_locked(cd, device, O_RDWR); devfd = device_open_locked(cd, device, O_RDWR);
if (devfd < 0) if (devfd < 0)
return devfd == -1 ? -EINVAL : devfd; return devfd == -1 ? -EINVAL : devfd;
hdr_json_len = hdr->hdr_size - LUKS2_HDR_BIN_LEN; hdr_json_len = hdr->hdr_size - LUKS2_HDR_BIN_LEN;
hdr_to_disk(hdr, &hdr_disk, secondary, offset); hdr_to_disk(hdr, &hdr_disk, secondary, offset);
/* /*
* Write header without checksum but with proper seqid. * Write header without checksum but with proper seqid.
skipping to change at line 388 skipping to change at line 386
int LUKS2_device_write_lock(struct crypt_device *cd, struct luks2_hdr *hdr, stru ct device *device) int LUKS2_device_write_lock(struct crypt_device *cd, struct luks2_hdr *hdr, stru ct device *device)
{ {
int r = device_write_lock(cd, device); int r = device_write_lock(cd, device);
if (r < 0) { if (r < 0) {
log_err(cd, _("Failed to acquire write lock on device %s."), devi ce_path(device)); log_err(cd, _("Failed to acquire write lock on device %s."), devi ce_path(device));
return r; return r;
} }
/* run sequence id check only on first write lock (r == 1) and w/o LUKS2 reencryption in-progress */ /* run sequence id check only on first write lock (r == 1) and w/o LUKS2 reencryption in-progress */
if (r == 1 && !crypt_get_reenc_context(cd)) { if (r == 1 && !crypt_get_luks2_reencrypt(cd)) {
log_dbg(cd, "Checking context sequence id matches value stored on disk."); log_dbg(cd, "Checking context sequence id matches value stored on disk.");
if (LUKS2_check_sequence_id(cd, hdr, device)) { if (LUKS2_check_sequence_id(cd, hdr, device)) {
device_write_unlock(cd, device); device_write_unlock(cd, device);
log_err(cd, _("Detected attempt for concurrent LUKS2 meta data update. Aborting operation.")); log_err(cd, _("Detected attempt for concurrent LUKS2 meta data update. Aborting operation."));
return -EINVAL; return -EINVAL;
} }
} }
return 0; return 0;
} }
skipping to change at line 416 skipping to change at line 414
char *json_area; char *json_area;
const char *json_text; const char *json_text;
size_t json_area_len; size_t json_area_len;
int r; int r;
if (hdr->version != 2) { if (hdr->version != 2) {
log_dbg(cd, "Unsupported LUKS2 header version (%u).", hdr->versio n); log_dbg(cd, "Unsupported LUKS2 header version (%u).", hdr->versio n);
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;
/* /*
* Allocate and zero JSON area (of proper header size). * Allocate and zero JSON area (of proper header size).
*/ */
json_area_len = hdr->hdr_size - LUKS2_HDR_BIN_LEN; json_area_len = hdr->hdr_size - LUKS2_HDR_BIN_LEN;
json_area = crypt_zalloc(json_area_len); json_area = crypt_zalloc(json_area_len);
if (!json_area) if (!json_area)
return -ENOMEM; return -ENOMEM;
skipping to change at line 672 skipping to change at line 670
*/ */
if (state_hdr1 == HDR_OK && state_hdr2 == HDR_OK) { if (state_hdr1 == HDR_OK && state_hdr2 == HDR_OK) {
if (be64_to_cpu(hdr_disk1.seqid) > be64_to_cpu(hdr_disk2.seqid)) if (be64_to_cpu(hdr_disk1.seqid) > be64_to_cpu(hdr_disk2.seqid))
state_hdr2 = HDR_OBSOLETE; state_hdr2 = HDR_OBSOLETE;
else if (be64_to_cpu(hdr_disk1.seqid) < be64_to_cpu(hdr_disk2.seq id)) else if (be64_to_cpu(hdr_disk1.seqid) < be64_to_cpu(hdr_disk2.seq id))
state_hdr1 = HDR_OBSOLETE; state_hdr1 = HDR_OBSOLETE;
} }
/* 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) ? -E IO : -EINVAL; r = (state_hdr1 == HDR_FAIL_IO && state_hdr2 == HDR_FAIL_IO) ? -E IO : -EINVAL;
goto err; goto err;
} }
r = device_check_size(cd, device, hdr_size, 0); r = device_check_size(cd, device, hdr_size, 0);
if (r) if (r)
goto err; goto err;
/* /*
skipping to change at line 791 skipping to change at line 789
return 0; return 0;
if (!device) if (!device)
return 0; return 0;
flags = O_RDONLY; flags = O_RDONLY;
if (device_direct_io(device)) if (device_direct_io(device))
flags |= O_DIRECT; flags |= O_DIRECT;
devfd = open(device_path(device), flags); devfd = open(device_path(device), flags);
if (devfd < 0) if (devfd != -1 && (read_lseek_blockwise(devfd, device_block_size(cd, dev
goto err; ice),
if ((read_lseek_blockwise(devfd, device_block_size(cd, device),
device_alignment(device), &hdr, sizeof(hdr), 0) == sizeof(hdr)) && device_alignment(device), &hdr, sizeof(hdr), 0) == sizeof(hdr)) &&
!memcmp(hdr.magic, LUKS2_MAGIC_1ST, LUKS2_MAGIC_L)) !memcmp(hdr.magic, LUKS2_MAGIC_1ST, LUKS2_MAGIC_L))
r = (int)be16_to_cpu(hdr.version); r = (int)be16_to_cpu(hdr.version);
err:
if (devfd != -1) if (devfd != -1)
close(devfd); close(devfd);
if (backup_file) if (backup_file)
device_free(cd, device); device_free(cd, device);
return r; return r;
} }
 End of changes. 7 change blocks. 
11 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)