From: Roberto Sassu <roberto.sassu@huawei.com>
To: <ebiggers@kernel.org>, <tytso@mit.edu>, <corbet@lwn.net>,
<viro@zeniv.linux.org.uk>, <hughd@google.com>,
<akpm@linux-foundation.org>
Cc: <linux-fscrypt@vger.kernel.org>, <linux-doc@vger.kernel.org>,
<linux-fsdevel@vger.kernel.org>, <linux-mm@kvack.org>,
<linux-integrity@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Roberto Sassu <roberto.sassu@huawei.com>
Subject: [RFC][PATCH 1/5] fsverity: Introduce fsverity_get_file_digest()
Date: Fri, 12 Nov 2021 13:44:07 +0100 [thread overview]
Message-ID: <20211112124411.1948809-2-roberto.sassu@huawei.com> (raw)
In-Reply-To: <20211112124411.1948809-1-roberto.sassu@huawei.com>
Since the fsverity_info structure is defined internally in fsverity, expose
the fsverity file digest through the new function
fsverity_get_file_digest().
Given that an fsverity file is guaranteed to be immutable, also the
retrieved file digest is stable and won't change.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
fs/verity/open.c | 24 ++++++++++++++++++++++++
include/linux/fsverity.h | 10 ++++++++++
2 files changed, 34 insertions(+)
diff --git a/fs/verity/open.c b/fs/verity/open.c
index 92df87f5fa38..9127c77c6539 100644
--- a/fs/verity/open.c
+++ b/fs/verity/open.c
@@ -218,6 +218,30 @@ void fsverity_free_info(struct fsverity_info *vi)
kmem_cache_free(fsverity_info_cachep, vi);
}
+/*
+ * Copy the file digest and associated algorithm taken from the passed
+ * fsverity_info structure to the locations supplied by the caller.
+ *
+ * Return: the digest size on success, a negative value on error
+ */
+ssize_t fsverity_get_file_digest(struct fsverity_info *info, u8 *buf,
+ size_t bufsize, enum hash_algo *algo)
+{
+ enum hash_algo a;
+
+ a = match_string(hash_algo_name, HASH_ALGO__LAST,
+ info->tree_params.hash_alg->name);
+ if (a < 0)
+ return a;
+
+ if (bufsize < hash_digest_size[a])
+ return -ERANGE;
+
+ *algo = a;
+ memcpy(buf, info->file_digest, hash_digest_size[*algo]);
+ return hash_digest_size[*algo];
+}
+
static bool validate_fsverity_descriptor(struct inode *inode,
const struct fsverity_descriptor *desc,
size_t desc_size)
diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h
index b568b3c7d095..877a7f609dd9 100644
--- a/include/linux/fsverity.h
+++ b/include/linux/fsverity.h
@@ -13,6 +13,7 @@
#include <linux/fs.h>
#include <uapi/linux/fsverity.h>
+#include <crypto/hash_info.h>
/* Verity operations for filesystems */
struct fsverity_operations {
@@ -137,6 +138,8 @@ int fsverity_ioctl_measure(struct file *filp, void __user *arg);
int fsverity_file_open(struct inode *inode, struct file *filp);
int fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr);
void fsverity_cleanup_inode(struct inode *inode);
+ssize_t fsverity_get_file_digest(struct fsverity_info *info, u8 *buf,
+ size_t bufsize, enum hash_algo *algo);
/* read_metadata.c */
@@ -187,6 +190,13 @@ static inline void fsverity_cleanup_inode(struct inode *inode)
{
}
+static inline ssize_t fsverity_get_file_digest(struct fsverity_info *info,
+ u8 *buf, size_t bufsize,
+ enum hash_algo *algo)
+{
+ return -EOPNOTSUPP;
+}
+
/* read_metadata.c */
static inline int fsverity_ioctl_read_metadata(struct file *filp,
--
2.32.0
next prev parent reply other threads:[~2021-11-12 12:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-12 12:44 [RFC][PATCH 0/5] shmem/fsverity: Prepare for mandatory integrity enforcement Roberto Sassu
2021-11-12 12:44 ` Roberto Sassu [this message]
2021-11-12 12:44 ` [RFC][PATCH 2/5] fsverity: Revalidate built-in signatures at file open Roberto Sassu
2021-11-12 19:15 ` Eric Biggers
2021-11-15 9:42 ` Roberto Sassu
2021-11-12 12:44 ` [RFC][PATCH 3/5] fsverity: Do initialization earlier Roberto Sassu
2021-11-12 12:44 ` [RFC][PATCH 4/5] shmem: Avoid segfault in shmem_read_mapping_page_gfp() Roberto Sassu
2021-11-12 12:53 ` Ajay Garg
2021-11-12 12:56 ` Roberto Sassu
2021-11-12 18:56 ` Eric Biggers
2021-11-15 8:02 ` Roberto Sassu
2021-11-12 12:44 ` [RFC][PATCH 5/5] shmem: Add fsverity support Roberto Sassu
2021-11-12 19:12 ` Eric Biggers
2021-11-15 8:49 ` Roberto Sassu
2021-11-15 19:05 ` Eric Biggers
2021-11-16 10:43 ` Roberto Sassu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211112124411.1948809-2-roberto.sassu@huawei.com \
--to=roberto.sassu@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=ebiggers@kernel.org \
--cc=hughd@google.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).