KEYS: fix refcount_inc() on zero
If a key's refcount is dropped to zero between key_lookup() peeking at
the refcount and subsequently attempting to increment it, refcount_inc()
will see a zero refcount. Here, refcount_inc() will WARN_ONCE(), and
will *not* increment the refcount, which will remain zero.
Once key_lookup() drops key_serial_lock, it is possible for the key to
be freed behind our back.
This patch uses refcount_inc_not_zero() to perform the peek and increment
atomically.
Fixes: fff292914d
("security, keys: convert key.usage from atomic_t to refcount_t")
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Cc: David Windsor <dwindsor@gmail.com>
Cc: Elena Reshetova <elena.reshetova@intel.com>
Cc: Hans Liljestrand <ishkamiel@gmail.com>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: James Morris <james.l.morris@oracle.com>
This commit is contained in:
parent
7cbe0932c2
commit
92347cfd62
1 changed files with 4 additions and 7 deletions
|
@ -660,14 +660,11 @@ not_found:
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
found:
|
found:
|
||||||
/* pretend it doesn't exist if it is awaiting deletion */
|
/* A key is allowed to be looked up only if someone still owns a
|
||||||
if (refcount_read(&key->usage) == 0)
|
* reference to it - otherwise it's awaiting the gc.
|
||||||
goto not_found;
|
|
||||||
|
|
||||||
/* this races with key_put(), but that doesn't matter since key_put()
|
|
||||||
* doesn't actually change the key
|
|
||||||
*/
|
*/
|
||||||
__key_get(key);
|
if (!refcount_inc_not_zero(&key->usage))
|
||||||
|
goto not_found;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
spin_unlock(&key_serial_lock);
|
spin_unlock(&key_serial_lock);
|
||||||
|
|
Loading…
Reference in a new issue