Keyrings Archive on lore.kernel.org
 help / color / Atom feed
From: Andrey Ryabinin <arbn@yandex-team.ru>
To: David Howells <dhowells@redhat.com>, Jarkko Sakkinen <jarkko@kernel.org>
Cc: James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	keyrings@vger.kernel.org, linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Andrey Ryabinin <arbn@yandex-team.ru>
Subject: [PATCH] keys: Allow disabling read permissions for key possessor
Date: Mon, 22 Mar 2021 12:57:26 +0300
Message-ID: <20210322095726.14939-1-arbn@yandex-team.ru> (raw)

keyctl_read_key() has a strange code which allows possessor to read
key's payload regardless of READ permission status:

$ keyctl add user test test @u
196773443
$ keyctl print 196773443
test
$ keyctl describe 196773443
196773443: alswrv-----v------------  1000  1000 user: test
$ keyctl rdescribe 196773443
user;1000;1000;3f010000;test
$ keyctl setperm 196773443 0x3d010000
$ keyctl describe 196773443
196773443: alsw-v-----v------------  1000  1000 user: test
$ keyctl  print 196773443
test

The last keyctl print should fail with -EACCESS instead of success.
Fix this by removing weird possessor checks.

Signed-off-by: Andrey Ryabinin <arbn@yandex-team.ru>
---

 - This was noticed by code review. It seems like a bug to me,
 but if I'm wrong and current behavior is correct, I think we need
 at least better comment here.
   

 security/keys/keyctl.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 96a92a645216d..2ec021c7adc12 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -845,22 +845,9 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
 
 	/* see if we can read it directly */
 	ret = key_permission(key_ref, KEY_NEED_READ);
-	if (ret == 0)
-		goto can_read_key;
-	if (ret != -EACCES)
+	if (ret != 0)
 		goto key_put_out;
 
-	/* we can't; see if it's searchable from this process's keyrings
-	 * - we automatically take account of the fact that it may be
-	 *   dangling off an instantiation key
-	 */
-	if (!is_key_possessed(key_ref)) {
-		ret = -EACCES;
-		goto key_put_out;
-	}
-
-	/* the key is probably readable - now try to read it */
-can_read_key:
 	if (!key->type->read) {
 		ret = -EOPNOTSUPP;
 		goto key_put_out;
-- 
2.26.2


             reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22  9:57 Andrey Ryabinin [this message]
2021-03-23  0:55 ` Eric Biggers
2021-03-23  2:02 ` Jarkko Sakkinen

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=20210322095726.14939-1-arbn@yandex-team.ru \
    --to=arbn@yandex-team.ru \
    --cc=dhowells@redhat.com \
    --cc=jarkko@kernel.org \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=serge@hallyn.com \
    /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

Keyrings Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/keyrings/0 keyrings/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 keyrings keyrings/ https://lore.kernel.org/keyrings \
		keyrings@vger.kernel.org
	public-inbox-index keyrings

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.keyrings


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git