aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2017-09-27 15:50:46 -0400
committerDavid Howells <dhowells@redhat.com>2017-10-18 04:12:41 -0400
commitab5c69f01313c80df948e4f768efe616258f85f4 (patch)
tree4ba32c1aad16a4bf1573a2f6b15d749b04a5eb42
parent9d6c8711b6a751a694bcfaf49fb557b82092ee46 (diff)
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>
-rw-r--r--security/keys/proc.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/security/keys/proc.c b/security/keys/proc.c
index 4089ce1f7757..6d1fcbba1e09 100644
--- a/security/keys/proc.c
+++ b/security/keys/proc.c
@@ -179,7 +179,9 @@ static int proc_keys_show(struct seq_file *m, void *v)
179 struct rb_node *_p = v; 179 struct rb_node *_p = v;
180 struct key *key = rb_entry(_p, struct key, serial_node); 180 struct key *key = rb_entry(_p, struct key, serial_node);
181 struct timespec now; 181 struct timespec now;
182 time_t expiry;
182 unsigned long timo; 183 unsigned long timo;
184 unsigned long flags;
183 key_ref_t key_ref, skey_ref; 185 key_ref_t key_ref, skey_ref;
184 char xbuf[16]; 186 char xbuf[16];
185 short state; 187 short state;
@@ -218,12 +220,13 @@ static int proc_keys_show(struct seq_file *m, void *v)
218 rcu_read_lock(); 220 rcu_read_lock();
219 221
220 /* come up with a suitable timeout value */ 222 /* come up with a suitable timeout value */
221 if (key->expiry == 0) { 223 expiry = READ_ONCE(key->expiry);
224 if (expiry == 0) {
222 memcpy(xbuf, "perm", 5); 225 memcpy(xbuf, "perm", 5);
223 } else if (now.tv_sec >= key->expiry) { 226 } else if (now.tv_sec >= expiry) {
224 memcpy(xbuf, "expd", 5); 227 memcpy(xbuf, "expd", 5);
225 } else { 228 } else {
226 timo = key->expiry - now.tv_sec; 229 timo = expiry - now.tv_sec;
227 230
228 if (timo < 60) 231 if (timo < 60)
229 sprintf(xbuf, "%lus", timo); 232 sprintf(xbuf, "%lus", timo);
@@ -239,18 +242,19 @@ static int proc_keys_show(struct seq_file *m, void *v)
239 242
240 state = key_read_state(key); 243 state = key_read_state(key);
241 244
242#define showflag(KEY, LETTER, FLAG) \ 245#define showflag(FLAGS, LETTER, FLAG) \
243 (test_bit(FLAG, &(KEY)->flags) ? LETTER : '-') 246 ((FLAGS & (1 << FLAG)) ? LETTER : '-')
244 247
248 flags = READ_ONCE(key->flags);
245 seq_printf(m, "%08x %c%c%c%c%c%c%c %5d %4s %08x %5d %5d %-9.9s ", 249 seq_printf(m, "%08x %c%c%c%c%c%c%c %5d %4s %08x %5d %5d %-9.9s ",
246 key->serial, 250 key->serial,
247 state != KEY_IS_UNINSTANTIATED ? 'I' : '-', 251 state != KEY_IS_UNINSTANTIATED ? 'I' : '-',
248 showflag(key, 'R', KEY_FLAG_REVOKED), 252 showflag(flags, 'R', KEY_FLAG_REVOKED),
249 showflag(key, 'D', KEY_FLAG_DEAD), 253 showflag(flags, 'D', KEY_FLAG_DEAD),
250 showflag(key, 'Q', KEY_FLAG_IN_QUOTA), 254 showflag(flags, 'Q', KEY_FLAG_IN_QUOTA),
251 showflag(key, 'U', KEY_FLAG_USER_CONSTRUCT), 255 showflag(flags, 'U', KEY_FLAG_USER_CONSTRUCT),
252 state < 0 ? 'N' : '-', 256 state < 0 ? 'N' : '-',
253 showflag(key, 'i', KEY_FLAG_INVALIDATED), 257 showflag(flags, 'i', KEY_FLAG_INVALIDATED),
254 refcount_read(&key->usage), 258 refcount_read(&key->usage),
255 xbuf, 259 xbuf,
256 key->perm, 260 key->perm,