Merge tag 'x86-asm-2024-01-08' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
[linux-2.6-microblaze.git] / security / keys / key.c
index 0260a19..5b10641 100644 (file)
@@ -294,6 +294,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
        key->uid = uid;
        key->gid = gid;
        key->perm = perm;
+       key->expiry = TIME64_MAX;
        key->restrict_link = restrict_link;
        key->last_used_at = ktime_get_real_seconds();
 
@@ -463,10 +464,7 @@ static int __key_instantiate_and_link(struct key *key,
                        if (authkey)
                                key_invalidate(authkey);
 
-                       if (prep->expiry != TIME64_MAX) {
-                               key->expiry = prep->expiry;
-                               key_schedule_gc(prep->expiry + key_gc_delay);
-                       }
+                       key_set_expiry(key, prep->expiry);
                }
        }
 
@@ -606,8 +604,7 @@ int key_reject_and_link(struct key *key,
                atomic_inc(&key->user->nikeys);
                mark_key_instantiated(key, -error);
                notify_key(key, NOTIFY_KEY_INSTANTIATED, -error);
-               key->expiry = ktime_get_real_seconds() + timeout;
-               key_schedule_gc(key->expiry + key_gc_delay);
+               key_set_expiry(key, ktime_get_real_seconds() + timeout);
 
                if (test_and_clear_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags))
                        awaken = 1;
@@ -723,16 +720,14 @@ found_kernel_type:
 
 void key_set_timeout(struct key *key, unsigned timeout)
 {
-       time64_t expiry = 0;
+       time64_t expiry = TIME64_MAX;
 
        /* make the changes with the locks held to prevent races */
        down_write(&key->sem);
 
        if (timeout > 0)
                expiry = ktime_get_real_seconds() + timeout;
-
-       key->expiry = expiry;
-       key_schedule_gc(key->expiry + key_gc_delay);
+       key_set_expiry(key, expiry);
 
        up_write(&key->sem);
 }