Skip to contentSkip to conversation

Add dm-verity hash device detection to blkid.

PATCH Applied Milan Broz 2 participants 4 messages Jun 1, 2012 – Jun 15, 2012 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Milan Broz

author
#0 lore raw

PATCH 1/1 Add dm-verity hash device detection to blkid.

dm-verity can use separate device for hash verification, in this case there is a superblock in the first sector.

See
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/device-mapper/verity.txt
for more info.

---
 libblkid/src/superblocks/lvm.c         |   41 ++++++++++++++++++++++++++++++++
 libblkid/src/superblocks/superblocks.c |    1 +
 libblkid/src/superblocks/superblocks.h |    1 +
 3 files changed, 43 insertions(+)
libblkid/src/superblocks/lvm.c +41 -0
index 3a9807c..57d2b6e 100644
@@ -4,6 +4,7 @@
  * Copyright (C) 2001 by Andreas Dilger
  * Copyright (C) 2004 Kay Sievers <[email protected]>
  * Copyright (C) 2008 Karel Zak <[email protected]>
+ * Copyright (C) 2012 Milan Broz <[email protected]>
  *
  * This file may be redistributed under the terms of the
  * GNU Lesser General Public License.
@@ -142,6 +143,34 @@ static int probe_lvm1(blkid_probe pr, const struct blkid_idmag *mag)
 	return 0;
 }
 
+#define MAX_SALT_SIZE 384
+struct verity_sb {
+	uint8_t signature[8];
+	uint8_t version;
+	uint8_t data_block_bits;
+	uint8_t hash_block_bits;
+	uint8_t pad1[1];
+	uint16_t salt_size;
+	uint8_t pad2[2];
+	uint32_t data_blocks_hi;
+	uint32_t data_blocks_lo;
+	uint8_t algorithm[16];
+	uint8_t salt[MAX_SALT_SIZE];
+	uint8_t pad3[88];
+} __attribute__((packed));
+
+static int probe_verity(blkid_probe pr, const struct blkid_idmag *mag)
+{
+	struct verity_sb *sb;
+
+	sb = blkid_probe_get_sb(pr, mag, struct verity_sb);
+	if (sb == NULL)
+		return -1;
+
+	blkid_probe_sprintf_version(pr, "%u", sb->version);
+	return 0;
+}
+
 /* NOTE: the original libblkid uses "lvm2pv" as a name */
 const struct blkid_idinfo lvm2_idinfo =
 {
@@ -180,3 +209,15 @@ const struct blkid_idinfo snapcow_idinfo =
 		{ NULL }
 	}
 };
+
+const struct blkid_idinfo verity_hash_idinfo =
+{
+	.name		= "DM_verity_hash",
+	.usage		= BLKID_USAGE_CRYPTO,
+	.probefunc	= probe_verity,
+	.magics		=
+	{
+		{ .magic = "verity\0\0", .len = 8 },
+		{ NULL }
+	}
+};
libblkid/src/superblocks/superblocks.c +1 -0
index 91f4f88..879a40f 100644
@@ -96,6 +96,7 @@ static const struct blkid_idinfo *idinfos[] =
 	&lvm2_idinfo,
 	&lvm1_idinfo,
 	&snapcow_idinfo,
+	&verity_hash_idinfo,
 	&luks_idinfo,
 	&vmfs_volume_idinfo,
 
libblkid/src/superblocks/superblocks.h +1 -0
index c97e447..086a568 100644
@@ -50,6 +50,7 @@ extern const struct blkid_idinfo hpfs_idinfo;
 extern const struct blkid_idinfo lvm2_idinfo;
 extern const struct blkid_idinfo lvm1_idinfo;
 extern const struct blkid_idinfo snapcow_idinfo;
+extern const struct blkid_idinfo verity_hash_idinfo;
 extern const struct blkid_idinfo luks_idinfo;
 extern const struct blkid_idinfo highpoint37x_idinfo;
 extern const struct blkid_idinfo highpoint45x_idinfo;
Signature · 6 lines
1.7.10

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Applied
#2 lore raw
In reply to a message not in the archive
Quoted 4 lines · Milan Broz
 libblkid/src/superblocks/lvm.c         |   41 ++++++++++++++++++++++++++++++++
 libblkid/src/superblocks/superblocks.c |    1 +
 libblkid/src/superblocks/superblocks.h |    1 +
 3 files changed, 43 insertions(+)

Applied, thanks.

Signature · 6 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#3 lore raw

PATCH 1/1 libblkid: update dm-verity scan

In reply to a message not in the archive

New superblock now contains UUID. Old version is not going to be used.

---
 libblkid/src/superblocks/lvm.c |   33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
libblkid/src/superblocks/lvm.c +19 -14
index 57d2b6e..0afc773 100644
@@ -143,31 +143,36 @@ static int probe_lvm1(blkid_probe pr, const struct blkid_idmag *mag)
 	return 0;
 }
 
-#define MAX_SALT_SIZE 384
 struct verity_sb {
-	uint8_t signature[8];
-	uint8_t version;
-	uint8_t data_block_bits;
-	uint8_t hash_block_bits;
-	uint8_t pad1[1];
-	uint16_t salt_size;
-	uint8_t pad2[2];
-	uint32_t data_blocks_hi;
-	uint32_t data_blocks_lo;
-	uint8_t algorithm[16];
-	uint8_t salt[MAX_SALT_SIZE];
-	uint8_t pad3[88];
+	uint8_t  signature[8];	/* "verity\0\0" */
+	uint32_t version;	/* superblock version */
+	uint32_t hash_type;	/* 0 - Chrome OS, 1 - normal */
+	uint8_t  uuid[16];	/* UUID of hash device */
+	uint8_t  algorithm[32];/* hash algorithm name */
+	uint32_t data_block_size; /* data block in bytes */
+	uint32_t hash_block_size; /* hash block in bytes */
+	uint64_t data_blocks;	/* number of data blocks */
+	uint16_t salt_size;	/* salt size */
+	uint8_t  _pad1[6];
+	uint8_t  salt[256];	/* salt */
+	uint8_t  _pad2[168];
 } __attribute__((packed));
 
 static int probe_verity(blkid_probe pr, const struct blkid_idmag *mag)
 {
 	struct verity_sb *sb;
+	unsigned int version;
 
 	sb = blkid_probe_get_sb(pr, mag, struct verity_sb);
 	if (sb == NULL)
 		return -1;
 
-	blkid_probe_sprintf_version(pr, "%u", sb->version);
+	version = le32_to_cpu(sb->version);
+	if (version != 1)
+		return 1;
+
+	blkid_probe_set_uuid(pr, sb->uuid);
+	blkid_probe_sprintf_version(pr, "%u", version);
 	return 0;
 }
 
Signature · 6 lines
1.7.10

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Applied
#5 lore raw

Re: [PATCH] libblkid: update dm-verity scan

In reply to a message not in the archive
Quoted 2 lines · Milan Broz
 libblkid/src/superblocks/lvm.c |   33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

Applied, thanks.

Signature · 6 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html