aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
Diffstat (limited to 'security')
-rw-r--r--security/keys/key.c20
-rw-r--r--security/keys/keyctl.c18
2 files changed, 22 insertions, 16 deletions
diff --git a/security/keys/key.c b/security/keys/key.c
index 7ada8019be1f..06783cffb3af 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -671,6 +671,26 @@ found_kernel_type:
671 return ktype; 671 return ktype;
672} 672}
673 673
674void key_set_timeout(struct key *key, unsigned timeout)
675{
676 struct timespec now;
677 time_t expiry = 0;
678
679 /* make the changes with the locks held to prevent races */
680 down_write(&key->sem);
681
682 if (timeout > 0) {
683 now = current_kernel_time();
684 expiry = now.tv_sec + timeout;
685 }
686
687 key->expiry = expiry;
688 key_schedule_gc(key->expiry + key_gc_delay);
689
690 up_write(&key->sem);
691}
692EXPORT_SYMBOL_GPL(key_set_timeout);
693
674/* 694/*
675 * Unlock a key type locked by key_type_lookup(). 695 * Unlock a key type locked by key_type_lookup().
676 */ 696 */
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 0b3f5d72af1c..0a4a21d73f6a 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -14,6 +14,7 @@
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/syscalls.h> 16#include <linux/syscalls.h>
17#include <linux/key.h>
17#include <linux/keyctl.h> 18#include <linux/keyctl.h>
18#include <linux/fs.h> 19#include <linux/fs.h>
19#include <linux/capability.h> 20#include <linux/capability.h>
@@ -1244,10 +1245,8 @@ error:
1244 */ 1245 */
1245long keyctl_set_timeout(key_serial_t id, unsigned timeout) 1246long keyctl_set_timeout(key_serial_t id, unsigned timeout)
1246{ 1247{
1247 struct timespec now;
1248 struct key *key, *instkey; 1248 struct key *key, *instkey;
1249 key_ref_t key_ref; 1249 key_ref_t key_ref;
1250 time_t expiry;
1251 long ret; 1250 long ret;
1252 1251
1253 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL, 1252 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
@@ -1273,20 +1272,7 @@ long keyctl_set_timeout(key_serial_t id, unsigned timeout)
1273 1272
1274okay: 1273okay:
1275 key = key_ref_to_ptr(key_ref); 1274 key = key_ref_to_ptr(key_ref);
1276 1275 key_set_timeout(key, timeout);
1277 /* make the changes with the locks held to prevent races */
1278 down_write(&key->sem);
1279
1280 expiry = 0;
1281 if (timeout > 0) {
1282 now = current_kernel_time();
1283 expiry = now.tv_sec + timeout;
1284 }
1285
1286 key->expiry = expiry;
1287 key_schedule_gc(key->expiry + key_gc_delay);
1288
1289 up_write(&key->sem);
1290 key_put(key); 1276 key_put(key);
1291 1277
1292 ret = 0; 1278 ret = 0;