History

fs-verity: add the hook for file ->open()

Add the fsverity_file_open() function, which prepares an fs-verity file to be read from. If not already done, it loads the fs-verity descriptor from the filesystem and sets up an fsverity_info structure for the inode which describes the Merkle tree and contains the file measurement. It also denies all attempts to open verity files for writing. This commit also begins the include/linux/fsverity.h header, which declares the interface between fs/verity/ and filesystems.

Eric Biggers committed 7 years ago

Commit fd2d1ac1 parent 5585f2a5 files · +449 −3Browse files

Showing the changes to include/linux (1 of 5 files). Show all

Unified · Split

include/linux/fsverity.h+71−0
@@ -0,0 +1,71 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+/*
3+ * fs-verity: read-only file-based authenticity protection
4+ *
5+ * This header declares the interface between the fs/verity/ support layer and
6+ * filesystems that support fs-verity.
7+ *
8+ * Copyright 2019 Google LLC
9+ */
10+
11+#ifndef _LINUX_FSVERITY_H
12+#define _LINUX_FSVERITY_H
13+
14+#include <linux/fs.h>
15+#include <uapi/linux/fsverity.h>
16+
17+/* Verity operations for filesystems */
18+struct fsverity_operations {
19+
20+ /**
21+ * Get the verity descriptor of the given inode.
22+ *
23+ * @inode: an inode with the S_VERITY flag set
24+ * @buf: buffer in which to place the verity descriptor
25+ * @bufsize: size of @buf, or 0 to retrieve the size only
26+ *
27+ * If bufsize == 0, then the size of the verity descriptor is returned.
28+ * Otherwise the verity descriptor is written to 'buf' and its actual
29+ * size is returned; -ERANGE is returned if it's too large. This may be
30+ * called by multiple processes concurrently on the same inode.
31+ *
32+ * Return: the size on success, -errno on failure
33+ */
34+ int (*get_verity_descriptor)(struct inode *inode, void *buf,
35+ size_t bufsize);
36+};
37+
38+#ifdef CONFIG_FS_VERITY
39+
40+static inline struct fsverity_info *fsverity_get_info(const struct inode *inode)
41+{
42+ /* pairs with the cmpxchg() in fsverity_set_info() */
43+ return READ_ONCE(inode->i_verity_info);
44+}
45+
46+/* open.c */
47+
48+extern int fsverity_file_open(struct inode *inode, struct file *filp);
49+extern void fsverity_cleanup_inode(struct inode *inode);
50+
51+#else /* !CONFIG_FS_VERITY */
52+
53+static inline struct fsverity_info *fsverity_get_info(const struct inode *inode)
54+{
55+ return NULL;
56+}
57+
58+/* open.c */
59+
60+static inline int fsverity_file_open(struct inode *inode, struct file *filp)
61+{
62+ return IS_VERITY(inode) ? -EOPNOTSUPP : 0;
63+}
64+
65+static inline void fsverity_cleanup_inode(struct inode *inode)
66+{
67+}
68+
69+#endif /* !CONFIG_FS_VERITY */
70+
71+#endif /* _LINUX_FSVERITY_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t