| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* eCryptfs: Linux filesystem encryption layer |
| 4 |
* |
| 5 |
* Copyright (C) 1997-2003 Erez Zadok |
| 6 |
* Copyright (C) 2001-2003 Stony Brook University |
| 7 |
* Copyright (C) 2004-2006 International Business Machines Corp. |
| 8 |
* Author(s): Michael A. Halcrow <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <linux/dcache.h> |
| 12 |
#include <linux/namei.h> |
| 13 |
#include <linux/mount.h> |
| 14 |
#include <linux/fs_stack.h> |
| 15 |
#include <linux/slab.h> |
| 16 |
#include "ecryptfs_kernel.h" |
| 17 |
|
| 18 |
/** |
| 19 |
* ecryptfs_d_revalidate - revalidate an ecryptfs dentry |
| 20 |
* @dir: inode of expected parent |
| 21 |
* @name: expected name |
| 22 |
* @dentry: dentry to revalidate |
| 23 |
* @flags: lookup flags |
| 24 |
* |
| 25 |
* Called when the VFS needs to revalidate a dentry. This |
| 26 |
* is called whenever a name lookup finds a dentry in the |
| 27 |
* dcache. Most filesystems leave this as NULL, because all their |
| 28 |
* dentries in the dcache are valid. |
| 29 |
* |
| 30 |
* Returns 1 if valid, 0 otherwise. |
| 31 |
* |
| 32 |
*/ |
| 33 |
static int ecryptfs_d_revalidate(struct inode *dir, const struct qstr *name, |
| 34 |
struct dentry *dentry, unsigned int flags) |
| 35 |
{ |
| 36 |
struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 37 |
int rc = 1; |
| 38 |
|
| 39 |
if (flags & LOOKUP_RCU) |
| 40 |
return -ECHILD; |
| 41 |
|
| 42 |
if (lower_dentry->d_flags & DCACHE_OP_REVALIDATE) { |
| 43 |
struct inode *lower_dir = ecryptfs_inode_to_lower(dir); |
| 44 |
struct name_snapshot n; |
| 45 |
|
| 46 |
take_dentry_name_snapshot(&n, lower_dentry); |
| 47 |
rc = lower_dentry->d_op->d_revalidate(lower_dir, &n.name, |
| 48 |
lower_dentry, flags); |
| 49 |
release_dentry_name_snapshot(&n); |
| 50 |
} |
| 51 |
|
| 52 |
if (d_really_is_positive(dentry)) { |
| 53 |
struct inode *inode = d_inode(dentry); |
| 54 |
|
| 55 |
fsstack_copy_attr_all(inode, ecryptfs_inode_to_lower(inode)); |
| 56 |
if (!inode->i_nlink) |
| 57 |
return 0; |
| 58 |
} |
| 59 |
return rc; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* ecryptfs_d_release |
| 64 |
* @dentry: The ecryptfs dentry |
| 65 |
* |
| 66 |
* Called when a dentry is really deallocated. |
| 67 |
*/ |
| 68 |
static void ecryptfs_d_release(struct dentry *dentry) |
| 69 |
{ |
| 70 |
dput(dentry->d_fsdata); |
| 71 |
} |
| 72 |
|
| 73 |
const struct dentry_operations ecryptfs_dops = { |
| 74 |
.d_revalidate = ecryptfs_d_revalidate, |
| 75 |
.d_release = ecryptfs_d_release, |
| 76 |
}; |