Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KEYS: Invert FINAL_PUT bit

Invert the FINAL_PUT bit so that test_bit_acquire and clear_bit_unlock
can be used instead of smp_mb.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Herbert Xu and committed by
Linus Torvalds
488ef356 aef17cb3

+6 -5
+1 -1
include/linux/key.h
··· 236 236 #define KEY_FLAG_ROOT_CAN_INVAL 7 /* set if key can be invalidated by root without permission */ 237 237 #define KEY_FLAG_KEEP 8 /* set if key should not be removed */ 238 238 #define KEY_FLAG_UID_KEYRING 9 /* set if key is a user or user session keyring */ 239 - #define KEY_FLAG_FINAL_PUT 10 /* set if final put has happened on key */ 239 + #define KEY_FLAG_USER_ALIVE 10 /* set if final put has not happened on key yet */ 240 240 241 241 /* the key type and key description string 242 242 * - the desc is used to match a key against search criteria
+2 -2
security/keys/gc.c
··· 218 218 key = rb_entry(cursor, struct key, serial_node); 219 219 cursor = rb_next(cursor); 220 220 221 - if (test_bit(KEY_FLAG_FINAL_PUT, &key->flags)) { 222 - smp_mb(); /* Clobber key->user after FINAL_PUT seen. */ 221 + if (!test_bit_acquire(KEY_FLAG_USER_ALIVE, &key->flags)) { 222 + /* Clobber key->user after final put seen. */ 223 223 goto found_unreferenced_key; 224 224 } 225 225
+3 -2
security/keys/key.c
··· 298 298 key->restrict_link = restrict_link; 299 299 key->last_used_at = ktime_get_real_seconds(); 300 300 301 + key->flags |= 1 << KEY_FLAG_USER_ALIVE; 301 302 if (!(flags & KEY_ALLOC_NOT_IN_QUOTA)) 302 303 key->flags |= 1 << KEY_FLAG_IN_QUOTA; 303 304 if (flags & KEY_ALLOC_BUILT_IN) ··· 659 658 key->user->qnbytes -= key->quotalen; 660 659 spin_unlock_irqrestore(&key->user->lock, flags); 661 660 } 662 - smp_mb(); /* key->user before FINAL_PUT set. */ 663 - set_bit(KEY_FLAG_FINAL_PUT, &key->flags); 661 + /* Mark key as safe for GC after key->user done. */ 662 + clear_bit_unlock(KEY_FLAG_USER_ALIVE, &key->flags); 664 663 schedule_work(&key_gc_work); 665 664 } 666 665 }