mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-20 00:11:22 +00:00
KEYS: load key flags and expiry time atomically in proc_keys_show()
In proc_keys_show(), the key semaphore is not held, so the key ->flags and ->expiry can be changed concurrently. We therefore should read them atomically just once. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: David Howells <dhowells@redhat.com>
This commit is contained in:
parent
9d6c8711b6
commit
ab5c69f013
@ -179,7 +179,9 @@ static int proc_keys_show(struct seq_file *m, void *v)
|
|||||||
struct rb_node *_p = v;
|
struct rb_node *_p = v;
|
||||||
struct key *key = rb_entry(_p, struct key, serial_node);
|
struct key *key = rb_entry(_p, struct key, serial_node);
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
|
time_t expiry;
|
||||||
unsigned long timo;
|
unsigned long timo;
|
||||||
|
unsigned long flags;
|
||||||
key_ref_t key_ref, skey_ref;
|
key_ref_t key_ref, skey_ref;
|
||||||
char xbuf[16];
|
char xbuf[16];
|
||||||
short state;
|
short state;
|
||||||
@ -218,12 +220,13 @@ static int proc_keys_show(struct seq_file *m, void *v)
|
|||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
|
|
||||||
/* come up with a suitable timeout value */
|
/* come up with a suitable timeout value */
|
||||||
if (key->expiry == 0) {
|
expiry = READ_ONCE(key->expiry);
|
||||||
|
if (expiry == 0) {
|
||||||
memcpy(xbuf, "perm", 5);
|
memcpy(xbuf, "perm", 5);
|
||||||
} else if (now.tv_sec >= key->expiry) {
|
} else if (now.tv_sec >= expiry) {
|
||||||
memcpy(xbuf, "expd", 5);
|
memcpy(xbuf, "expd", 5);
|
||||||
} else {
|
} else {
|
||||||
timo = key->expiry - now.tv_sec;
|
timo = expiry - now.tv_sec;
|
||||||
|
|
||||||
if (timo < 60)
|
if (timo < 60)
|
||||||
sprintf(xbuf, "%lus", timo);
|
sprintf(xbuf, "%lus", timo);
|
||||||
@ -239,18 +242,19 @@ static int proc_keys_show(struct seq_file *m, void *v)
|
|||||||
|
|
||||||
state = key_read_state(key);
|
state = key_read_state(key);
|
||||||
|
|
||||||
#define showflag(KEY, LETTER, FLAG) \
|
#define showflag(FLAGS, LETTER, FLAG) \
|
||||||
(test_bit(FLAG, &(KEY)->flags) ? LETTER : '-')
|
((FLAGS & (1 << FLAG)) ? LETTER : '-')
|
||||||
|
|
||||||
|
flags = READ_ONCE(key->flags);
|
||||||
seq_printf(m, "%08x %c%c%c%c%c%c%c %5d %4s %08x %5d %5d %-9.9s ",
|
seq_printf(m, "%08x %c%c%c%c%c%c%c %5d %4s %08x %5d %5d %-9.9s ",
|
||||||
key->serial,
|
key->serial,
|
||||||
state != KEY_IS_UNINSTANTIATED ? 'I' : '-',
|
state != KEY_IS_UNINSTANTIATED ? 'I' : '-',
|
||||||
showflag(key, 'R', KEY_FLAG_REVOKED),
|
showflag(flags, 'R', KEY_FLAG_REVOKED),
|
||||||
showflag(key, 'D', KEY_FLAG_DEAD),
|
showflag(flags, 'D', KEY_FLAG_DEAD),
|
||||||
showflag(key, 'Q', KEY_FLAG_IN_QUOTA),
|
showflag(flags, 'Q', KEY_FLAG_IN_QUOTA),
|
||||||
showflag(key, 'U', KEY_FLAG_USER_CONSTRUCT),
|
showflag(flags, 'U', KEY_FLAG_USER_CONSTRUCT),
|
||||||
state < 0 ? 'N' : '-',
|
state < 0 ? 'N' : '-',
|
||||||
showflag(key, 'i', KEY_FLAG_INVALIDATED),
|
showflag(flags, 'i', KEY_FLAG_INVALIDATED),
|
||||||
refcount_read(&key->usage),
|
refcount_read(&key->usage),
|
||||||
xbuf,
|
xbuf,
|
||||||
key->perm,
|
key->perm,
|
||||||
|
Loading…
Reference in New Issue
Block a user