Although it isn't used directly by the ioctls, "struct fsverity_descriptor" is required by userspace programs that need to compute fs-verity file digests in a standalone way. Therefore it's also needed to sign files in a standalone way. Similarly, "struct fsverity_formatted_digest" (previously called "struct fsverity_signed_digest" which was misleading) is also needed to sign files if the built-in signature verification is being used. Therefore, move these structs to the UAPI header. While doing this, try to make it clear that the signature-related fields in fsverity_descriptor aren't used in the file digest computation.
Showing the changes to include/uapi/linux (1 of 3 files). Show all
Unified · Split
| @@ -34,6 +34,55 @@ struct fsverity_digest { · 33 unmodified lines | |||
| 34 | __u8 digest[]; | 34 | __u8 digest[]; |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | /* | ||
| 38 | * Struct containing a file's Merkle tree properties. The fs-verity file digest | ||
| 39 | * is the hash of this struct. A userspace program needs this struct only if it | ||
| 40 | * needs to compute fs-verity file digests itself, e.g. in order to sign files. | ||
| 41 | * It isn't needed just to enable fs-verity on a file. | ||
| 42 | * | ||
| 43 | * Note: when computing the file digest, 'sig_size' and 'signature' must be left | ||
| 44 | * zero and empty, respectively. These fields are present only because some | ||
| 45 | * filesystems reuse this struct as part of their on-disk format. | ||
| 46 | */ | ||
| 47 | struct fsverity_descriptor { | ||
| 48 | __u8 version; /* must be 1 */ | ||
| 49 | __u8 hash_algorithm; /* Merkle tree hash algorithm */ | ||
| 50 | __u8 log_blocksize; /* log2 of size of data and tree blocks */ | ||
| 51 | __u8 salt_size; /* size of salt in bytes; 0 if none */ | ||
| 52 | #ifdef __KERNEL__ | ||
| 53 | __le32 sig_size; | ||
| 54 | #else | ||
| 55 | __le32 __reserved_0x04; /* must be 0 */ | ||
| 56 | #endif | ||
| 57 | __le64 data_size; /* size of file the Merkle tree is built over */ | ||
| 58 | __u8 root_hash[64]; /* Merkle tree root hash */ | ||
| 59 | __u8 salt[32]; /* salt prepended to each hashed block */ | ||
| 60 | __u8 __reserved[144]; /* must be 0's */ | ||
| 61 | #ifdef __KERNEL__ | ||
| 62 | __u8 signature[]; | ||
| 63 | #endif | ||
| 64 | }; | ||
| 65 | |||
| 66 | /* | ||
| 67 | * Format in which fs-verity file digests are signed in built-in signatures. | ||
| 68 | * This is the same as 'struct fsverity_digest', except here some magic bytes | ||
| 69 | * are prepended to provide some context about what is being signed in case the | ||
| 70 | * same key is used for non-fsverity purposes, and here the fields have fixed | ||
| 71 | * endianness. | ||
| 72 | * | ||
| 73 | * This struct is specific to the built-in signature verification support, which | ||
| 74 | * is optional. fs-verity users may also verify signatures in userspace, in | ||
| 75 | * which case userspace is responsible for deciding on what bytes are signed. | ||
| 76 | * This struct may still be used, but it doesn't have to be. For example, | ||
| 77 | * userspace could instead use a string like "sha256:$digest_as_hex_string". | ||
| 78 | */ | ||
| 79 | struct fsverity_formatted_digest { | ||
| 80 | char magic[8]; /* must be "FSVerity" */ | ||
| 81 | __le16 digest_algorithm; | ||
| 82 | __le16 digest_size; | ||
| 83 | __u8 digest[]; | ||
| 84 | }; | ||
| 85 | |||
| 37 | #define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) | 86 | #define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) |
| 38 | #define FS_IOC_MEASURE_VERITY _IOWR('f', 134, struct fsverity_digest) | 87 | #define FS_IOC_MEASURE_VERITY _IOWR('f', 134, struct fsverity_digest) |
| 39 | 88 | ||