From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, tytso@mit.edu
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [PATCH 09/10] f2fs crypto: sync ext4_lookup and ext4_file_open
Date: Wed, 2 Mar 2016 10:31:17 -0800 [thread overview]
Message-ID: <1456943478-11107-10-git-send-email-jaegeuk@kernel.org> (raw)
In-Reply-To: <1456943478-11107-1-git-send-email-jaegeuk@kernel.org>
This patch tries to catch up with lookup and open policies in ext4.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/dir.c | 2 +-
fs/f2fs/file.c | 4 ++++
fs/f2fs/namei.c | 23 +++++++++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index f82e28b..479467e 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -855,7 +855,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
if (f2fs_encrypted_inode(inode)) {
err = fscrypt_get_encryption_info(inode);
- if (err)
+ if (err && err != -ENOKEY)
return err;
err = fscrypt_fname_alloc_buffer(inode, F2FS_NAME_LEN, &fstr);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index f326764..533c2dc 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -441,6 +441,7 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
static int f2fs_file_open(struct inode *inode, struct file *filp)
{
int ret = generic_file_open(inode, filp);
+ struct inode *dir = filp->f_path.dentry->d_parent->d_inode;
if (!ret && f2fs_encrypted_inode(inode)) {
ret = fscrypt_get_encryption_info(inode);
@@ -449,6 +450,9 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
if (!f2fs_encrypted_inode(inode))
return -ENOKEY;
}
+ if (f2fs_encrypted_inode(dir) &&
+ !fscrypt_has_permitted_context(dir, inode))
+ return -EPERM;
return ret;
}
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 3bddd9f..7b07a47 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -262,6 +262,21 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
int err = 0;
unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
+ if (f2fs_encrypted_inode(dir)) {
+ int res = fscrypt_get_encryption_info(dir);
+
+ /*
+ * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is
+ * created while the directory was encrypted and we
+ * don't have access to the key.
+ */
+ if (fscrypt_has_encryption_key(dir))
+ fscrypt_set_encrypted_dentry(dentry);
+ fscrypt_set_d_op(dentry);
+ if (res && res != -ENOKEY)
+ return ERR_PTR(res);
+ }
+
if (dentry->d_name.len > F2FS_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG);
@@ -288,6 +303,14 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
if (err)
goto err_out;
}
+ if (!IS_ERR(inode) && f2fs_encrypted_inode(dir) &&
+ (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
+ !fscrypt_has_permitted_context(dir, inode)) {
+ bool nokey = f2fs_encrypted_inode(inode) &&
+ !fscrypt_has_encryption_key(inode);
+ iput(inode);
+ return nokey ? ERR_PTR(-ENOKEY) : ERR_PTR(-EPERM);
+ }
return d_splice_alias(inode, dentry);
err_out:
--
2.6.3
next prev parent reply other threads:[~2016-03-02 18:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-02 18:31 [PATCH v3 00/10] File-level Encryption Support by VFS Jaegeuk Kim
2016-03-02 18:31 ` [PATCH 01/10] fs crypto: add basic definitions for per-file encryption Jaegeuk Kim
2016-03-02 18:31 ` [PATCH 02/10] fs crypto: add crypto.c for encrypt/decrypt functions Jaegeuk Kim
2016-03-02 18:31 ` [PATCH 03/10] fs crypto: add policy.c to handle contexts Jaegeuk Kim
2016-03-02 18:31 ` [PATCH 04/10] fs crypto: add keyinfo.c to handle permissions Jaegeuk Kim
2016-03-02 18:31 ` [PATCH 05/10] fs crypto: add fname.c to support filename encryption Jaegeuk Kim
2016-03-02 18:31 ` [PATCH 06/10] fs crypto: add Makefile and Kconfig Jaegeuk Kim
2016-03-02 18:31 ` [PATCH 07/10] fs crypto: add dentry revalidation facility in crypto Jaegeuk Kim
2016-03-02 18:31 ` [PATCH 08/10] f2fs crypto: migrate into vfs's crypto engine Jaegeuk Kim
2016-03-02 18:31 ` Jaegeuk Kim [this message]
2016-03-02 18:31 ` [PATCH 10/10] ext4 " Jaegeuk Kim
-- strict thread matches above, loose matches on Subject: below --
2016-02-25 19:25 [PATCH 00/10 v2] File-level Encryption Support by VFS Jaegeuk Kim
2016-02-25 19:26 ` [PATCH 09/10] f2fs crypto: sync ext4_lookup and ext4_file_open Jaegeuk Kim
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=1456943478-11107-10-git-send-email-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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).