From: Victor Westerhuis Date: Wed, 24 Jul 2024 15:31:04 +0000 (+0200) Subject: libblkid: bitlocker: use volume identifier as UUID X-Git-Tag: v2.42-start~254 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6edc0013e2d5424916019cdc4597787c5d569a52;p=thirdparty%2Futil-linux.git libblkid: bitlocker: use volume identifier as UUID --- diff --git a/libblkid/src/superblocks/bitlocker.c b/libblkid/src/superblocks/bitlocker.c index 170a67605..e68c2b230 100644 --- a/libblkid/src/superblocks/bitlocker.c +++ b/libblkid/src/superblocks/bitlocker.c @@ -38,11 +38,25 @@ struct bde_header_togo { } __attribute__((packed)); -struct bde_fve_metadata { +struct bde_fve_metadata_block_header { /* 0 */ unsigned char signature[8]; -/* 8 */ uint16_t size; +/* 8 */ unsigned char __dummy1[10 - 8]; /* 10 */ uint16_t version; -}; +/* 12 */ unsigned char __dummy2[64 - 12]; +} __attribute__((packed)); + +struct bde_fve_metadata_header { +/* 0 */ uint32_t size; +/* 4 */ uint32_t version; +/* 8 */ uint32_t header_size; +/* 12 */ uint32_t size_copy; +/* 16 */ unsigned char volume_identifier[16]; +} __attribute__((packed)); + +struct bde_fve_metadata { + struct bde_fve_metadata_block_header block_header; + struct bde_fve_metadata_header header; +} __attribute__((packed)); enum { BDE_VERSION_VISTA = 0, @@ -124,7 +138,7 @@ static int get_bitlocker_headers(blkid_probe pr, return errno ? -errno : 1; fve = (const struct bde_fve_metadata *) buf; - if (memcmp(fve->signature, BDE_MAGIC_FVE, sizeof(fve->signature)) != 0) + if (memcmp(fve->block_header.signature, BDE_MAGIC_FVE, sizeof(fve->block_header.signature)) != 0) goto nothing; if (buf_fve) *buf_fve = buf; @@ -155,20 +169,24 @@ static int probe_bitlocker(blkid_probe pr, if (rc) return rc; - if (kind == BDE_VERSION_WIN7) { - const struct bde_header_win7 *hdr = (const struct bde_header_win7 *) buf_hdr; - - /* Unfortunately, it seems volume_serial is always zero */ - blkid_probe_sprintf_uuid(pr, - (const unsigned char *) &hdr->volume_serial, - sizeof(hdr->volume_serial), - "%016d", le32_to_cpu(hdr->volume_serial)); - } - if (buf_fve) { const struct bde_fve_metadata *fve = (const struct bde_fve_metadata *) buf_fve; - blkid_probe_sprintf_version(pr, "%d", le16_to_cpu(fve->version)); + blkid_probe_sprintf_version(pr, "%d", le16_to_cpu(fve->block_header.version)); + + /* Microsoft GUID format, interpreted as explained by Raymond Chen: + * https://devblogs.microsoft.com/oldnewthing/20220928-00/?p=107221 + */ + blkid_probe_sprintf_uuid(pr, fve->header.volume_identifier, 16, + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + fve->header.volume_identifier[3], fve->header.volume_identifier[2], /* uint32_t Data1 */ + fve->header.volume_identifier[1], fve->header.volume_identifier[0], + fve->header.volume_identifier[5], fve->header.volume_identifier[4], /* uint16_t Data2 */ + fve->header.volume_identifier[7], fve->header.volume_identifier[6], /* uint16_t Data3 */ + fve->header.volume_identifier[8], fve->header.volume_identifier[9], /* uint8_t Data4[8] */ + fve->header.volume_identifier[10], fve->header.volume_identifier[11], + fve->header.volume_identifier[12], fve->header.volume_identifier[13], + fve->header.volume_identifier[14], fve->header.volume_identifier[15]); } return 0; } diff --git a/tests/expected/blkid/low-probe-bitlocker-win7 b/tests/expected/blkid/low-probe-bitlocker-win7 index 4c54c6059..7ef347c9a 100644 --- a/tests/expected/blkid/low-probe-bitlocker-win7 +++ b/tests/expected/blkid/low-probe-bitlocker-win7 @@ -1,3 +1,5 @@ ID_FS_TYPE=BitLocker ID_FS_USAGE=crypto +ID_FS_UUID=83330ba8-07b7-4ea8-b641-ff7bdf18f6b3 +ID_FS_UUID_ENC=83330ba8-07b7-4ea8-b641-ff7bdf18f6b3 ID_FS_VERSION=2