@@ -230,6 +230,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
230
230
struct key * key ;
231
231
size_t desclen , quotalen ;
232
232
int ret ;
233
+ unsigned long irqflags ;
233
234
234
235
key = ERR_PTR (- EINVAL );
235
236
if (!desc || !* desc )
@@ -259,7 +260,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
259
260
unsigned maxbytes = uid_eq (uid , GLOBAL_ROOT_UID ) ?
260
261
key_quota_root_maxbytes : key_quota_maxbytes ;
261
262
262
- spin_lock (& user -> lock );
263
+ spin_lock_irqsave (& user -> lock , irqflags );
263
264
if (!(flags & KEY_ALLOC_QUOTA_OVERRUN )) {
264
265
if (user -> qnkeys + 1 > maxkeys ||
265
266
user -> qnbytes + quotalen > maxbytes ||
@@ -269,7 +270,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
269
270
270
271
user -> qnkeys ++ ;
271
272
user -> qnbytes += quotalen ;
272
- spin_unlock (& user -> lock );
273
+ spin_unlock_irqrestore (& user -> lock , irqflags );
273
274
}
274
275
275
276
/* allocate and initialise the key and its description */
@@ -327,10 +328,10 @@ struct key *key_alloc(struct key_type *type, const char *desc,
327
328
kfree (key -> description );
328
329
kmem_cache_free (key_jar , key );
329
330
if (!(flags & KEY_ALLOC_NOT_IN_QUOTA )) {
330
- spin_lock (& user -> lock );
331
+ spin_lock_irqsave (& user -> lock , irqflags );
331
332
user -> qnkeys -- ;
332
333
user -> qnbytes -= quotalen ;
333
- spin_unlock (& user -> lock );
334
+ spin_unlock_irqrestore (& user -> lock , irqflags );
334
335
}
335
336
key_user_put (user );
336
337
key = ERR_PTR (ret );
@@ -340,18 +341,18 @@ struct key *key_alloc(struct key_type *type, const char *desc,
340
341
kmem_cache_free (key_jar , key );
341
342
no_memory_2 :
342
343
if (!(flags & KEY_ALLOC_NOT_IN_QUOTA )) {
343
- spin_lock (& user -> lock );
344
+ spin_lock_irqsave (& user -> lock , irqflags );
344
345
user -> qnkeys -- ;
345
346
user -> qnbytes -= quotalen ;
346
- spin_unlock (& user -> lock );
347
+ spin_unlock_irqrestore (& user -> lock , irqflags );
347
348
}
348
349
key_user_put (user );
349
350
no_memory_1 :
350
351
key = ERR_PTR (- ENOMEM );
351
352
goto error ;
352
353
353
354
no_quota :
354
- spin_unlock (& user -> lock );
355
+ spin_unlock_irqrestore (& user -> lock , irqflags );
355
356
key_user_put (user );
356
357
key = ERR_PTR (- EDQUOT );
357
358
goto error ;
@@ -380,8 +381,9 @@ int key_payload_reserve(struct key *key, size_t datalen)
380
381
if (delta != 0 && test_bit (KEY_FLAG_IN_QUOTA , & key -> flags )) {
381
382
unsigned maxbytes = uid_eq (key -> user -> uid , GLOBAL_ROOT_UID ) ?
382
383
key_quota_root_maxbytes : key_quota_maxbytes ;
384
+ unsigned long flags ;
383
385
384
- spin_lock (& key -> user -> lock );
386
+ spin_lock_irqsave (& key -> user -> lock , flags );
385
387
386
388
if (delta > 0 &&
387
389
(key -> user -> qnbytes + delta > maxbytes ||
@@ -392,7 +394,7 @@ int key_payload_reserve(struct key *key, size_t datalen)
392
394
key -> user -> qnbytes += delta ;
393
395
key -> quotalen += delta ;
394
396
}
395
- spin_unlock (& key -> user -> lock );
397
+ spin_unlock_irqrestore (& key -> user -> lock , flags );
396
398
}
397
399
398
400
/* change the recorded data length if that didn't generate an error */
@@ -463,7 +465,8 @@ static int __key_instantiate_and_link(struct key *key,
463
465
if (authkey )
464
466
key_invalidate (authkey );
465
467
466
- key_set_expiry (key , prep -> expiry );
468
+ if (prep -> expiry != TIME64_MAX )
469
+ key_set_expiry (key , prep -> expiry );
467
470
}
468
471
}
469
472
@@ -645,8 +648,18 @@ void key_put(struct key *key)
645
648
if (key ) {
646
649
key_check (key );
647
650
648
- if (refcount_dec_and_test (& key -> usage ))
651
+ if (refcount_dec_and_test (& key -> usage )) {
652
+ unsigned long flags ;
653
+
654
+ /* deal with the user's key tracking and quota */
655
+ if (test_bit (KEY_FLAG_IN_QUOTA , & key -> flags )) {
656
+ spin_lock_irqsave (& key -> user -> lock , flags );
657
+ key -> user -> qnkeys -- ;
658
+ key -> user -> qnbytes -= key -> quotalen ;
659
+ spin_unlock_irqrestore (& key -> user -> lock , flags );
660
+ }
649
661
schedule_work (& key_gc_work );
662
+ }
650
663
}
651
664
}
652
665
EXPORT_SYMBOL (key_put );
0 commit comments