aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/nfs/idmap.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index 864c51e4b400..1b5058b4043b 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -205,12 +205,18 @@ static int nfs_idmap_init_keyring(void)
205 if (ret < 0) 205 if (ret < 0)
206 goto failed_put_key; 206 goto failed_put_key;
207 207
208 ret = register_key_type(&key_type_id_resolver_legacy);
209 if (ret < 0)
210 goto failed_reg_legacy;
211
208 set_bit(KEY_FLAG_ROOT_CAN_CLEAR, &keyring->flags); 212 set_bit(KEY_FLAG_ROOT_CAN_CLEAR, &keyring->flags);
209 cred->thread_keyring = keyring; 213 cred->thread_keyring = keyring;
210 cred->jit_keyring = KEY_REQKEY_DEFL_THREAD_KEYRING; 214 cred->jit_keyring = KEY_REQKEY_DEFL_THREAD_KEYRING;
211 id_resolver_cache = cred; 215 id_resolver_cache = cred;
212 return 0; 216 return 0;
213 217
218failed_reg_legacy:
219 unregister_key_type(&key_type_id_resolver);
214failed_put_key: 220failed_put_key:
215 key_put(keyring); 221 key_put(keyring);
216failed_put_cred: 222failed_put_cred:
@@ -222,6 +228,7 @@ static void nfs_idmap_quit_keyring(void)
222{ 228{
223 key_revoke(id_resolver_cache->thread_keyring); 229 key_revoke(id_resolver_cache->thread_keyring);
224 unregister_key_type(&key_type_id_resolver); 230 unregister_key_type(&key_type_id_resolver);
231 unregister_key_type(&key_type_id_resolver_legacy);
225 put_cred(id_resolver_cache); 232 put_cred(id_resolver_cache);
226} 233}
227 234
@@ -385,7 +392,7 @@ static const struct rpc_pipe_ops idmap_upcall_ops = {
385}; 392};
386 393
387static struct key_type key_type_id_resolver_legacy = { 394static struct key_type key_type_id_resolver_legacy = {
388 .name = "id_resolver", 395 .name = "id_legacy",
389 .instantiate = user_instantiate, 396 .instantiate = user_instantiate,
390 .match = user_match, 397 .match = user_match,
391 .revoke = user_revoke, 398 .revoke = user_revoke,
@@ -674,6 +681,7 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,
674 if (ret < 0) 681 if (ret < 0)
675 goto out2; 682 goto out2;
676 683
684 BUG_ON(idmap->idmap_key_cons != NULL);
677 idmap->idmap_key_cons = cons; 685 idmap->idmap_key_cons = cons;
678 686
679 ret = rpc_queue_upcall(idmap->idmap_pipe, msg); 687 ret = rpc_queue_upcall(idmap->idmap_pipe, msg);
@@ -687,8 +695,7 @@ out2:
687out1: 695out1:
688 kfree(msg); 696 kfree(msg);
689out0: 697out0:
690 key_revoke(cons->key); 698 complete_request_key(cons, ret);
691 key_revoke(cons->authkey);
692 return ret; 699 return ret;
693} 700}
694 701
@@ -722,11 +729,18 @@ idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
722{ 729{
723 struct rpc_inode *rpci = RPC_I(filp->f_path.dentry->d_inode); 730 struct rpc_inode *rpci = RPC_I(filp->f_path.dentry->d_inode);
724 struct idmap *idmap = (struct idmap *)rpci->private; 731 struct idmap *idmap = (struct idmap *)rpci->private;
725 struct key_construction *cons = idmap->idmap_key_cons; 732 struct key_construction *cons;
726 struct idmap_msg im; 733 struct idmap_msg im;
727 size_t namelen_in; 734 size_t namelen_in;
728 int ret; 735 int ret;
729 736
737 /* If instantiation is successful, anyone waiting for key construction
738 * will have been woken up and someone else may now have used
739 * idmap_key_cons - so after this point we may no longer touch it.
740 */
741 cons = ACCESS_ONCE(idmap->idmap_key_cons);
742 idmap->idmap_key_cons = NULL;
743
730 if (mlen != sizeof(im)) { 744 if (mlen != sizeof(im)) {
731 ret = -ENOSPC; 745 ret = -ENOSPC;
732 goto out; 746 goto out;
@@ -739,7 +753,7 @@ idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
739 753
740 if (!(im.im_status & IDMAP_STATUS_SUCCESS)) { 754 if (!(im.im_status & IDMAP_STATUS_SUCCESS)) {
741 ret = mlen; 755 ret = mlen;
742 complete_request_key(idmap->idmap_key_cons, -ENOKEY); 756 complete_request_key(cons, -ENOKEY);
743 goto out_incomplete; 757 goto out_incomplete;
744 } 758 }
745 759
@@ -756,7 +770,7 @@ idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
756 } 770 }
757 771
758out: 772out:
759 complete_request_key(idmap->idmap_key_cons, ret); 773 complete_request_key(cons, ret);
760out_incomplete: 774out_incomplete:
761 return ret; 775 return ret;
762} 776}