@@ -181,7 +181,6 @@ struct key {
#define KEY_FLAG_REVOKED 2 /* set if key had been revoked */
#define KEY_FLAG_IN_QUOTA 3 /* set if key consumes quota */
#define KEY_FLAG_USER_CONSTRUCT 4 /* set if key is being constructed in userspace */
-#define KEY_FLAG_NEGATIVE 5 /* set if key is negative */
#define KEY_FLAG_ROOT_CAN_CLEAR 6 /* set if key can be cleared by root without permission */
#define KEY_FLAG_INVALIDATED 7 /* set if key has been invalidated */
#define KEY_FLAG_BUILTIN 8 /* set if key is built in to the kernel */
@@ -376,7 +375,12 @@ static inline bool key_is_instantiated(const struct key *key)
unsigned long flags = smp_load_acquire(&key->flags);
return (flags & (1 << KEY_FLAG_INSTANTIATED)) &&
- !(flags & (1 << KEY_FLAG_NEGATIVE));
+ !(flags & KEY_FLAGS_REJECT_ERROR_MASK);
+}
+
+static inline bool key_is_negative(const struct key *key)
+{
+ return key->flags & KEY_FLAGS_REJECT_ERROR_MASK;
}
#define dereference_key_rcu(KEY) \
@@ -847,7 +847,7 @@ static int encrypted_update(struct key *key, struct key_preparsed_payload *prep)
size_t datalen = prep->datalen;
int ret = 0;
- if (test_bit(KEY_FLAG_NEGATIVE, &key->flags))
+ if (key_is_negative(key))
return -ENOKEY;
if (datalen <= 0 || datalen > 32767 || !prep->data)
return -EINVAL;
@@ -135,9 +135,7 @@ static noinline void key_gc_unused_keys(struct list_head *keys)
key_check(key);
/* Throw away the key data if the key is instantiated */
- if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags) &&
- !test_bit(KEY_FLAG_NEGATIVE, &key->flags) &&
- key->type->destroy)
+ if (key_is_instantiated(key) && key->type->destroy)
key->type->destroy(key);
security_key_free(key);
@@ -407,10 +407,8 @@ static void mark_key_instantiated(struct key *key, unsigned int reject_error)
do {
old = READ_ONCE(key->flags);
- new = (old & ~((1 << KEY_FLAG_NEGATIVE) |
- KEY_FLAGS_REJECT_ERROR_MASK)) |
+ new = (old & ~KEY_FLAGS_REJECT_ERROR_MASK) |
(1 << KEY_FLAG_INSTANTIATED) |
- (reject_error ? (1 << KEY_FLAG_NEGATIVE) : 0) |
(reject_error << KEY_FLAGS_REJECT_ERROR_SHIFT);
} while (cmpxchg_release(&key->flags, old, new) != old);
}
@@ -766,7 +766,7 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
key = key_ref_to_ptr(key_ref);
- if (test_bit(KEY_FLAG_NEGATIVE, &key->flags)) {
+ if (key_is_negative(key)) {
ret = -ENOKEY;
goto error2;
}
@@ -599,7 +599,7 @@ static int keyring_search_iterator(const void *object, void *iterator_data)
if (ctx->flags & KEYRING_SEARCH_DO_STATE_CHECK) {
/* we set a different error code if we pass a negative key */
- if (kflags & (1 << KEY_FLAG_NEGATIVE)) {
+ if (kflags & KEY_FLAGS_REJECT_ERROR_MASK) {
ctx->result = ERR_PTR(-(int)(kflags >>
KEY_FLAGS_REJECT_ERROR_SHIFT));
kleave(" = %d [neg]", ctx->skipped_ret);
@@ -250,7 +250,7 @@ static int proc_keys_show(struct seq_file *m, void *v)
showflag(flags, 'D', KEY_FLAG_DEAD),
showflag(flags, 'Q', KEY_FLAG_IN_QUOTA),
showflag(flags, 'U', KEY_FLAG_USER_CONSTRUCT),
- showflag(flags, 'N', KEY_FLAG_NEGATIVE),
+ (flags & KEY_FLAGS_REJECT_ERROR_MASK) ? 'N' : '-',
showflag(flags, 'i', KEY_FLAG_INVALIDATED),
refcount_read(&key->usage),
xbuf,
@@ -599,7 +599,7 @@ int wait_for_key_construction(struct key *key, bool intr)
/* Pairs with RELEASE in mark_key_instantiated() */
flags = smp_load_acquire(&key->flags);
- if (flags & (1 << KEY_FLAG_NEGATIVE))
+ if (flags & KEY_FLAGS_REJECT_ERROR_MASK)
return -(int)(flags >> KEY_FLAGS_REJECT_ERROR_SHIFT);
return key_validate(key);
@@ -1066,7 +1066,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
char *datablob;
int ret = 0;
- if (test_bit(KEY_FLAG_NEGATIVE, &key->flags))
+ if (key_is_negative(key))
return -ENOKEY;
p = key->payload.data[0];
if (!p->migratable)
@@ -114,7 +114,7 @@ int user_update(struct key *key, struct key_preparsed_payload *prep)
/* attach the new data, displacing the old */
key->expiry = prep->expiry;
- if (!test_bit(KEY_FLAG_NEGATIVE, &key->flags))
+ if (!key_is_negative(key))
zap = dereference_key_locked(key);
rcu_assign_keypointer(key, prep->payload.data[0]);
prep->payload.data[0] = NULL;