]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - security/keys/key.c
Created a function for setting timeouts on keys
[karo-tx-linux.git] / security / keys / key.c
index 7ada8019be1f2c08314fe0c8c14d3058a1ee26ea..06783cffb3afa631fcca8efee90d17cc4f711b2c 100644 (file)
@@ -671,6 +671,26 @@ found_kernel_type:
        return ktype;
 }
 
+void key_set_timeout(struct key *key, unsigned timeout)
+{
+       struct timespec now;
+       time_t expiry = 0;
+
+       /* make the changes with the locks held to prevent races */
+       down_write(&key->sem);
+
+       if (timeout > 0) {
+               now = current_kernel_time();
+               expiry = now.tv_sec + timeout;
+       }
+
+       key->expiry = expiry;
+       key_schedule_gc(key->expiry + key_gc_delay);
+
+       up_write(&key->sem);
+}
+EXPORT_SYMBOL_GPL(key_set_timeout);
+
 /*
  * Unlock a key type locked by key_type_lookup().
  */