From: Eric Biggers <ebiggers3@gmail.com>
To: linux-fscrypt@vger.kernel.org
Cc: "Theodore Y . Ts'o" <tytso@mit.edu>,
Eric Biggers <ebiggers@google.com>,
Michael Halcrow <mhalcrow@google.com>,
linux-f2fs-devel@lists.sourceforge.net,
linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org,
Jaegeuk Kim <jaegeuk@kernel.org>,
linux-ext4@vger.kernel.org
Subject: [PATCH 10/25] fscrypt: new helper function - fscrypt_prepare_setattr()
Date: Wed, 20 Sep 2017 15:45:50 -0700 [thread overview]
Message-ID: <20170920224605.22030-11-ebiggers3@gmail.com> (raw)
In-Reply-To: <20170920224605.22030-1-ebiggers3@gmail.com>
From: Eric Biggers <ebiggers@google.com>
Introduce a helper function for filesystems to call when processing
->setattr() on a possibly-encrypted inode. It handles enforcing that an
encrypted file can only be truncated if its encryption key is available.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
include/linux/fscrypt_notsupp.h | 8 ++++++++
include/linux/fscrypt_supp.h | 25 +++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/include/linux/fscrypt_notsupp.h b/include/linux/fscrypt_notsupp.h
index e9b437605f9c..b0dd2d1756b2 100644
--- a/include/linux/fscrypt_notsupp.h
+++ b/include/linux/fscrypt_notsupp.h
@@ -218,4 +218,12 @@ static inline int fscrypt_prepare_lookup(struct inode *dir,
return 0;
}
+static inline int fscrypt_prepare_setattr(struct dentry *dentry,
+ struct iattr *attr)
+{
+ if (IS_ENCRYPTED(d_inode(dentry)) && (attr->ia_valid & ATTR_SIZE))
+ return -EOPNOTSUPP;
+ return 0;
+}
+
#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
diff --git a/include/linux/fscrypt_supp.h b/include/linux/fscrypt_supp.h
index 2b99bc01c59b..bdd01e02435b 100644
--- a/include/linux/fscrypt_supp.h
+++ b/include/linux/fscrypt_supp.h
@@ -270,4 +270,29 @@ static inline int fscrypt_prepare_lookup(struct inode *dir,
return 0;
}
+/**
+ * fscrypt_prepare_setattr - prepare to change a possibly-encrypted inode's attributes
+ * @dentry: dentry through which the inode is being changed
+ * @attr: attributes to change
+ *
+ * Prepare for ->setattr() on a possibly-encrypted inode. On an encrypted file,
+ * most attribute changes are allowed even without the encryption key. However,
+ * without the encryption key we do have to forbid truncates. This is needed
+ * because the size being truncated to may not be a multiple of the filesystem
+ * block size, and in that case we'd have to decrypt the final block, zero the
+ * portion past i_size, and re-encrypt it. (We *could* allow truncating to a
+ * filesystem block boundary, but it's simpler to just forbid all truncates ---
+ * and we already forbid all other contents modifications without the key.)
+ *
+ * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code
+ * if a problem occurred while setting up the encryption key.
+ */
+static inline int fscrypt_prepare_setattr(struct dentry *dentry,
+ struct iattr *attr)
+{
+ if (IS_ENCRYPTED(d_inode(dentry)) && (attr->ia_valid & ATTR_SIZE))
+ return fscrypt_require_key(d_inode(dentry));
+ return 0;
+}
+
#endif /* _LINUX_FSCRYPT_SUPP_H */
--
2.14.1.821.g8fa685d3b7-goog
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
next prev parent reply other threads:[~2017-09-20 22:47 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-20 22:45 [PATCH 00/25] fscrypt: add some higher-level helper functions Eric Biggers
2017-09-20 22:45 ` [PATCH 01/25] fs, fscrypt: add an S_ENCRYPTED inode flag Eric Biggers
2017-09-20 22:45 ` [PATCH 02/25] fscrypt: switch from ->is_encrypted() to IS_ENCRYPTED() Eric Biggers
2017-09-20 22:45 ` [PATCH 03/25] fscrypt: remove ->is_encrypted() Eric Biggers
2017-09-20 22:45 ` [PATCH 04/25] fscrypt: remove unneeded empty fscrypt_operations structs Eric Biggers
2017-09-20 22:45 ` [PATCH 05/25] fscrypt: new helper function - fscrypt_require_key() Eric Biggers
2017-09-20 22:45 ` [PATCH 06/25] fscrypt: new helper function - fscrypt_file_open() Eric Biggers
2017-09-20 22:45 ` [PATCH 07/25] fscrypt: new helper function - fscrypt_prepare_link() Eric Biggers
2017-09-20 22:45 ` [PATCH 08/25] fscrypt: new helper function - fscrypt_prepare_rename() Eric Biggers
2017-09-20 22:45 ` [PATCH 09/25] fscrypt: new helper function - fscrypt_prepare_lookup() Eric Biggers
2017-09-20 22:45 ` Eric Biggers [this message]
2017-09-20 22:45 ` [PATCH 11/25] ext4: switch to fscrypt_file_open() Eric Biggers
2017-09-20 22:45 ` [PATCH 12/25] ext4: switch to fscrypt_prepare_link() Eric Biggers
2017-09-20 22:45 ` [PATCH 13/25] ext4: switch to fscrypt_prepare_rename() Eric Biggers
2017-09-20 22:45 ` [PATCH 14/25] ext4: switch to fscrypt_prepare_lookup() Eric Biggers
2017-09-20 22:45 ` [PATCH 15/25] ext4: switch to fscrypt_prepare_setattr() Eric Biggers
2017-09-20 22:45 ` [PATCH 16/25] f2fs: switch to fscrypt_file_open() Eric Biggers
2017-09-20 22:45 ` [PATCH 17/25] f2fs: switch to fscrypt_prepare_link() Eric Biggers
2017-09-20 22:45 ` [PATCH 18/25] f2fs: switch to fscrypt_prepare_rename() Eric Biggers
2017-09-20 22:45 ` [PATCH 19/25] f2fs: switch to fscrypt_prepare_lookup() Eric Biggers
2017-09-20 22:46 ` [PATCH 20/25] f2fs: switch to fscrypt_prepare_setattr() Eric Biggers
2017-09-20 22:46 ` [PATCH 21/25] ubifs: switch to fscrypt_file_open() Eric Biggers
2017-09-20 22:46 ` [PATCH 22/25] ubifs: switch to fscrypt_prepare_link() Eric Biggers
2017-09-20 22:46 ` [PATCH 23/25] ubifs: switch to fscrypt_prepare_rename() Eric Biggers
2017-09-20 22:46 ` [PATCH 24/25] ubifs: switch to fscrypt_prepare_lookup() Eric Biggers
2017-09-20 22:46 ` [PATCH 25/25] ubifs: switch to fscrypt_prepare_setattr() Eric Biggers
2017-09-21 6:45 ` [PATCH 00/25] fscrypt: add some higher-level helper functions Dave Chinner
2017-09-21 17:47 ` Eric Biggers
2017-09-21 20:48 ` Dave Chinner
2017-09-21 14:19 ` [f2fs-dev] " Chao Yu
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=20170920224605.22030-11-ebiggers3@gmail.com \
--to=ebiggers3@gmail.com \
--cc=ebiggers@google.com \
--cc=jaegeuk@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fscrypt@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=mhalcrow@google.com \
--cc=tytso@mit.edu \
/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).