mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-17 05:40:13 +01:00
Do not touch new LUKS headers.
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <popt.h>
|
#include <popt.h>
|
||||||
@@ -199,11 +200,13 @@ static int alignment(int fd)
|
|||||||
return alignment;
|
return alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Depends on the first two fields of LUKS1 header format, magic and version */
|
||||||
static int device_check(struct reenc_ctx *rc, header_magic set_magic)
|
static int device_check(struct reenc_ctx *rc, header_magic set_magic)
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int r, devfd;
|
int r, devfd;
|
||||||
ssize_t s;
|
ssize_t s;
|
||||||
|
uint16_t version;
|
||||||
|
|
||||||
devfd = open(rc->device, O_RDWR | O_EXCL | O_DIRECT);
|
devfd = open(rc->device, O_RDWR | O_EXCL | O_DIRECT);
|
||||||
if (devfd == -1) {
|
if (devfd == -1) {
|
||||||
@@ -234,16 +237,21 @@ static int device_check(struct reenc_ctx *rc, header_magic set_magic)
|
|||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set_magic == MAKE_UNUSABLE && !memcmp(buf, MAGIC, MAGIC_L)) {
|
/* Be sure that we do not process new version of header */
|
||||||
|
memcpy((void*)&version, &buf[MAGIC_L], sizeof(uint16_t));
|
||||||
|
version = ntohs(version);
|
||||||
|
|
||||||
|
if (set_magic == MAKE_UNUSABLE && !memcmp(buf, MAGIC, MAGIC_L) &&
|
||||||
|
version == 1) {
|
||||||
log_verbose(_("Marking LUKS device %s unusable.\n"), rc->device);
|
log_verbose(_("Marking LUKS device %s unusable.\n"), rc->device);
|
||||||
memcpy(buf, NOMAGIC, MAGIC_L);
|
memcpy(buf, NOMAGIC, MAGIC_L);
|
||||||
r = 0;
|
r = 0;
|
||||||
|
} else if (set_magic == MAKE_USABLE && !memcmp(buf, NOMAGIC, MAGIC_L) &&
|
||||||
} else if (set_magic == MAKE_USABLE && !memcmp(buf, NOMAGIC, MAGIC_L)) {
|
version == 1) {
|
||||||
log_verbose(_("Marking LUKS device %s usable.\n"), rc->device);
|
log_verbose(_("Marking LUKS device %s usable.\n"), rc->device);
|
||||||
memcpy(buf, MAGIC, MAGIC_L);
|
memcpy(buf, MAGIC, MAGIC_L);
|
||||||
r = 0;
|
r = 0;
|
||||||
} else if (set_magic == CHECK_UNUSABLE) {
|
} else if (set_magic == CHECK_UNUSABLE && version == 1) {
|
||||||
r = memcmp(buf, NOMAGIC, MAGIC_L) ? -EINVAL : 0;
|
r = memcmp(buf, NOMAGIC, MAGIC_L) ? -EINVAL : 0;
|
||||||
if (!r)
|
if (!r)
|
||||||
rc->device_uuid = strndup(&buf[0xa8], 40);
|
rc->device_uuid = strndup(&buf[0xa8], 40);
|
||||||
@@ -551,7 +559,9 @@ static void remove_headers(struct reenc_ctx *rc)
|
|||||||
if (crypt_init(&cd, NULL))
|
if (crypt_init(&cd, NULL))
|
||||||
return;
|
return;
|
||||||
crypt_set_log_callback(cd, _quiet_log, NULL);
|
crypt_set_log_callback(cd, _quiet_log, NULL);
|
||||||
|
if (*rc->header_file_org)
|
||||||
(void)crypt_deactivate(cd, rc->header_file_org);
|
(void)crypt_deactivate(cd, rc->header_file_org);
|
||||||
|
if (*rc->header_file_new)
|
||||||
(void)crypt_deactivate(cd, rc->header_file_new);
|
(void)crypt_deactivate(cd, rc->header_file_new);
|
||||||
crypt_free(cd);
|
crypt_free(cd);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user