* [PATCH] keys: Allow disabling read permissions for key possessor
@ 2021-03-22 9:57 Andrey Ryabinin
2021-03-23 0:55 ` Eric Biggers
2021-03-23 2:02 ` Jarkko Sakkinen
0 siblings, 2 replies; 3+ messages in thread
From: Andrey Ryabinin @ 2021-03-22 9:57 UTC (permalink / raw)
To: David Howells, Jarkko Sakkinen
Cc: James Morris, Serge E. Hallyn, keyrings, linux-security-module,
linux-kernel, Andrey Ryabinin
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] keys: Allow disabling read permissions for key possessor
2021-03-22 9:57 [PATCH] keys: Allow disabling read permissions for key possessor Andrey Ryabinin
@ 2021-03-23 0:55 ` Eric Biggers
2021-03-23 2:02 ` Jarkko Sakkinen
1 sibling, 0 replies; 3+ messages in thread
From: Eric Biggers @ 2021-03-23 0:55 UTC (permalink / raw)
To: Andrey Ryabinin
Cc: David Howells, Jarkko Sakkinen, James Morris, Serge E. Hallyn,
keyrings, linux-security-module, linux-kernel
On Mon, Mar 22, 2021 at 12:57:26PM +0300, Andrey Ryabinin wrote:
> 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;
> - }
> -
This might be intentional, given the comment above the function:
* The key must either grant the caller Read permission, or it must grant the
* caller Search permission when searched for from the process keyrings.
The 'is_key_possessed()' check is implementing the second part, right?
Maybe check if this shows up in the documentation and tests too.
- Eric
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] keys: Allow disabling read permissions for key possessor
2021-03-22 9:57 [PATCH] keys: Allow disabling read permissions for key possessor Andrey Ryabinin
2021-03-23 0:55 ` Eric Biggers
@ 2021-03-23 2:02 ` Jarkko Sakkinen
1 sibling, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2021-03-23 2:02 UTC (permalink / raw)
To: Andrey Ryabinin, David Howells
Cc: James Morris, Serge E. Hallyn, keyrings, linux-security-module,
linux-kernel
On Mon, Mar 22, 2021 at 12:57:26PM +0300, Andrey Ryabinin wrote:
> 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>
I wrote a new test. If you include a test into a commit please
describe it so that it can be easily executed. Otherwise, it is
somewhat useless.
Anyway,
https://gist.github.com/jarkk0sakkinen/7b417be20cb52ed971a90561192f0883
David, why all of these end up allowing to still print the payload?
/Jarkko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-23 2:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 9:57 [PATCH] keys: Allow disabling read permissions for key possessor Andrey Ryabinin
2021-03-23 0:55 ` Eric Biggers
2021-03-23 2:02 ` Jarkko Sakkinen
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.