From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
dedekind1@gmail.com, adrian.hunter@intel.com, tytso@mit.edu,
jaegeuk@kernel.org, david@sigma-star.at, wd@denx.de,
sbabic@denx.de, dengler@linutronix.de,
Richard Weinberger <richard@nod.at>
Subject: [PATCH 01/26] fscrypto: Add buffer operations
Date: Fri, 21 Oct 2016 14:48:16 +0200 [thread overview]
Message-ID: <1477054121-10198-2-git-send-email-richard@nod.at> (raw)
In-Reply-To: <1477054121-10198-1-git-send-email-richard@nod.at>
Not all filesystems operate on pages, therefore offer
operations to en/decrypt buffers.
Of course these buffers have to be allocated in a way such that
the kernel crypto framework can work with them.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
fs/crypto/crypto.c | 63 +++++++++++++++++++++++++++++++++++++++---------
include/linux/fscrypto.h | 24 ++++++++++++++++++
2 files changed, 76 insertions(+), 11 deletions(-)
diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index c502c116924c..1c2f9516b4be 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -147,15 +147,14 @@ typedef enum {
FS_ENCRYPT,
} fscrypt_direction_t;
-static int do_page_crypto(struct inode *inode,
- fscrypt_direction_t rw, pgoff_t index,
- struct page *src_page, struct page *dest_page,
- gfp_t gfp_flags)
+static int do_crypto(struct inode *inode,
+ fscrypt_direction_t rw, pgoff_t index,
+ struct scatterlist *src, struct scatterlist *dst,
+ unsigned int cryptlen, gfp_t gfp_flags)
{
u8 xts_tweak[FS_XTS_TWEAK_SIZE];
struct skcipher_request *req = NULL;
DECLARE_FS_COMPLETION_RESULT(ecr);
- struct scatterlist dst, src;
struct fscrypt_info *ci = inode->i_crypt_info;
struct crypto_skcipher *tfm = ci->ci_ctfm;
int res = 0;
@@ -177,12 +176,8 @@ static int do_page_crypto(struct inode *inode,
memset(&xts_tweak[sizeof(index)], 0,
FS_XTS_TWEAK_SIZE - sizeof(index));
- sg_init_table(&dst, 1);
- sg_set_page(&dst, dest_page, PAGE_SIZE, 0);
- sg_init_table(&src, 1);
- sg_set_page(&src, src_page, PAGE_SIZE, 0);
- skcipher_request_set_crypt(req, &src, &dst, PAGE_SIZE,
- xts_tweak);
+ skcipher_request_set_crypt(req, src, dst, cryptlen,
+ xts_tweak);
if (rw == FS_DECRYPT)
res = crypto_skcipher_decrypt(req);
else
@@ -202,6 +197,34 @@ static int do_page_crypto(struct inode *inode,
return 0;
}
+static int do_page_crypto(struct inode *inode,
+ fscrypt_direction_t rw, pgoff_t index,
+ struct page *src_page, struct page *dst_page,
+ gfp_t gfp_flags)
+{
+ struct scatterlist src, dst;
+
+ sg_init_table(&src, 1);
+ sg_set_page(&src, src_page, PAGE_SIZE, 0);
+ sg_init_table(&dst, 1);
+ sg_set_page(&dst, dst_page, PAGE_SIZE, 0);
+
+ return do_crypto(inode, rw, index, &src, &dst, PAGE_SIZE, gfp_flags);
+}
+
+static int do_buf_crypto(struct inode *inode,
+ fscrypt_direction_t rw, pgoff_t index,
+ const void *src_buf, const void *dst_buf,
+ unsigned int buflen, gfp_t gfp_flags)
+{
+ struct scatterlist src, dst;
+
+ sg_init_one(&src, src_buf, buflen);
+ sg_init_one(&dst, dst_buf, buflen);
+
+ return do_crypto(inode, rw, index, &src, &dst, buflen, gfp_flags);
+}
+
static struct page *alloc_bounce_page(struct fscrypt_ctx *ctx, gfp_t gfp_flags)
{
ctx->w.bounce_page = mempool_alloc(fscrypt_bounce_page_pool, gfp_flags);
@@ -264,6 +287,24 @@ errout:
}
EXPORT_SYMBOL(fscrypt_encrypt_page);
+int fscrypt_encrypt_buffer(struct inode *inode, const void *plaintext_buf,
+ const void *ciphertext_buf, unsigned int buflen,
+ pgoff_t index, gfp_t gfp_flags)
+{
+ return do_buf_crypto(inode, FS_ENCRYPT, index, plaintext_buf,
+ ciphertext_buf, buflen, gfp_flags);
+}
+EXPORT_SYMBOL(fscrypt_encrypt_buffer);
+
+int fscrypt_decrypt_buffer(struct inode *inode, const void *ciphertext_buf,
+ const void *plaintext_buf, unsigned int buflen,
+ pgoff_t index, gfp_t gfp_flags)
+{
+ return do_buf_crypto(inode, FS_DECRYPT, index, ciphertext_buf,
+ plaintext_buf, buflen, gfp_flags);
+}
+EXPORT_SYMBOL(fscrypt_decrypt_buffer);
+
/**
* f2crypt_decrypt_page() - Decrypts a page in-place
* @page: The page to decrypt. Must be locked.
diff --git a/include/linux/fscrypto.h b/include/linux/fscrypto.h
index 76cff18bb032..a9628b4882e7 100644
--- a/include/linux/fscrypto.h
+++ b/include/linux/fscrypto.h
@@ -273,6 +273,12 @@ extern void fscrypt_pullback_bio_page(struct page **, bool);
extern void fscrypt_restore_control_page(struct page *);
extern int fscrypt_zeroout_range(struct inode *, pgoff_t, sector_t,
unsigned int);
+int fscrypt_encrypt_buffer(struct inode *inode, const void *plaintext_buf,
+ const void *ciphertext_buf, unsigned int buflen,
+ pgoff_t index, gfp_t gfp_flags);
+int fscrypt_decrypt_buffer(struct inode *inode, const void *ciphertext_buf,
+ const void *plaintext_buf, unsigned int buflen,
+ pgoff_t index, gfp_t gfp_flags);
/* policy.c */
extern int fscrypt_process_policy(struct file *, const struct fscrypt_policy *);
extern int fscrypt_get_policy(struct inode *, struct fscrypt_policy *);
@@ -418,6 +424,24 @@ static inline void fscrypt_notsupp_fname_free_buffer(struct fscrypt_str *c)
return;
}
+static inline int fscrypt_notsupp_encrypt_buffer(const struct inode *inode,
+ const void *plaintext_buf,
+ const void *ciphertext_buf,
+ unsigned int buflen,
+ pgoff_t index, gfp_t gfp_flags)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int fscrypt_notsupp_decrypt_buffer(const struct inode *inode,
+ const void *ciphertext_buf,
+ const void *plaintext_buf,
+ unsigned int buflen,
+ pgoff_t index, gfp_t gfp_flags)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int fscrypt_notsupp_fname_disk_to_usr(struct inode *inode,
u32 hash, u32 minor_hash,
const struct fscrypt_str *iname,
--
2.7.3
next prev parent reply other threads:[~2016-10-21 12:49 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-21 12:48 [PATCH 00/26] UBIFS File Encryption Richard Weinberger
2016-10-21 12:48 ` Richard Weinberger [this message]
2016-10-21 13:05 ` [PATCH 01/26] fscrypto: Add buffer operations Christoph Hellwig
2016-10-21 13:17 ` Richard Weinberger
2016-10-21 13:24 ` Christoph Hellwig
2016-10-21 15:14 ` Theodore Ts'o
2016-10-24 7:05 ` Richard Weinberger
2016-10-21 12:48 ` [PATCH 02/26] fscrypto: Constify struct inode pointer Richard Weinberger
2016-10-21 14:57 ` Theodore Ts'o
2016-10-21 15:10 ` Richard Weinberger
2016-10-21 12:48 ` [PATCH 03/26] ubifs: Export ubifs_check_dir_empty() Richard Weinberger
2016-10-21 12:48 ` [PATCH 04/26] ubifs: Export xattr get and set functions Richard Weinberger
2016-10-21 12:48 ` [PATCH 05/26] ubifs: Define UBIFS crypto context xattr Richard Weinberger
2016-10-21 12:48 ` [PATCH 06/26] ubifs: Add skeleton for fscrypto Richard Weinberger
2016-10-21 12:48 ` [PATCH 07/26] ubifs: Massage ubifs_listxattr() for encryption context Richard Weinberger
2016-10-21 12:48 ` [PATCH 08/26] ubifs: Implement directory open operation Richard Weinberger
2016-10-21 12:48 ` [PATCH 09/26] ubifs: Implement file " Richard Weinberger
2016-10-21 12:48 ` [PATCH 10/26] ubifs: Enforce crypto policy in ->link and ->rename Richard Weinberger
2016-10-21 12:48 ` [PATCH 11/26] ubifs: Preload crypto context in ->lookup() Richard Weinberger
2016-10-21 12:48 ` [PATCH 12/26] ubifs: Massage assert in ubifs_xattr_set() wrt. fscrypto Richard Weinberger
2016-10-21 12:48 ` [PATCH 13/26] ubifs: Enforce crypto policy in mmap Richard Weinberger
2016-10-21 12:48 ` [PATCH 14/26] ubifs: Introduce new data node field, compr_size Richard Weinberger
2016-10-21 12:48 ` [PATCH 15/26] ubifs: Implement encrypt/decrypt for all IO Richard Weinberger
2016-10-21 17:14 ` Michael Halcrow
2016-10-21 17:21 ` Richard Weinberger
2016-10-21 17:52 ` Michael Halcrow
2016-10-21 18:21 ` Richard Weinberger
2016-10-21 18:25 ` Eric Biggers
2016-10-24 7:00 ` Richard Weinberger
2016-10-21 12:48 ` [PATCH 16/26] ubifs: Relax checks in ubifs_validate_entry() Richard Weinberger
2016-10-21 12:48 ` [PATCH 17/26] ubifs: Make r5 hash binary string aware Richard Weinberger
2016-10-21 12:48 ` [PATCH 18/26] ubifs: Constify struct inode pointer in ubifs_crypt_is_encrypted() Richard Weinberger
2016-10-21 12:48 ` [PATCH 19/26] ubifs: Implement encrypted filenames Richard Weinberger
2016-10-21 12:48 ` [PATCH 20/26] ubifs: Add support for encrypted symlinks Richard Weinberger
2016-10-21 18:42 ` Eric Biggers
2016-10-24 6:54 ` Richard Weinberger
2016-10-21 12:48 ` [PATCH 21/26] ubifs: Rename tnc_read_node_nm Richard Weinberger
2016-10-21 12:48 ` [PATCH 22/26] ubifs: Add full hash lookup support Richard Weinberger
2016-10-21 12:48 ` [PATCH 23/26] ubifs: Use a random number for cookies Richard Weinberger
2016-10-21 12:48 ` [PATCH 24/26] ubifs: Implement UBIFS_FLG_DOUBLE_HASH Richard Weinberger
2016-10-21 12:48 ` [PATCH 25/26] ubifs: Implement UBIFS_FLG_ENCRYPTION Richard Weinberger
2016-10-21 18:30 ` Eric Biggers
2016-10-24 6:59 ` Richard Weinberger
2016-10-24 13:48 ` Theodore Ts'o
2016-10-21 12:48 ` [PATCH 26/26] ubifs: Raise write version to 5 Richard Weinberger
2016-10-21 17:31 ` Michael Halcrow
2016-10-21 17:47 ` Theodore Ts'o
2016-10-21 18:19 ` Eric Biggers
2016-10-21 22:34 ` Theodore Ts'o
2016-10-24 7:03 ` Richard Weinberger
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=1477054121-10198-2-git-send-email-richard@nod.at \
--to=richard@nod.at \
--cc=adrian.hunter@intel.com \
--cc=david@sigma-star.at \
--cc=dedekind1@gmail.com \
--cc=dengler@linutronix.de \
--cc=jaegeuk@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=sbabic@denx.de \
--cc=tytso@mit.edu \
--cc=wd@denx.de \
/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
all inboxes | Powered by JetHome®