fsverity-utils: introduce libfsverity
Subsystems (3)
Eric Biggers
maintainercover fsverity-utils: introduce libfsverity
From the 'fsverity' program, split out a library 'libfsverity'. Currently it supports computing file measurements ("digests"), and signing those file measurements for use with the fs-verity builtin signature verification feature.
Rewritten from patches by Jes Sorensen <[email protected]>. I made a lot of improvements; see patch 2 for details.
Jes, can you let me know whether this works for you? Especially take a close look at the API in libfsverity.h.
This patchset can also be found at branch "libfsverity" of
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/fsverity-utils.git/
Eric Biggers (3):
Split up cmd_sign.c
Introduce libfsverity
Add some basic test programs for libfsverity
.gitignore | 9 +- Makefile | 198 ++++++- cmd_sign.c | 635 ---------------------- commands.h | 24 - util.h => common/common_defs.h | 47 +- fsverity_uapi.h => common/fsverity_uapi.h | 0 common/libfsverity.h | 132 +++++ hash_algs.h | 68 --- lib/compute_digest.c | 243 +++++++++ hash_algs.c => lib/hash_algs.c | 126 +++-- lib/lib_private.h | 83 +++ lib/sign_digest.c | 395 ++++++++++++++ lib/utils.c | 107 ++++ cmd_enable.c => programs/cmd_enable.c | 32 +- cmd_measure.c => programs/cmd_measure.c | 12 +- programs/cmd_sign.c | 163 ++++++ fsverity.c => programs/fsverity.c | 52 +- programs/fsverity.h | 41 ++ programs/test_compute_digest.c | 54 ++ programs/test_hash_algs.c | 27 + programs/test_sign_digest.c | 44 ++ util.c => programs/utils.c | 7 +- programs/utils.h | 42 ++ testdata/cert.pem | 31 ++ testdata/file.sig | Bin 0 -> 708 bytes testdata/key.pem | 52 ++ 26 files changed, 1742 insertions(+), 882 deletions(-) delete mode 100644 cmd_sign.c delete mode 100644 commands.h rename util.h => common/common_defs.h (58%) rename fsverity_uapi.h => common/fsverity_uapi.h (100%) create mode 100644 common/libfsverity.h delete mode 100644 hash_algs.h create mode 100644 lib/compute_digest.c rename hash_algs.c => lib/hash_algs.c (54%) create mode 100644 lib/lib_private.h create mode 100644 lib/sign_digest.c create mode 100644 lib/utils.c rename cmd_enable.c => programs/cmd_enable.c (82%) rename cmd_measure.c => programs/cmd_measure.c (84%) create mode 100644 programs/cmd_sign.c rename fsverity.c => programs/fsverity.c (82%) create mode 100644 programs/fsverity.h create mode 100644 programs/test_compute_digest.c create mode 100644 programs/test_hash_algs.c create mode 100644 programs/test_sign_digest.c rename util.c => programs/utils.c (96%) create mode 100644 programs/utils.h create mode 100644 testdata/cert.pem create mode 100644 testdata/file.sig create mode 100644 testdata/key.pem
Signature · 1 line
2.26.2
Eric Biggers
maintainerPATCH 1/3 Split up cmd_sign.c
From: Eric Biggers <[email protected]>
In preparation for moving most of the functionality of 'fsverity sign' into a shared library, split up cmd_sign.c into three files:
- cmd_sign.c: the actual command
- compute_digest.c: computing the file measurement
- sign_digest.c: sign the file measurement
No "real" changes; this is just moving code around.
--- Makefile | 4 +- cmd_sign.c | 481 +------------------------------------------ lib/compute_digest.c | 184 +++++++++++++++++ lib/sign_digest.c | 304 +++++++++++++++++++++++++++ sign.h | 32 +++ 5 files changed, 523 insertions(+), 482 deletions(-) create mode 100644 lib/compute_digest.c create mode 100644 lib/sign_digest.c create mode 100644 sign.h
Makefile +2 -2
@@ -1,9 +1,9 @@ EXE := fsverity CFLAGS := -O2 -Wall -CPPFLAGS := -D_FILE_OFFSET_BITS=64 +CPPFLAGS := -D_FILE_OFFSET_BITS=64 -I. LDLIBS := -lcrypto DESTDIR := /usr/local -SRC := $(wildcard *.c) +SRC := $(wildcard *.c) $(wildcard lib/*.c) OBJ := $(SRC:.c=.o) HDRS := $(wildcard *.h)
cmd_sign.c +1 -480
499 lines not on this page · raw message
lib/compute_digest.c new file +184 -0
184 lines not on this page · raw message
lib/sign_digest.c new file +304 -0
304 lines not on this page · raw message
sign.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +#ifndef SIGN_H +#define SIGN_H + +#include "hash_algs.h" + +#include <linux/types.h> + +/* +* Format in which verity file measurements are signed. This is the same as +* 'struct fsverity_digest', except here some magic bytes are prepended to +* provide some context about what is being signed in case the same key is used +* for non-fsverity purposes, and here the fields have fixed endianness. +*/ +struct fsverity_signed_digest { +char magic[8 ];/* must be "FSVerity" */ +__le16 digest_algorithm; +__le16 digest_size; +__u8 digest[]; +}; + +bool compute_file_measurement (const char *filename, +const struct fsverity_hash_alg *hash_alg, +u32 block_size,const u8 *salt, +u32 salt_size,u8 *measurement); + +bool sign_data (const void *data_to_sign,size_t data_size, +const char *keyfile,const char *certfile, +const struct fsverity_hash_alg *hash_alg, +u8 **sig_ret,u32 *sig_size_ret); + +#endif /* SIGN_H */
Signature · 1 line
2.26.2
Re: [PATCH 1/3] Split up cmd_sign.c
Quoted 12 lines · Eric Biggers
From: Eric Biggers <[email protected]>
In preparation for moving most of the functionality of 'fsverity sign' into a shared library, split up
cmd_sign.cinto three files:-
cmd_sign.c: the actual command
-compute_digest.c: computing the file measurement
-sign_digest.c: sign the file measurementNo "real" changes; this is just moving code around.
Signed-off-by Eric Biggers <[email protected]>
Quoted 10 lines
--- Makefile | 4 +- cmd_sign.c | 481 +------------------------------------------ lib/compute_digest.c | 184 +++++++++++++++++ lib/sign_digest.c | 304 +++++++++++++++++++++++++++ sign.h | 32 +++ 5 files changed, 523 insertions(+), 482 deletions(-) create mode 100644 lib/compute_digest.c create mode 100644 lib/sign_digest.c create mode 100644 sign.h
I don't really have specific comments to this one, except for the u8/u16/u32 datatype issue I mentioned in the the 2/3 patch.
Thanks,
Jes
Eric Biggers
maintainerPATCH 2/3 Introduce libfsverity
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
From the 'fsverity' program, split out a library 'libfsverity'. Currently it supports computing file measurements ("digests"), and signing those file measurements for use with the fs-verity builtin signature verification feature.
Rewritten from patches by Jes Sorensen <[email protected]>. I made a lot of improvements, e.g.:
- Separated library and program source into different directories.
- Drastically improved the Makefile.
- Added 'make check' target and rules to build test programs.
- In the shared lib, only export the functions intended to be public.
- Prefixed global functions with "libfsverity_" so that they don't cause conflicts when the library is built as a static library.
- Made library error messages be sent to a user-specified callback rather than always be printed to stderr.
- Keep showing OpenSSL error messages.
- Stopped abort()ing in library code, when possible.
- Made libfsverity_digest use native endianness.
- Moved file_size into the merkle_tree_params.
- Made libfsverity_hash_name() just return the static strings.
- Made some variables in the API uint32_t instead of uint16_t.
- Shared parse_hash_alg_option() between cmd_enable and cmd_sign.
- Lots of fixes.
--- .gitignore | 9 +- Makefile | 198 +++++++++++++++++++-- commands.h | 24 --- util.h => common/common_defs.h | 47 +---- fsverity_uapi.h => common/fsverity_uapi.h | 0 common/libfsverity.h | 132 ++++++++++++++ hash_algs.h | 68 -------- lib/compute_digest.c | 181 ++++++++++++------- hash_algs.c => lib/hash_algs.c | 126 +++++++++----- lib/lib_private.h | 83 +++++++++ lib/sign_digest.c | 201 ++++++++++++++++------ lib/utils.c | 107 ++++++++++++ cmd_enable.c => programs/cmd_enable.c | 32 +--- cmd_measure.c => programs/cmd_measure.c | 12 +- cmd_sign.c => programs/cmd_sign.c | 91 +++++----- fsverity.c => programs/fsverity.c | 52 +++++- programs/fsverity.h | 41 +++++ util.c => programs/utils.c | 7 +- programs/utils.h | 42 +++++ sign.h | 32 ---- 20 files changed, 1048 insertions(+), 437 deletions(-) delete mode 100644 commands.h rename util.h => common/common_defs.h (58%) rename fsverity_uapi.h => common/fsverity_uapi.h (100%) create mode 100644 common/libfsverity.h delete mode 100644 hash_algs.h rename hash_algs.c => lib/hash_algs.c (54%) create mode 100644 lib/lib_private.h create mode 100644 lib/utils.c rename cmd_enable.c => programs/cmd_enable.c (82%) rename cmd_measure.c => programs/cmd_measure.c (84%) rename cmd_sign.c => programs/cmd_sign.c (54%) rename fsverity.c => programs/fsverity.c (82%) create mode 100644 programs/fsverity.h rename util.c => programs/utils.c (96%) create mode 100644 programs/utils.h delete mode 100644 sign.h
.gitignore +7 -2
@@ -1,5 +1,10 @@ -fsverity +*.a *.o -tags +*.so +*.so.* +/.build-config +/fsverity +/test_* cscope.* ncscope.* +tags
Makefile +183 -15
205 lines not on this page · raw message
commands.h deleted +0 -24
@@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -#ifndef COMMANDS_H -#define COMMANDS_H - -#include "util.h" - -#include <stdio.h> - -struct fsverity_command ; - -void usage (const struct fsverity_command *cmd,FILE *fp); - -int fsverity_cmd_enable (const struct fsverity_command *cmd, -int argc,char *argv[]); -int fsverity_cmd_measure (const struct fsverity_command *cmd, -int argc,char *argv[]); -int fsverity_cmd_sign (const struct fsverity_command *cmd, -int argc,char *argv[]); - -bool parse_block_size_option (const char *arg,u32 *size_ptr); -u32 get_default_block_size (void ); -bool parse_salt_option (const char *arg,u8 **salt_ptr,u32 *salt_size_ptr); - -#endif /* COMMANDS_H */
common/common_defs.h renamed from util.h +5 -42
61 lines not on this page · raw message
common/fsverity_uapi.h renamed from fsverity_uapi.h +0 -0
common/libfsverity.h new file +132 -0
132 lines not on this page · raw message
hash_algs.h deleted +0 -68
68 lines not on this page · raw message
lib/compute_digest.c +120 -61
260 lines not on this page · raw message
lib/hash_algs.c renamed from hash_algs.c +82 -44
196 lines not on this page · raw message
lib/lib_private.h new file +83 -0
83 lines not on this page · raw message
lib/sign_digest.c +146 -55
384 lines not on this page · raw message
lib/utils.c new file +107 -0
107 lines not on this page · raw message
programs/cmd_enable.c renamed from cmd_enable.c +1 -31
@@ -7,43 +7,13 @@* Written by Eric Biggers. */ -#include "commands.h" -#include "fsverity_uapi.h" -#include "hash_algs.h" +#include "fsverity.h" #include <fcntl.h> #include <getopt.h> #include <limits.h> -#include <stdlib.h> -#include <string.h> #include <sys/ioctl.h> -static bool parse_hash_alg_option (const char *arg,u32 *alg_ptr) -{ -char *end; -unsigned long n =strtoul (arg, &end,10 ); -const struct fsverity_hash_alg *alg; - -if (*alg_ptr !=0 ) { -error_msg ("--hash-alg can only be specified once" ); -return false; - } - -/* Specified by number? */ -if (n >0 && n <INT32_MAX && *end =='\0' ) { - *alg_ptr = n; -return true; - } - -/* Specified by name? */ - alg =find_hash_alg_by_name (arg); -if (alg !=NULL ) { - *alg_ptr = alg - fsverity_hash_algs; -return true; - } -return false; -} -static bool read_signature (const char *filename,u8 **sig_ret,u32 *sig_size_ret) {
programs/cmd_measure.c renamed from cmd_measure.c +3 -9
@@ -7,12 +7,9 @@* Written by Eric Biggers. */ -#include "commands.h" -#include "fsverity_uapi.h" -#include "hash_algs.h" +#include "fsverity.h" #include <fcntl.h> -#include <stdlib.h> #include <sys/ioctl.h> /* Display the measurement of the given verity file(s). */
@@ -22,7 +19,6 @@ int fsverity_cmd_measure(const struct fsverity_command *cmd,struct fsverity_digest *d =NULL ;struct filedes file;char digest_hex[FS_VERITY_MAX_DIGEST_SIZE *2 +1 ]; -const struct fsverity_hash_alg *hash_alg;char _hash_alg_name[32 ];const char *hash_alg_name;int status;
@@ -48,10 +44,8 @@ int fsverity_cmd_measure(const struct fsverity_command *cmd,ASSERT (d->digest_size <=FS_VERITY_MAX_DIGEST_SIZE );bin2hex (d->digest, d->digest_size, digest_hex); - hash_alg =find_hash_alg_by_num (d->digest_algorithm); -if (hash_alg) { - hash_alg_name = hash_alg->name; - }else { + hash_alg_name =libfsverity_hash_name (d->digest_algorithm); +if (!hash_alg_name) {sprintf (_hash_alg_name,"ALG_%u" , d->digest_algorithm); hash_alg_name = _hash_alg_name; }
programs/cmd_sign.c renamed from cmd_sign.c +49 -42
158 lines not on this page · raw message
programs/fsverity.c renamed from fsverity.c +45 -7
89 lines not on this page · raw message
programs/fsverity.h new file +41 -0
41 lines not on this page · raw message
programs/utils.c renamed from util.c +2 -5
@@ -7,15 +7,12 @@* Written by Eric Biggers. */ -#include "util.h" +#include "utils.h" #include <errno.h> #include <fcntl.h> #include <limits.h> #include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <sys/stat.h> #include <unistd.h>
@@ -47,7 +44,7 @@ char *xstrdup(const char *s)/* ========== Error messages and assertions ========== */ -void do_error_msg (const char *format,va_list va,int err) +static void do_error_msg (const char *format,va_list va,int err) {fputs ("ERROR: " , stderr);vfprintf (stderr, format, va);
programs/utils.h new file +42 -0
42 lines not on this page · raw message
sign.h deleted +0 -32
@@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -#ifndef SIGN_H -#define SIGN_H - -#include "hash_algs.h" - -#include <linux/types.h> - -/* -* Format in which verity file measurements are signed. This is the same as -* 'struct fsverity_digest', except here some magic bytes are prepended to -* provide some context about what is being signed in case the same key is used -* for non-fsverity purposes, and here the fields have fixed endianness. -*/ -struct fsverity_signed_digest { -char magic[8 ];/* must be "FSVerity" */ -__le16 digest_algorithm; -__le16 digest_size; -__u8 digest[]; -}; - -bool compute_file_measurement (const char *filename, -const struct fsverity_hash_alg *hash_alg, -u32 block_size,const u8 *salt, -u32 salt_size,u8 *measurement); - -bool sign_data (const void *data_to_sign,size_t data_size, -const char *keyfile,const char *certfile, -const struct fsverity_hash_alg *hash_alg, -u8 **sig_ret,u32 *sig_size_ret); - -#endif /* SIGN_H */
Signature · 1 line
2.26.2
Re: [PATCH 2/3] Introduce libfsverity
Quoted 27 lines · Eric Biggers
From: Eric Biggers <[email protected]>
From the 'fsverity' program, split out a library 'libfsverity'. Currently it supports computing file measurements ("digests"), and signing those file measurements for use with the fs-verity builtin signature verification feature.
Rewritten from patches by Jes Sorensen <[email protected]>. I made a lot of improvements, e.g.:
- Separated library and program source into different directories.
- Drastically improved theMakefile.
- Added 'make check' target and rules to build test programs.
- In the shared lib, only export the functions intended to be public.
- Prefixed global functions with "libfsverity_" so that they don't cause conflicts when the library is built as a static library.
- Made library error messages be sent to a user-specified callback rather than always be printed to stderr.
- Keep showing OpenSSL error messages.
- Stopped abort()ing in library code, when possible.
- Madelibfsverity_digestuse native endianness.
- Movedfile_sizeinto themerkle_tree_params.
- Madelibfsverity_hash_name()just return the static strings.
- Made some variables in the APIuint32_tinstead ofuint16_t.
- Sharedparse_hash_alg_option()betweencmd_enableandcmd_sign.
- Lots of fixes.
Quoted 1 line
Signed-off-by Eric Biggers <[email protected]>
Eric,
Here is a more detailed review. The code as we have it seems to work for me, but there are some issues that I think would be right to address:
I appreciate that you improved the error return values from the original true/false/assert handling.
As much as I hate typedefs, I also like the introduction of libfsverity_read_fn_t as function pointers are somewhat annoying to deal with.
My biggest objection is the export of kernel datatypes to userland and I really don't think using u32/u16/u8 internally in the library adds any value. I had explicitly converted it to uint32_t/uint16_t/uint8_t in my version.
max() defined in common/utils.h is not used by anything, so lets get rid of it.
I also wonder if we should introduce an libfsverity_get_digest_size(alg_nr) function? It would be useful for a caller trying to allocate buffers to store them in, to be able to do this prior to calculating the first digest.
Quoted 5 lines
lib/compute_digest.c +0
-0@@ -1,13 +1,13 @@
... snip ...
lib/compute_digest.c
Quoted 3 lines
lib/compute_digest.c +2
-1-const struct fsverity_hash_alg *find_hash_alg_by_name (const char *name) +LIBEXPORT u32 +libfsverity_find_hash_alg_by_name (const char *name)
This export of u32 here is problematic.
Quoted 27 lines
lib/sign_digest.c +7
-3@@ -1,45 +1,68 @@// SPDX-License-Identifier: GPL-2.0+ /* -* sign_digest.c +* Implementation of libfsverity_sign_digest(). * * Copyright (C) 2018 Google LLC +* Copyright (C) 2020 Facebook */ -#include "hash_algs.h" -#include "sign.h" +#include "lib_private.h" #include <limits.h> #include <openssl/bio.h> #include <openssl/err.h> #include <openssl/pem.h> #include <openssl/pkcs7.h> +#include <string.h> + +/* +* Format in which verity file measurements are signed. This is the same as
lib/sign_digest.c line 29
Quoted 10 lines
lib/sign_digest.c +10
-0+* 'struct fsverity_digest', except here some magic bytes are prepended to +* provide some context about what is being signed in case the same key is used +* for non-fsverity purposes, and here the fields have fixed endianness. +*/ +struct fsverity_signed_digest { +char magic[8 ];/* must be "FSVerity" */ +__le16 digest_algorithm; +__le16 digest_size; +__u8 digest[]; +};
I don't really understand why you prefer to manage two versions of the digest, ie. libfsverity_digest and libfsverity_signed_digest, but it's not a big deal.
Quoted 28 lines
lib/utils.c new file +22
-0@@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Utility functions for libfsverity +* +* Copyright 2020 Google LLC +*/ + +#define _GNU_SOURCE/* for asprintf() */ + +#include "lib_private.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static void *xmalloc (size_t size) +{ +void *p =malloc (size); + +if (!p) +libfsverity_error_msg ("out of memory" ); +return p;
lib/utils.c line 32
Quoted 10 lines
lib/utils.c new file +10
-0+} + +void *libfsverity_zalloc (size_t size) +{ +void *p =xmalloc (size); + +if (!p) +return NULL ; +return memset (p,0 , size); +}
I suggest we get rid of xmalloc() and libfsverity_zalloc(). libc provides perfectly good malloc() and calloc() functions, and printing an out of memory error in a generic location doesn't tell us where the error happened. If anything those error messages should be printed by the calling function IMO.
Cheers,
Jes
Eric Biggers
maintainerRe: [PATCH 2/3] Introduce libfsverity
Quoted 28 lines · Jes Sorensen
Quoted 27 lines · Eric Biggers
From: Eric Biggers <[email protected]>
From the 'fsverity' program, split out a library 'libfsverity'. Currently it supports computing file measurements ("digests"), and signing those file measurements for use with the fs-verity builtin signature verification feature.
Rewritten from patches by Jes Sorensen <[email protected]>. I made a lot of improvements, e.g.:
- Separated library and program source into different directories.
- Drastically improved theMakefile.
- Added 'make check' target and rules to build test programs.
- In the shared lib, only export the functions intended to be public.
- Prefixed global functions with "libfsverity_" so that they don't cause conflicts when the library is built as a static library.
- Made library error messages be sent to a user-specified callback rather than always be printed to stderr.
- Keep showing OpenSSL error messages.
- Stopped abort()ing in library code, when possible.
- Madelibfsverity_digestuse native endianness.
- Movedfile_sizeinto themerkle_tree_params.
- Madelibfsverity_hash_name()just return the static strings.
- Made some variables in the APIuint32_tinstead ofuint16_t.
- Sharedparse_hash_alg_option()betweencmd_enableandcmd_sign.
- Lots of fixes.
Quoted 6 lines
Quoted 1 line
Signed-off-by Eric Biggers <[email protected]>Eric,
Here is a more detailed review. The code as we have it seems to work for me, but there are some issues that I think would be right to address:
Thanks for the feedback!
Quoted 4 lines
I appreciate that you improved the error return values from the original true/false/assert handling.
Quoted 8 lines
As much as I hate typedefs, I also like the introduction of
libfsverity_read_fn_tas function pointers are somewhat annoying to deal with.My biggest objection is the export of kernel datatypes to userland and I really don't think using u32/u16/u8 internally in the library adds any value. I had explicitly converted it to uint32_t/uint16_t/uint8_t in my version.
I prefer u64/u32/u16/u8 since they're shorter and easier to read, and it's the same convention that is used in the kernel code (which is where the other half of fs-verity is).
Note that these types aren't "exported" to or from anywhere but rather are just typedefs in common/common_defs.h. It's just a particular convention.
Also, fsverity-utils is already using this convention prior to this patchset. If we did decide to change it, then we should change it in all the code, not just in certain places.
Quoted 3 lines
max()defined incommon/utils.his not used by anything, so lets get rid of it.
Yes, I'll do that.
Quoted 5 lines
I also wonder if we should introduce an
libfsverity_get_digest_size(alg_nr)function? It would be useful for a caller trying to allocate buffers to store them in, to be able to do this prior to calculating the first digest.
That already exists; it's called libfsverity_digest_size().
Would it be clearer if we renamed:
libfsverity_digest_size() => libfsverity_get_digest_size() libfsverity_hash_name() => libfsverity_get_hash_name()
Quoted 6 lines
Quoted 5 lines
lib/compute_digest.c +0
-0@@ -1,13 +1,13 @@... snip ...
Quoted 6 lines
lib/compute_digest.c
Quoted 3 lines
lib/compute_digest.c +2
-1-const struct fsverity_hash_alg *find_hash_alg_by_name (const char *name) +LIBEXPORT u32 +libfsverity_find_hash_alg_by_name (const char *name)This export of u32 here is problematic.
It's not "exported"; this is a .c file. As long as we use the stdint.h name in libfsverity.h (to avoid polluting the library user's namespace), it is okay. u32 and uint32_t are compatible; they're just different names for the same type.
Quoted 33 lines
Quoted 33 lines
lib/sign_digest.c +13
-3@@ -1,45 +1,68 @@// SPDX-License-Identifier: GPL-2.0+ /* -* sign_digest.c +* Implementation of libfsverity_sign_digest(). * * Copyright (C) 2018 Google LLC +* Copyright (C) 2020 Facebook */ -#include "hash_algs.h" -#include "sign.h" +#include "lib_private.h" #include <limits.h> #include <openssl/bio.h> #include <openssl/err.h> #include <openssl/pem.h> #include <openssl/pkcs7.h> +#include <string.h> + +/* +* Format in which verity file measurements are signed. This is the same as +* 'struct fsverity_digest', except here some magic bytes are prepended to +* provide some context about what is being signed in case the same key is used +* for non-fsverity purposes, and here the fields have fixed endianness. +*/ +struct fsverity_signed_digest { +char magic[8 ];/* must be "FSVerity" */
Quoted 8 lines
lib/sign_digest.c line 29
Quoted 4 lines
lib/sign_digest.c +4
-0+__le16 digest_algorithm; +__le16 digest_size; +__u8 digest[]; +};I don't really understand why you prefer to manage two versions of the digest, ie.
libfsverity_digestandlibfsverity_signed_digest, but it's not a big deal.
Because fsverity_signed_digest has a specific endianness, people will access the fields directly and forget to do the needed endianness conventions -- thus producing code that doesn't work on big endian systems. Using a native-endianness type for the intermediate struct avoids that pitfall.
I think keeping the byte order handling internal to the library is preferable.
Quoted 37 lines
Quoted 37 lines
lib/utils.c new file +30
-0@@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Utility functions for libfsverity +* +* Copyright 2020 Google LLC +*/ + +#define _GNU_SOURCE/* for asprintf() */ + +#include "lib_private.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static void *xmalloc (size_t size) +{ +void *p =malloc (size); + +if (!p) +libfsverity_error_msg ("out of memory" ); +return p; +} + +void *libfsverity_zalloc (size_t size) +{ +void *p =xmalloc (size); + +if (!p) +return NULL ;
Quoted 9 lines
lib/utils.c line 32
Quoted 2 lines
lib/utils.c new file +2
-0+return memset (p,0 , size); +}I suggest we get rid of
xmalloc()andlibfsverity_zalloc(). libc provides perfectly goodmalloc()andcalloc()functions, and printing an out of memory error in a generic location doesn't tell us where the error happened. If anything those error messages should be printed by the calling function IMO.
Maybe. I'm not sure knowing the specific allocation sites would be useful enough to make all the callers handle printing the error message (which is easily forgotten about). We could also add the allocation size that failed to the message here.
- Eric
Re: [PATCH 2/3] Introduce libfsverity
Quoted 17 lines · Eric Biggers
Quoted 4 lines · Jes Sorensen
Eric,
Here is a more detailed review. The code as we have it seems to work for me, but there are some issues that I think would be right to address:
Thanks for the feedback!
Quoted 8 lines
I appreciate that you improved the error return values from the original true/false/assert handling.
As much as I hate typedefs, I also like the introduction of
libfsverity_read_fn_tas function pointers are somewhat annoying to deal with.
Quoted 8 lines
Quoted 4 lines
My biggest objection is the export of kernel datatypes to userland and I really don't think using u32/u16/u8 internally in the library adds any value. I had explicitly converted it to uint32_t/uint16_t/uint8_t in my version.
I prefer u64/u32/u16/u8 since they're shorter and easier to read, and it's the same convention that is used in the kernel code (which is where the other half of fs-verity is).
I like them too, but I tend to live in kernel space.
Quoted 6 lines
Note that these types aren't "exported" to or from anywhere but rather are just typedefs in
common/common_defs.h. It's just a particular convention.Also, fsverity-utils is already using this convention prior to this patchset. If we did decide to change it, then we should change it in all the code, not just in certain places.
I thought I did it everywhere in my patch set?
Quoted 11 lines
Quoted 4 lines
I also wonder if we should introduce an
libfsverity_get_digest_size(alg_nr)function? It would be useful for a caller trying to allocate buffers to store them in, to be able to do this prior to calculating the first digest.That already exists; it's called
libfsverity_digest_size().Would it be clearer if we renamed:
libfsverity_digest_size()=>libfsverity_get_digest_size()libfsverity_hash_name()=>libfsverity_get_hash_name()
Oh I missed you added that. Probably a good idea to rename them for consistency.
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
lib/compute_digest.c +0
-0@@ -1,13 +1,13 @@... snip ...
lib/compute_digest.c
Quoted 3 lines
lib/compute_digest.c +2
-1-const struct fsverity_hash_alg *find_hash_alg_by_name (const char *name) +LIBEXPORT u32 +libfsverity_find_hash_alg_by_name (const char *name)This export of u32 here is problematic.
Quoted 3 lines
It's not "exported"; this is a .c file. As long as we use the
stdint.hname inlibfsverity.h(to avoid polluting the library user's namespace), it is okay. u32 anduint32_tare compatible; they're just different names for the same type.
I would still keep it consistent avoid relying on assumptions that types are identical.
Quoted 11 lines
Quoted 10 lines
lib/compute_digest.c
Quoted 6 lines
lib/compute_digest.c +6
-0+struct fsverity_signed_digest { +char magic[8 ];/* must be "FSVerity" */ +__le16 digest_algorithm; +__le16 digest_size; +__u8 digest[]; +};I don't really understand why you prefer to manage two versions of the digest, ie.
libfsverity_digestandlibfsverity_signed_digest, but it's not a big deal.
Quoted 6 lines
Because
fsverity_signed_digesthas a specific endianness, people will access the fields directly and forget to do the needed endianness conventions -- thus producing code that doesn't work on big endian systems. Using a native-endianness type for the intermediate struct avoids that pitfall.I think keeping the byte order handling internal to the library is preferable.
Fair enough
Quoted 25 lines
Quoted 15 lines
Quoted 15 lines
lib/compute_digest.c +15
-0+static void *xmalloc (size_t size) +{ +void *p =malloc (size); + +if (!p) +libfsverity_error_msg ("out of memory" ); +return p; +} + +void *libfsverity_zalloc (size_t size) +{ +void *p =xmalloc (size); + +if (!p) +return NULL ;Quoted 9 lines
lib/compute_digest.c
Quoted 2 lines
lib/compute_digest.c +2
-0+return memset (p,0 , size); +}I suggest we get rid of
xmalloc()andlibfsverity_zalloc(). libc provides perfectly goodmalloc()andcalloc()functions, and printing an out of memory error in a generic location doesn't tell us where the error happened. If anything those error messages should be printed by the calling function IMO.
Quoted 4 lines
Maybe. I'm not sure knowing the specific allocation sites would be useful enough to make all the callers handle printing the error message (which is easily forgotten about). We could also add the allocation size that failed to the message here.
My point is mostly at this point, this just adds code obfuscation rather than adding real value. I can see how it was useful during initial development.
Cheers,
Jes
Eric Biggers
maintainerRe: [PATCH 2/3] Introduce libfsverity
Quoted 11 lines · Jes Sorensen
Quoted 8 lines
Quoted 4 lines
My biggest objection is the export of kernel datatypes to userland and I really don't think using u32/u16/u8 internally in the library adds any value. I had explicitly converted it to uint32_t/uint16_t/uint8_t in my version.
I prefer u64/u32/u16/u8 since they're shorter and easier to read, and it's the same convention that is used in the kernel code (which is where the other half of fs-verity is).
I like them too, but I tend to live in kernel space.
Quoted 8 lines
Quoted 6 lines
Note that these types aren't "exported" to or from anywhere but rather are just typedefs in
common/common_defs.h. It's just a particular convention.Also, fsverity-utils is already using this convention prior to this patchset. If we did decide to change it, then we should change it in all the code, not just in certain places.
I thought I did it everywhere in my patch set?
No, they were still left in various places.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
I also wonder if we should introduce an
libfsverity_get_digest_size(alg_nr)function? It would be useful for a caller trying to allocate buffers to store them in, to be able to do this prior to calculating the first digest.That already exists; it's called
libfsverity_digest_size().
Quoted 7 lines
Quoted 4 lines
Would it be clearer if we renamed:
libfsverity_digest_size()=>libfsverity_get_digest_size()libfsverity_hash_name()=>libfsverity_get_hash_name()Oh I missed you added that. Probably a good idea to rename them for consistency.
libfsverity_digest_size() was actually in your patchset too.
I'll add the "get" to the names so that all function names start with a verb.
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 7 lines
lib/utils.c new file +7
-0+static void *xmalloc (size_t size) +{ +void *p =malloc (size); + +if (!p) +libfsverity_error_msg ("out of memory" ); +return p;lib/utils.c line 32
Quoted 10 lines
lib/utils.c new file +10
-0+} + +void *libfsverity_zalloc (size_t size) +{ +void *p =xmalloc (size); + +if (!p) +return NULL ; +return memset (p,0 , size); +}I suggest we get rid of
xmalloc()andlibfsverity_zalloc(). libc provides perfectly goodmalloc()andcalloc()functions, and printing an out of memory error in a generic location doesn't tell us where the error happened. If anything those error messages should be printed by the calling function IMO.
Quoted 8 lines
Quoted 4 lines
Maybe. I'm not sure knowing the specific allocation sites would be useful enough to make all the callers handle printing the error message (which is easily forgotten about). We could also add the allocation size that failed to the message here.
My point is mostly at this point, this just adds code obfuscation rather than adding real value. I can see how it was useful during initial development.
It's helpful to eliminate the need for callers to print the error message.
We also still need libfsverity_memdup() anyway, unless we hard-code malloc() + memcpy().
I also had in mind that we'd follow the (increasingly recommended) practice of initializing all heap memory. This can be done by only providing allocation functions that initialize memory.
I'll think about it.
- Eric
Re: [PATCH 2/3] Introduce libfsverity
Quoted 15 lines · Eric Biggers
Quoted 14 lines · Jes Sorensen
Quoted 8 lines
Quoted 4 lines
My biggest objection is the export of kernel datatypes to userland and I really don't think using u32/u16/u8 internally in the library adds any value. I had explicitly converted it to uint32_t/uint16_t/uint8_t in my version.
I prefer u64/u32/u16/u8 since they're shorter and easier to read, and it's the same convention that is used in the kernel code (which is where the other half of fs-verity is).
I like them too, but I tend to live in kernel space.
Quoted 3 lines
Note that these types aren't "exported" to or from anywhere but rather are just typedefs in
common/common_defs.h. It's just a particular convention.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Also, fsverity-utils is already using this convention prior to this patchset. If we did decide to change it, then we should change it in all the code, not just in certain places.
I thought I did it everywhere in my patch set?
No, they were still left in various places.
I see, I thought I had only left the __u32 ones in place, but just goes to show I didn't do my job properly.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
I also wonder if we should introduce an
libfsverity_get_digest_size(alg_nr)function? It would be useful for a caller trying to allocate buffers to store them in, to be able to do this prior to calculating the first digest.That already exists; it's called
libfsverity_digest_size().Would it be clearer if we renamed:
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
libfsverity_digest_size()=>libfsverity_get_digest_size()libfsverity_hash_name()=>libfsverity_get_hash_name()Oh I missed you added that. Probably a good idea to rename them for consistency.
libfsverity_digest_size()was actually in your patchset too.
Whoops egg on face :)
Quoted 1 line
I'll add the "get" to the names so that all function names start with a verb.
Sounds good!
Quoted 36 lines
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 7 lines
lib/utils.c new file +7
-0+static void *xmalloc (size_t size) +{ +void *p =malloc (size); + +if (!p) +libfsverity_error_msg ("out of memory" ); +return p;lib/utils.c line 32
Quoted 10 lines
lib/utils.c new file +10
-0+} + +void *libfsverity_zalloc (size_t size) +{ +void *p =xmalloc (size); + +if (!p) +return NULL ; +return memset (p,0 , size); +}I suggest we get rid of
xmalloc()andlibfsverity_zalloc(). libc provides perfectly goodmalloc()andcalloc()functions, and printing an out of memory error in a generic location doesn't tell us where the error happened. If anything those error messages should be printed by the calling function IMO.Quoted 8 lines
Quoted 4 lines
Maybe. I'm not sure knowing the specific allocation sites would be useful enough to make all the callers handle printing the error message (which is easily forgotten about). We could also add the allocation size that failed to the message here.
My point is mostly at this point, this just adds code obfuscation rather than adding real value. I can see how it was useful during initial development.
It's helpful to eliminate the need for callers to print the error message.
Quoted 8 lines
We also still need
libfsverity_memdup()anyway, unless we hard-codemalloc()+memcpy().I also had in mind that we'd follow the (increasingly recommended) practice of initializing all heap memory. This can be done by only providing allocation functions that initialize memory.
I'll think about it.
It's not a showstopper, my primary interest is a working release :)
Cheers,
Jes
Eric Biggers
maintainerPATCH 3/3 Add some basic test programs for libfsverity
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Add three test programs: 'test_hash_algs', 'test_compute_digest', and 'test_sign_digest'. Nothing fancy yet, just some basic tests to test each library function.
With the new Makefile, these get run by 'make check'.
--- programs/test_compute_digest.c | 54 +++++++++++++++++++++++++++++++++ programs/test_hash_algs.c | 27 +++++++++++++++++ programs/test_sign_digest.c | 44 +++++++++++++++++++++++++++ testdata/cert.pem | 31 +++++++++++++++++++ testdata/file.sig | Bin 0 -> 708 bytes testdata/key.pem | 52 +++++++++++++++++++++++++++++++ 6 files changed, 208 insertions(+) create mode 100644 programs/test_compute_digest.c create mode 100644 programs/test_hash_algs.c create mode 100644 programs/test_sign_digest.c create mode 100644 testdata/cert.pem create mode 100644 testdata/file.sig create mode 100644 testdata/key.pem
programs/test_compute_digest.c new file +54 -0
@@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include "utils.h" + +struct file { +u8 *data; +size_t size; +size_t offset; +}; + +static int read_fn (void *fd,void *buf,size_t count) +{ +struct file *f = fd; + +ASSERT (count <= f->size - f->offset); +memcpy (buf, &f->data[f->offset], count); + f->offset += count; +return 0 ; +} + +int main (void ) +{ +struct file f = { .size =1000000 }; +size_t i; +const struct libfsverity_merkle_tree_params params = { + .version =1 , + .hash_algorithm =FS_VERITY_HASH_ALG_SHA256 , + .block_size =4096 , + .salt_size =4 , + .salt = (u8 *)"abcd" , + .file_size = f.size, + }; +struct libfsverity_digest *d; +static const u8 expected_digest[32 ] = +"\x91\x79\x00\xb0\xd2\x99\x45\x4a\xa3\x04\xd5\xde\xbc\x6f\x39" +"\xe4\xaf\x7b\x5a\xbe\x33\xbd\xbc\x56\x8d\x5d\x8f\x1e\x5c\x4d" +"\x86\x52" ; +int err; + + f.data =xmalloc (f.size); +for (i =0 ; i < f.size; i++) + f.data[i] = (i %11 ) + (i %439 ) + (i %1103 ); + + err =libfsverity_compute_digest (&f, read_fn, ¶ms, &d); +ASSERT (err ==0 ); + +ASSERT (d->digest_algorithm ==FS_VERITY_HASH_ALG_SHA256 ); +ASSERT (d->digest_size ==32 ); +ASSERT (!memcmp (d->digest, expected_digest,32 )); + +free (f.data); +free (d); +printf ("test_compute_digest passed\n" ); +return 0 ; +}
programs/test_hash_algs.c new file +27 -0
@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include "utils.h" + +int main (void ) +{ +ASSERT (libfsverity_digest_size (0 ) ==-1 ); +ASSERT (libfsverity_hash_name (0 ) ==NULL ); +ASSERT (libfsverity_find_hash_alg_by_name ("bad" ) ==0 ); + +ASSERT (libfsverity_digest_size (100 ) ==-1 ); +ASSERT (libfsverity_hash_name (100 ) ==NULL ); + +ASSERT (libfsverity_digest_size (FS_VERITY_HASH_ALG_SHA256 ) ==32 ); +ASSERT (!strcmp ("sha256" , +libfsverity_hash_name (FS_VERITY_HASH_ALG_SHA256 ))); +ASSERT (libfsverity_find_hash_alg_by_name ("sha256" ) == +FS_VERITY_HASH_ALG_SHA256 ); + +ASSERT (libfsverity_digest_size (FS_VERITY_HASH_ALG_SHA512 ) ==64 ); +ASSERT (!strcmp ("sha512" , +libfsverity_hash_name (FS_VERITY_HASH_ALG_SHA512 ))); +ASSERT (libfsverity_find_hash_alg_by_name ("sha512" ) == +FS_VERITY_HASH_ALG_SHA512 ); + +printf ("test_hash_algs passed\n" ); +return 0 ; +}
programs/test_sign_digest.c new file +44 -0
44 lines not on this page · raw message
testdata/cert.pem new file +31 -0
@@ -0,0 +1,31 @@ +-----BEGIN CERTIFICATE----- +MIIFazCCA1OgAwIBAgIUYaRYcyZGDIv9fIxx/RoJwQu23+owDQYJKoZIhvcNAQEL +BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM +GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMDA1MTUwMjUyMzFaFw0yMDA2 +MTQwMjUyMzFaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw +HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggIiMA0GCSqGSIb3DQEB +AQUAA4ICDwAwggIKAoICAQC5lXk9otBz/VM/tbvBBK6sK//HE+q3ctY4+fPVv3Ob +D1YNYuWRD59U+7K8fVUfZlXyjgxt3n4VPzkLgRSr/w5YUTa5NEOVJIltKT4ugswL +5oY8eRVSuIr1O+vTbu+EpUk3DhTaFkalVzwspwipBeiVTDO9kh0NAueRk2HyLJte +IoPyfzSCKxg9sED6/WtLFqrhDb5+1qeGoMNGM66ueWXKX0QjomMEODGXC04ypIY3 +sTwB+sYhZUe3YRpY0HyaVNh/6cxCxSiKr2jkC5UL+ry+46EJerNZbKmeqqyqmhXh +P2cHv8MO91zdH1xbXUUenLcdpK/0oq+/sTAVV1/qPvnAofpN8tdZdrH65JD753jt +s+lH/f0iGuKAb9ZpLOTM2d3wjY13OcHElj0zu2Usw9PXQpTK/DYlbcapOI4NTVyU +NpK3yP4i5dPnkHoxpjLWz75Eq6gP9ZXohGq3YG0LxtvELWfaFmpzEUTlD59hJJOZ +ELGxAXzsxLbelX/EmpX+GIqnFBpdMIuPO4HEfJwD5IcdeHqGl2iH9LIqsY5DcGj4 +hnqYplIYYk5mWgbhkexRbJIGNdn8WyXlraVp2MoSr3p7xJbmo0qYRRtt3kQShzDG +0FrZX7wqxemc/g/hr+g2xqMQj0nYLehDeodqxA2n9grDUr4AdgQyxXDMUkGZdrg3 +cwIDAQABo1MwUTAdBgNVHQ4EFgQUxpaj6YjgLFyh9UVM71hf18cb/hkwHwYDVR0j +BBgwFoAUxpaj6YjgLFyh9UVM71hf18cb/hkwDwYDVR0TAQH/BAUwAwEB/zANBgkq +hkiG9w0BAQsFAAOCAgEAQnXMCgI+eSjK+l3nrpE+TRrXZhHeB0aT3gilVtBqFM95 +GxkLzOgJnW4SU+BCKTiGjwhCEXQiFj6UNDrI7vaNzmurI370uqmC9/pwKn4/L27V +ToqLHk5d8kmvjSJyfgY/9H73srzHjNcqLG3uy+JP3/fIzaUzy7x9OUJtzdH19zic +b61kCbqe6TJrlpL0Y50FY91QTzupsIS9IsAAeYXrJiEwpkXv/O9c51swtGZmQhVD +TDn4B2aKOHecR+gKZQbPcuwTCbNLDRRPT4q0IM9yKjUxIM8vkAaxlrW3O7fgqUV0 +GU3/i0zZugq2XEludF3VelrqMUhSMqaREAtRUe3ufipwEsovDa43Hr9P6bINAfU3 +92Kv6adgeKZc4DmuEg6sFje/ET85teioHtwmjviJu6vnkbZg7x+IU01Y6YHboz/z +hTAjz9g6owgdsbTG9nptvgJllY83zBtnAGOqhJLNVZ+TC3pbbKht/7sT+s+WP2+K +81oZ3gmxIr6myMVyR5CCt+FNJ1hFxYNBJDao35iiZLxDe2s5nMJKHYezUY60ujqT +Ljv3Ku4uAk5PgXltZnWGz152ntjopA0gbnlU4f+SgnmPoBFcvn36BcUQWQbTDqmh +h+Y0OaXR3x/27M/qkPBov4IAfoCkWeF7i02wxwtdTLiSF7OjTDkQXtZemUzN5+w= +-----END CERTIFICATE-----
testdata/file.sig new file binary +0 -0
testdata/key.pem new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH 3/3] Add some basic test programs for libfsverity
Quoted 30 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Add three test programs: '
test_hash_algs', 'test_compute_digest', and 'test_sign_digest'. Nothing fancy yet, just some basic tests to test each library function.With the new
Makefile, these get run by 'make check'.Signed-off-by Eric Biggers <[email protected]>--- programs/test_compute_digest.c | 54 +++++++++++++++++++++++++++++++++ programs/test_hash_algs.c | 27 +++++++++++++++++ programs/test_sign_digest.c | 44 +++++++++++++++++++++++++++ testdata/cert.pem | 31 +++++++++++++++++++ testdata/file.sig | Bin 0 -> 708 bytes testdata/key.pem | 52 +++++++++++++++++++++++++++++++ 6 files changed, 208 insertions(+) create mode 100644 programs/test_compute_digest.c create mode 100644 programs/test_hash_algs.c create mode 100644 programs/test_sign_digest.c create mode 100644 testdata/cert.pem create mode 100644 testdata/file.sig create mode 100644 testdata/key.pemprograms/test_compute_digest.c new file +0
-0
programs/test_compute_digest.c line 8
Quoted 8 lines
programs/test_compute_digest.c new file +8
-0@@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include "utils.h" + +struct file { +u8 *data; +size_t size; +size_t offset; +};
The only issue I have here is the use of u8/u16/u32 in userland.
Cheers,
Jes
Quoted 10 lines · Eric Biggers
From the 'fsverity' program, split out a library 'libfsverity'. Currently it supports computing file measurements ("digests"), and signing those file measurements for use with the fs-verity builtin signature verification feature.
Rewritten from patches by Jes Sorensen <[email protected]>. I made a lot of improvements; see patch 2 for details.
Jes, can you let me know whether this works for you? Especially take a close look at the API in
libfsverity.h.
Hi Eric,
Thanks for looking at this. I have gone through this and managed to get my RPM code to work with it. I will push the updated code to my rpm github repo shortly. I have two fixes for the Makefile I will send to you in a separate email.
One comment I have is that you changed the size of version and hash_algorithm to 32 bit in struct libfsverity_merkle_tree_params, but the kernel API only takes 8 bit values anyway. I had them at 16 bit to handle the struct padding, but if anything it seems to make more sense to make them 8 bit and pad the struct?
struct libfsverity_merkle_tree_params {
uint32_t version;
uint32_t hash_algorithm;That said, not a big deal.
Cheers,
Jes
Eric Biggers
maintainerQuoted 25 lines · Jes Sorensen
Quoted 10 lines · Eric Biggers
From the 'fsverity' program, split out a library 'libfsverity'. Currently it supports computing file measurements ("digests"), and signing those file measurements for use with the fs-verity builtin signature verification feature.
Rewritten from patches by Jes Sorensen <[email protected]>. I made a lot of improvements; see patch 2 for details.
Jes, can you let me know whether this works for you? Especially take a close look at the API in
libfsverity.h.Hi Eric,
Thanks for looking at this. I have gone through this and managed to get my RPM code to work with it. I will push the updated code to my rpm github repo shortly. I have two fixes for the
MakefileI will send to you in a separate email.One comment I have is that you changed the size of version and
hash_algorithmto 32 bit in structlibfsverity_merkle_tree_params, but the kernel API only takes 8 bit values anyway. I had them at 16 bit to handle the struct padding, but if anything it seems to make more sense to make them 8 bit and pad the struct?
Quoted 6 lines
struct libfsverity_merkle_tree_params { uint32_t version; uint32_t hash_algorithm;That said, not a big deal.
Well, they're 32-bit in 'struct fsverity_enable_arg' (the argument to FS_IOC_ENABLE_VERITY), but 8-bit in 'struct fsverity_descriptor'. The reason for the difference is that 'struct fsverity_enable_arg' is just an in-memory structure for the ioctl, so there was no reason not to use larger fields. But fsverity_descriptor is stored on-disk and hashed, and it has to have a specific byte order, so just using 8-bit fields for it seemed best.
'struct libfsverity_merkle_tree_params' is just an in-memory structure too, so I think going with the 32-bits convention makes sense.
- Eric
Quoted 40 lines · Eric Biggers
Quoted 25 lines · Jes Sorensen
Quoted 10 lines · Eric Biggers
From the 'fsverity' program, split out a library 'libfsverity'. Currently it supports computing file measurements ("digests"), and signing those file measurements for use with the fs-verity builtin signature verification feature.
Rewritten from patches by Jes Sorensen <[email protected]>. I made a lot of improvements; see patch 2 for details.
Jes, can you let me know whether this works for you? Especially take a close look at the API in
libfsverity.h.Hi Eric,
Thanks for looking at this. I have gone through this and managed to get my RPM code to work with it. I will push the updated code to my rpm github repo shortly. I have two fixes for the
MakefileI will send to you in a separate email.One comment I have is that you changed the size of version and
hash_algorithmto 32 bit in structlibfsverity_merkle_tree_params, but the kernel API only takes 8 bit values anyway. I had them at 16 bit to handle the struct padding, but if anything it seems to make more sense to make them 8 bit and pad the struct?Quoted 6 lines
struct libfsverity_merkle_tree_params { uint32_t version; uint32_t hash_algorithm;That said, not a big deal.
Well, they're 32-bit in 'struct
fsverity_enable_arg' (the argument toFS_IOC_ENABLE_VERITY), but 8-bit in 'structfsverity_descriptor'. The reason for the difference is that 'structfsverity_enable_arg' is just an in-memory structure for the ioctl, so there was no reason not to use larger fields. Butfsverity_descriptoris stored on-disk and hashed, and it has to have a specific byte order, so just using 8-bit fields for it seemed best.
Quoted 2 lines
'struct
libfsverity_merkle_tree_params' is just an in-memory structure too, so I think going with the 32-bits convention makes sense.
OK, thanks for the explanation, it's not a big deal going one way or the other.
Cheers,
Jes