diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2016-02-23 12:21:37 -0500 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2016-03-18 00:19:42 -0400 |
commit | 8074bb515014d281a6f5f1218648aa3abd9c22ab (patch) | |
tree | e40dc1a7d5d8f7bf26d911169c9b1ddd1c3752d7 /fs | |
parent | 0b81d0779072696371822e5ed9e7c6292e547024 (diff) |
f2fs crypto: sync ext4_lookup and ext4_file_open
This patch tries to catch up with lookup and open policies in ext4.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/f2fs/dir.c | 2 | ||||
-rw-r--r-- | fs/f2fs/file.c | 4 | ||||
-rw-r--r-- | fs/f2fs/namei.c | 23 |
3 files changed, 28 insertions, 1 deletions
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index f82e28b121a8..479467e442ea 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) | |||
855 | 855 | ||
856 | if (f2fs_encrypted_inode(inode)) { | 856 | if (f2fs_encrypted_inode(inode)) { |
857 | err = fscrypt_get_encryption_info(inode); | 857 | err = fscrypt_get_encryption_info(inode); |
858 | if (err) | 858 | if (err && err != -ENOKEY) |
859 | return err; | 859 | return err; |
860 | 860 | ||
861 | err = fscrypt_fname_alloc_buffer(inode, F2FS_NAME_LEN, &fstr); | 861 | err = fscrypt_fname_alloc_buffer(inode, F2FS_NAME_LEN, &fstr); |
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 04ab1e4fc1df..b41c3579ea9e 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) | |||
441 | static int f2fs_file_open(struct inode *inode, struct file *filp) | 441 | static int f2fs_file_open(struct inode *inode, struct file *filp) |
442 | { | 442 | { |
443 | int ret = generic_file_open(inode, filp); | 443 | int ret = generic_file_open(inode, filp); |
444 | struct inode *dir = filp->f_path.dentry->d_parent->d_inode; | ||
444 | 445 | ||
445 | if (!ret && f2fs_encrypted_inode(inode)) { | 446 | if (!ret && f2fs_encrypted_inode(inode)) { |
446 | ret = fscrypt_get_encryption_info(inode); | 447 | ret = fscrypt_get_encryption_info(inode); |
@@ -449,6 +450,9 @@ static int f2fs_file_open(struct inode *inode, struct file *filp) | |||
449 | if (!fscrypt_has_encryption_key(inode)) | 450 | if (!fscrypt_has_encryption_key(inode)) |
450 | return -ENOKEY; | 451 | return -ENOKEY; |
451 | } | 452 | } |
453 | if (f2fs_encrypted_inode(dir) && | ||
454 | !fscrypt_has_permitted_context(dir, inode)) | ||
455 | return -EPERM; | ||
452 | return ret; | 456 | return ret; |
453 | } | 457 | } |
454 | 458 | ||
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 3bddd9f657e5..7b07a4799952 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, | |||
262 | int err = 0; | 262 | int err = 0; |
263 | unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir)); | 263 | unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir)); |
264 | 264 | ||
265 | if (f2fs_encrypted_inode(dir)) { | ||
266 | int res = fscrypt_get_encryption_info(dir); | ||
267 | |||
268 | /* | ||
269 | * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is | ||
270 | * created while the directory was encrypted and we | ||
271 | * don't have access to the key. | ||
272 | */ | ||
273 | if (fscrypt_has_encryption_key(dir)) | ||
274 | fscrypt_set_encrypted_dentry(dentry); | ||
275 | fscrypt_set_d_op(dentry); | ||
276 | if (res && res != -ENOKEY) | ||
277 | return ERR_PTR(res); | ||
278 | } | ||
279 | |||
265 | if (dentry->d_name.len > F2FS_NAME_LEN) | 280 | if (dentry->d_name.len > F2FS_NAME_LEN) |
266 | return ERR_PTR(-ENAMETOOLONG); | 281 | return ERR_PTR(-ENAMETOOLONG); |
267 | 282 | ||
@@ -288,6 +303,14 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, | |||
288 | if (err) | 303 | if (err) |
289 | goto err_out; | 304 | goto err_out; |
290 | } | 305 | } |
306 | if (!IS_ERR(inode) && f2fs_encrypted_inode(dir) && | ||
307 | (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) && | ||
308 | !fscrypt_has_permitted_context(dir, inode)) { | ||
309 | bool nokey = f2fs_encrypted_inode(inode) && | ||
310 | !fscrypt_has_encryption_key(inode); | ||
311 | iput(inode); | ||
312 | return nokey ? ERR_PTR(-ENOKEY) : ERR_PTR(-EPERM); | ||
313 | } | ||
291 | return d_splice_alias(inode, dentry); | 314 | return d_splice_alias(inode, dentry); |
292 | 315 | ||
293 | err_out: | 316 | err_out: |