All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers3@gmail.com>
To: keyrings@vger.kernel.org
Cc: David Howells <dhowells@redhat.com>,
	Michael Halcrow <mhalcrow@google.com>,
	linux-cachefs@redhat.com, ecryptfs@vger.kernel.org,
	linux-fscrypt@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	Eric Biggers <ebiggers@google.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/7] KEYS: encrypted: fix dereference of NULL user_key_payload
Date: Thu, 28 Sep 2017 14:25:56 -0700	[thread overview]
Message-ID: <20170928212602.41744-2-ebiggers3@gmail.com> (raw)
In-Reply-To: <20170928212602.41744-1-ebiggers3@gmail.com>

From: Eric Biggers <ebiggers@google.com>

A key of type "encrypted" references a "master key" which is used to
encrypt and decrypt the encrypted key's payload.  However, when we
accessed the master key's payload, we failed to handle the case where
the master key has been revoked, which sets the payload pointer to NULL.
Note that request_key() *does* skip revoked keys, but there is still a
window where the key can be revoked before we acquire its semaphore.

Fix it by checking for a NULL payload, treating it like a key which was
already revoked at the time it was requested.

This was an issue for master keys of type "user" only.  Master keys can
also be of type "trusted", but those cannot be revoked.

Fixes: 7e70cb497850 ("keys: add new key-type encrypted")
Cc: <stable@vger.kernel.org>    [v2.6.38+]
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 security/keys/encrypted-keys/encrypted.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
index f54b92868bc3..d92cbf9687c3 100644
--- a/security/keys/encrypted-keys/encrypted.c
+++ b/security/keys/encrypted-keys/encrypted.c
@@ -309,6 +309,13 @@ static struct key *request_user_key(const char *master_desc, const u8 **master_k
 
 	down_read(&ukey->sem);
 	upayload = user_key_payload_locked(ukey);
+	if (!upayload) {
+		/* key was revoked before we acquired its semaphore */
+		up_read(&ukey->sem);
+		key_put(ukey);
+		ukey = ERR_PTR(-EKEYREVOKED);
+		goto error;
+	}
 	*master_key = upayload->data;
 	*master_keylen = upayload->datalen;
 error:
-- 
2.14.2.822.g60be5d43e6-goog

WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers3@gmail.com>
To: keyrings@vger.kernel.org
Cc: David Howells <dhowells@redhat.com>,
	Michael Halcrow <mhalcrow@google.com>,
	linux-cachefs@redhat.com, ecryptfs@vger.kernel.org,
	linux-fscrypt@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	Eric Biggers <ebiggers@google.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/7] KEYS: encrypted: fix dereference of NULL user_key_payload
Date: Thu, 28 Sep 2017 21:25:56 +0000	[thread overview]
Message-ID: <20170928212602.41744-2-ebiggers3@gmail.com> (raw)
In-Reply-To: <20170928212602.41744-1-ebiggers3@gmail.com>

From: Eric Biggers <ebiggers@google.com>

A key of type "encrypted" references a "master key" which is used to
encrypt and decrypt the encrypted key's payload.  However, when we
accessed the master key's payload, we failed to handle the case where
the master key has been revoked, which sets the payload pointer to NULL.
Note that request_key() *does* skip revoked keys, but there is still a
window where the key can be revoked before we acquire its semaphore.

Fix it by checking for a NULL payload, treating it like a key which was
already revoked at the time it was requested.

This was an issue for master keys of type "user" only.  Master keys can
also be of type "trusted", but those cannot be revoked.

Fixes: 7e70cb497850 ("keys: add new key-type encrypted")
Cc: <stable@vger.kernel.org>    [v2.6.38+]
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 security/keys/encrypted-keys/encrypted.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
index f54b92868bc3..d92cbf9687c3 100644
--- a/security/keys/encrypted-keys/encrypted.c
+++ b/security/keys/encrypted-keys/encrypted.c
@@ -309,6 +309,13 @@ static struct key *request_user_key(const char *master_desc, const u8 **master_k
 
 	down_read(&ukey->sem);
 	upayload = user_key_payload_locked(ukey);
+	if (!upayload) {
+		/* key was revoked before we acquired its semaphore */
+		up_read(&ukey->sem);
+		key_put(ukey);
+		ukey = ERR_PTR(-EKEYREVOKED);
+		goto error;
+	}
 	*master_key = upayload->data;
 	*master_keylen = upayload->datalen;
 error:
-- 
2.14.2.822.g60be5d43e6-goog


WARNING: multiple messages have this Message-ID (diff)
From: ebiggers3@gmail.com (Eric Biggers)
To: linux-security-module@vger.kernel.org
Subject: [PATCH 1/7] KEYS: encrypted: fix dereference of NULL user_key_payload
Date: Thu, 28 Sep 2017 14:25:56 -0700	[thread overview]
Message-ID: <20170928212602.41744-2-ebiggers3@gmail.com> (raw)
In-Reply-To: <20170928212602.41744-1-ebiggers3@gmail.com>

From: Eric Biggers <ebiggers@google.com>

A key of type "encrypted" references a "master key" which is used to
encrypt and decrypt the encrypted key's payload.  However, when we
accessed the master key's payload, we failed to handle the case where
the master key has been revoked, which sets the payload pointer to NULL.
Note that request_key() *does* skip revoked keys, but there is still a
window where the key can be revoked before we acquire its semaphore.

Fix it by checking for a NULL payload, treating it like a key which was
already revoked at the time it was requested.

This was an issue for master keys of type "user" only.  Master keys can
also be of type "trusted", but those cannot be revoked.

Fixes: 7e70cb497850 ("keys: add new key-type encrypted")
Cc: <stable@vger.kernel.org>    [v2.6.38+]
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 security/keys/encrypted-keys/encrypted.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
index f54b92868bc3..d92cbf9687c3 100644
--- a/security/keys/encrypted-keys/encrypted.c
+++ b/security/keys/encrypted-keys/encrypted.c
@@ -309,6 +309,13 @@ static struct key *request_user_key(const char *master_desc, const u8 **master_k
 
 	down_read(&ukey->sem);
 	upayload = user_key_payload_locked(ukey);
+	if (!upayload) {
+		/* key was revoked before we acquired its semaphore */
+		up_read(&ukey->sem);
+		key_put(ukey);
+		ukey = ERR_PTR(-EKEYREVOKED);
+		goto error;
+	}
 	*master_key = upayload->data;
 	*master_keylen = upayload->datalen;
 error:
-- 
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 at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2017-09-28 21:25 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-28 21:25 [PATCH 0/7] Fix dereferencing payload of revoked keys Eric Biggers
2017-09-28 21:25 ` Eric Biggers
2017-09-28 21:25 ` Eric Biggers
2017-09-28 21:25 ` Eric Biggers [this message]
2017-09-28 21:25   ` [PATCH 1/7] KEYS: encrypted: fix dereference of NULL user_key_payload Eric Biggers
2017-09-28 21:25   ` Eric Biggers
2017-10-03 10:51   ` James Morris
2017-10-03 10:51     ` James Morris
2017-10-03 10:51     ` James Morris
2017-09-28 21:25 ` [PATCH 2/7] FS-Cache: " Eric Biggers
2017-09-28 21:25   ` Eric Biggers
2017-09-28 21:25   ` Eric Biggers
2017-10-03 10:51   ` James Morris
2017-10-03 10:51     ` James Morris
2017-10-03 10:51     ` James Morris
2017-09-28 21:25 ` [PATCH 3/7] lib/digsig: " Eric Biggers
2017-09-28 21:25   ` Eric Biggers
2017-09-28 21:25   ` Eric Biggers
2017-10-03 10:52   ` James Morris
2017-10-03 10:52     ` James Morris
2017-10-03 10:52     ` James Morris
2017-09-28 21:25 ` [PATCH 4/7] fscrypt: " Eric Biggers
2017-09-28 21:25   ` Eric Biggers
2017-09-28 21:25   ` Eric Biggers
2017-10-03 10:56   ` James Morris
2017-10-03 10:56     ` James Morris
2017-10-03 10:56     ` James Morris
2017-09-28 21:26 ` [PATCH 5/7] ecryptfs: " Eric Biggers
2017-09-28 21:26   ` Eric Biggers
2017-09-28 21:26   ` Eric Biggers
2017-10-03 11:01   ` James Morris
2017-10-03 11:01     ` James Morris
2017-10-03 11:01     ` James Morris
2017-09-28 21:26 ` [PATCH 6/7] ecryptfs: fix out-of-bounds read of key payload Eric Biggers
2017-09-28 21:26   ` Eric Biggers
2017-09-28 21:26   ` Eric Biggers
2017-10-03 11:03   ` James Morris
2017-10-03 11:03     ` James Morris
2017-10-03 11:03     ` James Morris
2017-09-28 21:26 ` [PATCH 7/7] ecryptfs: move key payload accessor functions into keystore.c Eric Biggers
2017-09-28 21:26   ` Eric Biggers
2017-09-28 21:26   ` Eric Biggers
2017-10-03 11:05   ` James Morris
2017-10-03 11:05     ` James Morris
2017-10-03 11:05     ` James Morris

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=20170928212602.41744-2-ebiggers3@gmail.com \
    --to=ebiggers3@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@google.com \
    --cc=ecryptfs@vger.kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mhalcrow@google.com \
    --cc=stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.