From 445d582f54883617b6666e522d781f659a1e208a Mon Sep 17 00:00:00 2001 From: Tao Huang Date: Thu, 24 Sep 2020 19:56:29 +0800 Subject: [PATCH] Revert "Revert "ANDROID: fscrypt: add key removal notifier chain"" This reverts commit 4da740c10dc0f2de632686e8cc0274cfa52e67e4. For sdcardfs. Signed-off-by: Tao Huang Change-Id: I863e5efdf4aeec130447b1a655659ce16db55bd4 --- fs/crypto/keyring.c | 22 ++++++++++++++++++++++ include/linux/fscrypt.h | 14 ++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c index dea246b7493b..ae081f06e149 100644 --- a/fs/crypto/keyring.c +++ b/fs/crypto/keyring.c @@ -867,12 +867,34 @@ static int check_for_busy_inodes(struct super_block *sb, return -EBUSY; } +static BLOCKING_NOTIFIER_HEAD(fscrypt_key_removal_notifiers); + +/* + * Register a function to be executed when the FS_IOC_REMOVE_ENCRYPTION_KEY + * ioctl has removed a key and is about to try evicting inodes. + */ +int fscrypt_register_key_removal_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&fscrypt_key_removal_notifiers, + nb); +} +EXPORT_SYMBOL_GPL(fscrypt_register_key_removal_notifier); + +int fscrypt_unregister_key_removal_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&fscrypt_key_removal_notifiers, + nb); +} +EXPORT_SYMBOL_GPL(fscrypt_unregister_key_removal_notifier); + static int try_to_lock_encrypted_files(struct super_block *sb, struct fscrypt_master_key *mk) { int err1; int err2; + blocking_notifier_call_chain(&fscrypt_key_removal_notifiers, 0, NULL); + /* * An inode can't be evicted while it is dirty or has dirty pages. * Thus, we first have to clean the inodes in ->mk_decrypted_inodes. diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 1337108a4a46..afc56580aebe 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -178,6 +178,8 @@ int fscrypt_ioctl_add_key(struct file *filp, void __user *arg); int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg); int fscrypt_ioctl_remove_key_all_users(struct file *filp, void __user *arg); int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg); +int fscrypt_register_key_removal_notifier(struct notifier_block *nb); +int fscrypt_unregister_key_removal_notifier(struct notifier_block *nb); /* keysetup.c */ int fscrypt_get_encryption_info(struct inode *inode); @@ -380,6 +382,18 @@ static inline int fscrypt_ioctl_get_key_status(struct file *filp, return -EOPNOTSUPP; } +static inline int fscrypt_register_key_removal_notifier( + struct notifier_block *nb) +{ + return 0; +} + +static inline int fscrypt_unregister_key_removal_notifier( + struct notifier_block *nb) +{ + return 0; +} + /* keysetup.c */ static inline int fscrypt_get_encryption_info(struct inode *inode) {