summaryrefslogtreecommitdiffstats
path: root/fs/crypto/hooks.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2017-10-09 12:15:41 -0700
committerTheodore Ts'o <tytso@mit.edu>2017-10-18 19:52:38 -0400
commit0ea87a9644ebb5c9a3b100585d10533366de3269 (patch)
tree3934cd8c3a6f16ecbabd3b2909dba12bfde6b4ce /fs/crypto/hooks.c
parentefcc7ae2c9172d9a7ae94afdaf066a7abf0b9a90 (diff)
downloadlinux-stable-0ea87a9644ebb5c9a3b100585d10533366de3269.tar.gz
linux-stable-0ea87a9644ebb5c9a3b100585d10533366de3269.tar.bz2
linux-stable-0ea87a9644ebb5c9a3b100585d10533366de3269.zip
fscrypt: new helper function - fscrypt_prepare_link()
Introduce a helper function which prepares to link an inode into a possibly-encrypted directory. It handles setting up the target directory's encryption key, then verifying that the link won't violate the constraint that all files in an encrypted directory tree use the same encryption policy. Acked-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/crypto/hooks.c')
-rw-r--r--fs/crypto/hooks.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/fs/crypto/hooks.c b/fs/crypto/hooks.c
index 069088e91ea9..8b90217320dd 100644
--- a/fs/crypto/hooks.c
+++ b/fs/crypto/hooks.c
@@ -47,3 +47,18 @@ int fscrypt_file_open(struct inode *inode, struct file *filp)
return err;
}
EXPORT_SYMBOL_GPL(fscrypt_file_open);
+
+int __fscrypt_prepare_link(struct inode *inode, struct inode *dir)
+{
+ int err;
+
+ err = fscrypt_require_key(dir);
+ if (err)
+ return err;
+
+ if (!fscrypt_has_permitted_context(dir, inode))
+ return -EPERM;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(__fscrypt_prepare_link);