Skip to content

Commit c4a9fe6

Browse files
author
Al Viro
committed
fscrypt_d_revalidate(): use stable parent inode passed by caller
The only thing it's using is parent directory inode and we are already given a stable reference to that - no need to bother with boilerplate. Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 541795c commit c4a9fe6

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

fs/crypto/fname.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,10 @@ EXPORT_SYMBOL_GPL(fscrypt_fname_siphash);
574574
* Validate dentries in encrypted directories to make sure we aren't potentially
575575
* caching stale dentries after a key has been added.
576576
*/
577-
int fscrypt_d_revalidate(struct inode *parent_dir, const struct qstr *name,
577+
int fscrypt_d_revalidate(struct inode *dir, const struct qstr *name,
578578
struct dentry *dentry, unsigned int flags)
579579
{
580-
struct dentry *dir;
581580
int err;
582-
int valid;
583581

584582
/*
585583
* Plaintext names are always valid, since fscrypt doesn't support
@@ -592,30 +590,21 @@ int fscrypt_d_revalidate(struct inode *parent_dir, const struct qstr *name,
592590
/*
593591
* No-key name; valid if the directory's key is still unavailable.
594592
*
595-
* Although fscrypt forbids rename() on no-key names, we still must use
596-
* dget_parent() here rather than use ->d_parent directly. That's
597-
* because a corrupted fs image may contain directory hard links, which
598-
* the VFS handles by moving the directory's dentry tree in the dcache
599-
* each time ->lookup() finds the directory and it already has a dentry
600-
* elsewhere. Thus ->d_parent can be changing, and we must safely grab
601-
* a reference to some ->d_parent to prevent it from being freed.
593+
* Note in RCU mode we have to bail if we get here -
594+
* fscrypt_get_encryption_info() may block.
602595
*/
603596

604597
if (flags & LOOKUP_RCU)
605598
return -ECHILD;
606599

607-
dir = dget_parent(dentry);
608600
/*
609601
* Pass allow_unsupported=true, so that files with an unsupported
610602
* encryption policy can be deleted.
611603
*/
612-
err = fscrypt_get_encryption_info(d_inode(dir), true);
613-
valid = !fscrypt_has_encryption_key(d_inode(dir));
614-
dput(dir);
615-
604+
err = fscrypt_get_encryption_info(dir, true);
616605
if (err < 0)
617606
return err;
618607

619-
return valid;
608+
return !fscrypt_has_encryption_key(dir);
620609
}
621610
EXPORT_SYMBOL_GPL(fscrypt_d_revalidate);

0 commit comments

Comments
 (0)