linux/fs/verity
Eric Biggers c2c8261151 fs-verity: factor out fsverity_get_descriptor()
The FS_IOC_READ_VERITY_METADATA ioctl will need to return the fs-verity
descriptor (and signature) to userspace.

There are a few ways we could implement this:

- Save a copy of the descriptor (and signature) in the fsverity_info
  struct that hangs off of the in-memory inode.  However, this would
  waste memory since most of the time it wouldn't be needed.

- Regenerate the descriptor from the merkle_tree_params in the
  fsverity_info.  However, this wouldn't work for the signature, nor for
  the salt which the merkle_tree_params only contains indirectly as part
  of the 'hashstate'.  It would also be error-prone.

- Just get them from the filesystem again.  The disadvantage is that in
  general we can't trust that they haven't been maliciously changed
  since the file has opened.  However, the use cases for
  FS_IOC_READ_VERITY_METADATA don't require that it verifies the chain
  of trust.  So this is okay as long as we do some basic validation.

In preparation for implementing the third option, factor out a helper
function fsverity_get_descriptor() which gets the descriptor (and
appended signature) from the filesystem and does some basic validation.

As part of this, start checking the sig_size field for overflow.
Currently fsverity_verify_signature() does this.  But the new ioctl will
need this too, so do it earlier.

Link: https://lore.kernel.org/r/20210115181819.34732-2-ebiggers@kernel.org
Reviewed-by: Victor Hsieh <victorhsieh@google.com>
Reviewed-by: Jaegeuk Kim <jaegeuk@kernel.org>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
2021-02-07 14:51:03 -08:00
..
enable.c fs-verity: rename "file measurement" to "file digest" 2020-11-16 11:40:12 -08:00
fsverity_private.h fs-verity: factor out fsverity_get_descriptor() 2021-02-07 14:51:03 -08:00
hash_algs.c fs-verity: remove filenames from file comments 2020-11-16 11:40:10 -08:00
init.c fs-verity: remove filenames from file comments 2020-11-16 11:40:10 -08:00
Kconfig fs-verity: support builtin file signatures 2019-08-12 19:33:50 -07:00
Makefile fs-verity: support builtin file signatures 2019-08-12 19:33:50 -07:00
measure.c fs-verity: rename "file measurement" to "file digest" 2020-11-16 11:40:12 -08:00
open.c fs-verity: factor out fsverity_get_descriptor() 2021-02-07 14:51:03 -08:00
signature.c fs-verity: rename "file measurement" to "file digest" 2020-11-16 11:40:12 -08:00
verify.c fs-verity: remove filenames from file comments 2020-11-16 11:40:10 -08:00