| 1 |
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
| 2 |
/* |
| 3 |
* fs-verity user API |
| 4 |
* |
| 5 |
* These ioctls can be used on filesystems that support fs-verity. See the |
| 6 |
* "User API" section of Documentation/filesystems/fsverity.rst. |
| 7 |
* |
| 8 |
* Copyright 2019 Google LLC |
| 9 |
*/ |
| 10 |
#ifndef _UAPI_LINUX_FSVERITY_H |
| 11 |
#define _UAPI_LINUX_FSVERITY_H |
| 12 |
|
| 13 |
#ifndef _WIN32 |
| 14 |
#include <linux/ioctl.h> |
| 15 |
#include <linux/types.h> |
| 16 |
#endif /* !_WIN32 */ |
| 17 |
|
| 18 |
#define FS_VERITY_HASH_ALG_SHA256 1 |
| 19 |
#define FS_VERITY_HASH_ALG_SHA512 2 |
| 20 |
|
| 21 |
struct fsverity_enable_arg { |
| 22 |
__u32 version; |
| 23 |
__u32 hash_algorithm; |
| 24 |
__u32 block_size; |
| 25 |
__u32 salt_size; |
| 26 |
__u64 salt_ptr; |
| 27 |
__u32 sig_size; |
| 28 |
__u32 __reserved1; |
| 29 |
__u64 sig_ptr; |
| 30 |
__u64 __reserved2[11]; |
| 31 |
}; |
| 32 |
|
| 33 |
struct fsverity_digest { |
| 34 |
__u16 digest_algorithm; |
| 35 |
__u16 digest_size; /* input/output */ |
| 36 |
__u8 digest[]; |
| 37 |
}; |
| 38 |
|
| 39 |
/* |
| 40 |
* Struct containing a file's Merkle tree properties. The fs-verity file digest |
| 41 |
* is the hash of this struct. A userspace program needs this struct only if it |
| 42 |
* needs to compute fs-verity file digests itself, e.g. in order to sign files. |
| 43 |
* It isn't needed just to enable fs-verity on a file. |
| 44 |
* |
| 45 |
* Note: when computing the file digest, 'sig_size' and 'signature' must be left |
| 46 |
* zero and empty, respectively. These fields are present only because some |
| 47 |
* filesystems reuse this struct as part of their on-disk format. |
| 48 |
*/ |
| 49 |
struct fsverity_descriptor { |
| 50 |
__u8 version; /* must be 1 */ |
| 51 |
__u8 hash_algorithm; /* Merkle tree hash algorithm */ |
| 52 |
__u8 log_blocksize; /* log2 of size of data and tree blocks */ |
| 53 |
__u8 salt_size; /* size of salt in bytes; 0 if none */ |
| 54 |
#ifdef __KERNEL__ |
| 55 |
__le32 sig_size; |
| 56 |
#else |
| 57 |
__le32 __reserved_0x04; /* must be 0 */ |
| 58 |
#endif |
| 59 |
__le64 data_size; /* size of file the Merkle tree is built over */ |
| 60 |
__u8 root_hash[64]; /* Merkle tree root hash */ |
| 61 |
__u8 salt[32]; /* salt prepended to each hashed block */ |
| 62 |
__u8 __reserved[144]; /* must be 0's */ |
| 63 |
#ifdef __KERNEL__ |
| 64 |
__u8 signature[]; |
| 65 |
#endif |
| 66 |
}; |
| 67 |
|
| 68 |
/* |
| 69 |
* Format in which fs-verity file digests are signed in built-in signatures. |
| 70 |
* This is the same as 'struct fsverity_digest', except here some magic bytes |
| 71 |
* are prepended to provide some context about what is being signed in case the |
| 72 |
* same key is used for non-fsverity purposes, and here the fields have fixed |
| 73 |
* endianness. |
| 74 |
* |
| 75 |
* This struct is specific to the built-in signature verification support, which |
| 76 |
* is optional. fs-verity users may also verify signatures in userspace, in |
| 77 |
* which case userspace is responsible for deciding on what bytes are signed. |
| 78 |
* This struct may still be used, but it doesn't have to be. For example, |
| 79 |
* userspace could instead use a string like "sha256:$digest_as_hex_string". |
| 80 |
*/ |
| 81 |
struct fsverity_formatted_digest { |
| 82 |
char magic[8]; /* must be "FSVerity" */ |
| 83 |
__le16 digest_algorithm; |
| 84 |
__le16 digest_size; |
| 85 |
__u8 digest[]; |
| 86 |
}; |
| 87 |
|
| 88 |
#define FS_VERITY_METADATA_TYPE_MERKLE_TREE 1 |
| 89 |
#define FS_VERITY_METADATA_TYPE_DESCRIPTOR 2 |
| 90 |
#define FS_VERITY_METADATA_TYPE_SIGNATURE 3 |
| 91 |
|
| 92 |
struct fsverity_read_metadata_arg { |
| 93 |
__u64 metadata_type; |
| 94 |
__u64 offset; |
| 95 |
__u64 length; |
| 96 |
__u64 buf_ptr; |
| 97 |
__u64 __reserved; |
| 98 |
}; |
| 99 |
|
| 100 |
#define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) |
| 101 |
#define FS_IOC_MEASURE_VERITY _IOWR('f', 134, struct fsverity_digest) |
| 102 |
#define FS_IOC_READ_VERITY_METADATA \ |
| 103 |
_IOWR('f', 135, struct fsverity_read_metadata_arg) |
| 104 |
|
| 105 |
#endif /* _UAPI_LINUX_FSVERITY_H */ |