Print a warning if system encryption is used and device is a partition.

System encryption hav metadata in space located ouside of
partition itself.

Ideally the check should be automatic but for virtualized systems
(where a partition could be "whole device" for another sustem this
can be dangerous.
This commit is contained in:
Milan Broz
2013-06-23 15:26:45 +02:00
parent a36de633d5
commit 42b0ab437a
3 changed files with 33 additions and 6 deletions

View File

@@ -565,7 +565,7 @@ int TCRYPT_read_phdr(struct crypt_device *cd,
{
struct device *device = crypt_metadata_device(cd);
ssize_t hdr_size = sizeof(struct tcrypt_phdr);
int devfd = 0, r, bs;
int devfd = 0, r, bs, partition;
assert(sizeof(struct tcrypt_phdr) == 512);
@@ -585,8 +585,15 @@ int TCRYPT_read_phdr(struct crypt_device *cd,
r = -EIO;
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER) {
if (lseek(devfd, TCRYPT_HDR_SYSTEM_OFFSET, SEEK_SET) >= 0 &&
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size)
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size) {
r = TCRYPT_init_hdr(cd, hdr, params);
if (r == -EPERM &&
crypt_sysfs_get_partition(device_path(device), &partition) &&
partition)
log_std(cd, _("WARNING: device %s is a partition, for TCRYPT "
"system encryption you usually need to use "
"whole block device path.\n"), device_path(device));
}
} else if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER) {
if (params->flags & CRYPT_TCRYPT_BACKUP_HEADER) {
if (lseek(devfd, TCRYPT_HDR_HIDDEN_OFFSET_BCK, SEEK_END) >= 0 &&