Merge tag 'keys-request-20190626' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / kernel / cred.c
index c73a87a4df13fa02d96661fa889ec9fa5f4fd7ea..f9a0ce66c9c3e125393f011be7d55a322785ed2e 100644 (file)
@@ -170,6 +170,11 @@ void exit_creds(struct task_struct *tsk)
        validate_creds(cred);
        alter_cred_subscribers(cred, -1);
        put_cred(cred);
+
+#ifdef CONFIG_KEYS_REQUEST_CACHE
+       key_put(current->cached_requested_key);
+       current->cached_requested_key = NULL;
+#endif
 }
 
 /**
@@ -323,6 +328,10 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
        struct cred *new;
        int ret;
 
+#ifdef CONFIG_KEYS_REQUEST_CACHE
+       p->cached_requested_key = NULL;
+#endif
+
        if (
 #ifdef CONFIG_KEYS
                !p->cred->thread_keyring &&
@@ -460,9 +469,9 @@ int commit_creds(struct cred *new)
 
        /* alter the thread keyring */
        if (!uid_eq(new->fsuid, old->fsuid))
-               key_fsuid_changed(task);
+               key_fsuid_changed(new);
        if (!gid_eq(new->fsgid, old->fsgid))
-               key_fsgid_changed(task);
+               key_fsgid_changed(new);
 
        /* do it
         * RLIMIT_NPROC limits on user->processes have already been checked