fs/verity/fsverity_private.h

Source file repositories/reference/linux-study-clean/fs/verity/fsverity_private.h

File Facts

System
Linux kernel
Corpus path
fs/verity/fsverity_private.h
Extension
.h
Size
5420 bytes
Lines
172
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct fsverity_hash_alg {
	const char *name;	  /* crypto API name, e.g. sha256 */
	unsigned int digest_size; /* digest size in bytes, e.g. 32 for SHA-256 */
	unsigned int block_size;  /* block size in bytes, e.g. 64 for SHA-256 */
	/*
	 * The HASH_ALGO_* constant for this algorithm.  This is different from
	 * FS_VERITY_HASH_ALG_*, which uses a different numbering scheme.
	 */
	enum hash_algo algo_id;
};

union fsverity_hash_ctx {
	struct sha256_ctx sha256;
	struct sha512_ctx sha512;
};

/* Merkle tree parameters: hash algorithm, initial hash state, and topology */
struct merkle_tree_params {
	const struct fsverity_hash_alg *hash_alg; /* the hash algorithm */
	/* initial hash state if salted, NULL if unsalted */
	const union fsverity_hash_ctx *hashstate;
	unsigned int digest_size;	/* same as hash_alg->digest_size */
	unsigned int block_size;	/* size of data and tree blocks */
	unsigned int hashes_per_block;	/* number of hashes per tree block */
	unsigned int blocks_per_page;	/* PAGE_SIZE / block_size */
	u8 log_digestsize;		/* log2(digest_size) */
	u8 log_blocksize;		/* log2(block_size) */
	u8 log_arity;			/* log2(hashes_per_block) */
	u8 log_blocks_per_page;		/* log2(blocks_per_page) */
	unsigned int num_levels;	/* number of levels in Merkle tree */
	u64 tree_size;			/* Merkle tree size in bytes */
	unsigned long tree_pages;	/* Merkle tree size in pages */

	/* the hash of an all-zeroes block */
	u8 zero_digest[FS_VERITY_MAX_DIGEST_SIZE];

	/*
	 * Starting block index for each tree level, ordered from leaf level (0)
	 * to root level ('num_levels - 1')
	 */
	unsigned long level_start[FS_VERITY_MAX_LEVELS];
};

/*
 * fsverity_info - cached verity metadata for an inode
 *
 * When a verity file is first opened, an instance of this struct is allocated
 * and a pointer to it is stored in the global hash table, indexed by the inode
 * pointer value.  It remains alive until the inode is evicted.  It caches
 * information about the Merkle tree that's needed to efficiently verify data
 * read from the file.  It also caches the file digest.  The Merkle tree pages
 * themselves are not cached here, but the filesystem may cache them.
 */
struct fsverity_info {
	struct rhash_head rhash_head;
	struct merkle_tree_params tree_params;
	u8 root_hash[FS_VERITY_MAX_DIGEST_SIZE];
	u8 file_digest[FS_VERITY_MAX_DIGEST_SIZE];
	struct inode *inode;
	unsigned long *hash_block_verified;
};

#define FS_VERITY_MAX_SIGNATURE_SIZE	(FS_VERITY_MAX_DESCRIPTOR_SIZE - \
					 sizeof(struct fsverity_descriptor))

/* hash_algs.c */

extern const struct fsverity_hash_alg fsverity_hash_algs[];

const struct fsverity_hash_alg *fsverity_get_hash_alg(const struct inode *inode,
						      unsigned int num);
union fsverity_hash_ctx *
fsverity_prepare_hash_state(const struct fsverity_hash_alg *alg,
			    const u8 *salt, size_t salt_size);
void fsverity_hash_block(const struct merkle_tree_params *params,
			 const void *data, u8 *out);
void fsverity_hash_buffer(const struct fsverity_hash_alg *alg,
			  const void *data, size_t size, u8 *out);
void __init fsverity_check_hash_algs(void);

/* init.c */

void __printf(3, 4) __cold
fsverity_msg(const struct inode *inode, const char *level,
	     const char *fmt, ...);

#define fsverity_warn(inode, fmt, ...)		\
	fsverity_msg((inode), KERN_WARNING, fmt, ##__VA_ARGS__)
#define fsverity_err(inode, fmt, ...)		\
	fsverity_msg((inode), KERN_ERR, fmt, ##__VA_ARGS__)

Annotation

Implementation Notes