Skip to contentSkip to conversation

Add dump_metadata subcommand

RFC PATCH New Eric Biggers 1 participant 3 messages Jan 15, 2021

Subsystems (2)
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

cover Add dump_metadata subcommand

Add new subcommand 'fsverity dump_metadata' which wraps the proposed FS_IOC_READ_VERITY_METADATA ioctl
(https://lkml.kernel.org/linux-fscrypt/[email protected]/T/#u).

This subcommand is useful for xfstests and for debugging.

Eric Biggers (2):
Upgrade to latest fsverity_uapi.h
programs/fsverity: Add dump_metadata subcommand

 Makefile                     |   1 +
 common/fsverity_uapi.h       |  14 +++
 programs/cmd_dump_metadata.c | 167 +++++++++++++++++++++++++++++++++++
 programs/fsverity.c          |   6 ++
 programs/fsverity.h          |   6 ++
 5 files changed, 194 insertions(+)
 create mode 100644 programs/cmd_dump_metadata.c
Signature · 8 lines
2.30.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
author maintainer
#1 lore raw

RFC PATCH 1/2 Upgrade to latest fsverity_uapi.h

From: Eric Biggers <[email protected]>

Add the FS_IOC_READ_VERITY_METADATA ioctl.

---
 common/fsverity_uapi.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
common/fsverity_uapi.h +14 -0
index a739c9a..c59a897 100644
@@ -85,7 +85,21 @@ struct fsverity_formatted_digest {
 	__u8 digest[];
 };
 
+#define FS_VERITY_METADATA_TYPE_MERKLE_TREE	1
+#define FS_VERITY_METADATA_TYPE_DESCRIPTOR	2
+#define FS_VERITY_METADATA_TYPE_SIGNATURE	3
+
+struct fsverity_read_metadata_arg {
+	__u64 metadata_type;
+	__u64 offset;
+	__u64 length;
+	__u64 buf_ptr;
+	__u64 __reserved;
+};
+
 #define FS_IOC_ENABLE_VERITY	_IOW('f', 133, struct fsverity_enable_arg)
 #define FS_IOC_MEASURE_VERITY	_IOWR('f', 134, struct fsverity_digest)
+#define FS_IOC_READ_VERITY_METADATA \
+	_IOWR('f', 135, struct fsverity_read_metadata_arg)
 
 #endif /* _UAPI_LINUX_FSVERITY_H */
Signature · 8 lines
2.30.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
author maintainer
#2 lore raw

RFC PATCH 2/2 programs/fsverity: Add dump_metadata subcommand

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

Add a 'fsverity dump_metadata' subcommand which calls FS_IOC_READ_VERITY_METADATA on a file and prints the returned metadata to stdout. There are three subsubcommands, one for each type of metadata that can be read using the ioctl:

fsverity dump_metadata merkle_tree FILE
fsverity dump_metadata descriptor FILE
fsverity dump_metadata signature FILE

By default the whole metadata item is dumped. --length and --offset can be specified to dump only a particular range of the item.

This subcommand will be used by xfstests to test the FS_IOC_READ_VERITY_METADATA ioctl.

---
 Makefile                     |   1 +
 programs/cmd_dump_metadata.c | 167 +++++++++++++++++++++++++++++++++++
 programs/fsverity.c          |   6 ++
 programs/fsverity.h          |   6 ++
 4 files changed, 180 insertions(+)
 create mode 100644 programs/cmd_dump_metadata.c
Makefile +1 -0
index 0354f62..fd28b06 100644
@@ -160,6 +160,7 @@ FSVERITY_PROG_OBJ := $(PROG_COMMON_OBJ)		\
 		     programs/fsverity.o
 ifneq ($(MINGW),1)
 FSVERITY_PROG_OBJ += \
+		     programs/cmd_dump_metadata.o \
 		     programs/cmd_enable.o	\
 		     programs/cmd_measure.o
 endif
programs/cmd_dump_metadata.c new file +167 -0

167 lines not on this page · raw message

programs/fsverity.c +6 -0
index b911b2e..1168430 100644
@@ -29,6 +29,12 @@ static const struct fsverity_command {
 "               [--hash-alg=HASH_ALG] [--block-size=BLOCK_SIZE] [--salt=SALT]\n"
 "               [--compact] [--for-builtin-sig]\n"
 #ifndef _WIN32
+	}, {
+		.name = "dump_metadata",
+		.func = fsverity_cmd_dump_metadata,
+		.short_desc = "Dump the fs-verity metadata of the given file",
+		.usage_str =
+"    fsverity dump_metadata TYPE FILE [--offset=OFFSET] [--length=LENGTH]\n"
 	}, {
 		.name = "enable",
 		.func = fsverity_cmd_enable,
programs/fsverity.h +6 -0
index 45c4fe1..9785013 100644
@@ -27,6 +27,8 @@ enum {
 	OPT_FOR_BUILTIN_SIG,
 	OPT_HASH_ALG,
 	OPT_KEY,
+	OPT_LENGTH,
+	OPT_OFFSET,
 	OPT_SALT,
 	OPT_SIGNATURE,
 };
@@ -37,6 +39,10 @@ struct fsverity_command;
 int fsverity_cmd_digest(const struct fsverity_command *cmd,
 			int argc, char *argv[]);
 
+/* cmd_dump_metadata.c */
+int fsverity_cmd_dump_metadata(const struct fsverity_command *cmd,
+			       int argc, char *argv[]);
+
 /* cmd_enable.c */
 int fsverity_cmd_enable(const struct fsverity_command *cmd,
 			int argc, char *argv[]);
Signature · 8 lines
2.30.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel