From: ebiggers3@gmail.com (Eric Biggers)
To: linux-security-module@vger.kernel.org
Subject: [PATCH v3 3/7] KEYS: load key flags atomically in key_is_instantiated()
Date: Wed, 27 Sep 2017 12:50:43 -0700 [thread overview]
Message-ID: <20170927195047.122358-4-ebiggers3@gmail.com> (raw)
In-Reply-To: <20170927195047.122358-1-ebiggers3@gmail.com>
From: Eric Biggers <ebiggers@google.com>
In key_is_instantiated(), we check for KEY_FLAG_INSTANTIATED set and
KEY_FLAG_NEGATIVE unset. But this was done as two separate bit tests
which were not atomic with respect to each other, and had no memory
barrier providing ordering. Therefore, it was theoretically possible
for the function to incorrectly return true if called while the key was
being negatively instantiated.
There also needs to be a memory barrier before anything which is only
meaningful for positively instantiated keys, e.g. ->payload and
->datalen, can be read --- which some of the ->describe() methods do.
Fix both these problems by loading the flags using smp_load_acquire().
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
include/linux/key.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/include/linux/key.h b/include/linux/key.h
index b7b590d7c480..551f099f2f6a 100644
--- a/include/linux/key.h
+++ b/include/linux/key.h
@@ -372,8 +372,11 @@ extern void key_set_timeout(struct key *, unsigned);
*/
static inline bool key_is_instantiated(const struct key *key)
{
- return test_bit(KEY_FLAG_INSTANTIATED, &key->flags) &&
- !test_bit(KEY_FLAG_NEGATIVE, &key->flags);
+ /* Pairs with RELEASE in mark_key_instantiated() */
+ unsigned long flags = smp_load_acquire(&key->flags);
+
+ return (flags & (1 << KEY_FLAG_INSTANTIATED)) &&
+ !(flags & (1 << KEY_FLAG_NEGATIVE));
}
#define dereference_key_rcu(KEY) \
--
2.14.2.822.g60be5d43e6-goog
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info@ http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-09-27 19:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-27 19:50 [PATCH v3 0/7] KEYS: instantiation and atomicity fixes Eric Biggers
2017-09-27 19:50 ` [PATCH v3 1/7] KEYS: don't let add_key() update an uninstantiated key Eric Biggers
2017-09-27 19:50 ` [PATCH v3 2/7] KEYS: fix race between updating and finding negative key Eric Biggers
2017-09-27 19:50 ` Eric Biggers [this message]
2017-09-27 19:50 ` [PATCH v3 4/7] KEYS: load key flags and expiry time atomically in key_validate() Eric Biggers
2017-09-27 19:50 ` [PATCH v3 5/7] KEYS: load key flags and expiry time atomically in keyring_search_iterator() Eric Biggers
2017-09-27 19:50 ` [PATCH v3 6/7] KEYS: load key flags and expiry time atomically in proc_keys_show() Eric Biggers
2017-09-27 19:50 ` [PATCH v3 7/7] KEYS: remove KEY_FLAG_NEGATIVE Eric Biggers
2017-10-04 14:34 ` [PATCH v3 1/7] KEYS: don't let add_key() update an uninstantiated key David Howells
2017-10-04 16:33 ` [PATCH v3 2/7] KEYS: fix race between updating and finding negative key David Howells
2017-10-12 15:27 ` [PATCH v3 1/7] KEYS: don't let add_key() update an uninstantiated key David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170927195047.122358-4-ebiggers3@gmail.com \
--to=ebiggers3@gmail.com \
--cc=linux-security-module@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).