From: "Jarkko Sakkinen" <jarkko.sakkinen@iki.fi>
To: "Mickaël Salaün" <mic@digikod.net>,
"David Howells" <dhowells@redhat.com>,
"Jarkko Sakkinen" <jarkko@kernel.org>
Cc: "Günther Noack" <gnoack@google.com>,
"James Morris" <jmorris@namei.org>,
"Jann Horn" <jannh@google.com>, "Kees Cook" <kees@kernel.org>,
"Paul Moore" <paul@paul-moore.com>,
keyrings@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org
Subject: Re: [PATCH v1] keys: Restrict KEYCTL_SESSION_TO_PARENT according to ptrace_may_access()
Date: Mon, 29 Jul 2024 17:06:14 +0300 [thread overview]
Message-ID: <D322X0D8UBYG.3FIRWQEBNURZF@iki.fi> (raw)
In-Reply-To: <20240729125846.1043211-1-mic@digikod.net>
On Mon Jul 29, 2024 at 3:58 PM EEST, Mickaël Salaün wrote:
> A process can modify its parent's credentials with
> KEYCTL_SESSION_TO_PARENT when their EUID and EGID are the same. This
> doesn't take into account all possible access controls.
Add a smoke test transcript here, which demonstrates the above
for A/B testing sake so that there is no need to invent one by
the reviewer.
Otherwise, it is too involved to give tested-by tag to this patch.
>
> Enforce the same access checks as for impersonating a process.
>
> The current credentials checks are untouch because they check against
> EUID and EGID, whereas ptrace_may_access() checks against UID and GID.
>
> Cc: David Howells <dhowells@redhat.com>
> Cc: Günther Noack <gnoack@google.com>
> Cc: James Morris <jmorris@namei.org>
> Cc: Jann Horn <jannh@google.com>
> Cc: Jarkko Sakkinen <jarkko@kernel.org>
> Cc: Kees Cook <kees@kernel.org>
> Cc: Paul Moore <paul@paul-moore.com>
> Fixes: ee18d64c1f63 ("KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]")
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> Link: https://lore.kernel.org/r/20240729125846.1043211-1-mic@digikod.net
> ---
> security/keys/keyctl.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
> index ab927a142f51..511bf79fa14c 100644
> --- a/security/keys/keyctl.c
> +++ b/security/keys/keyctl.c
> @@ -21,6 +21,7 @@
> #include <linux/security.h>
> #include <linux/uio.h>
> #include <linux/uaccess.h>
> +#include <linux/ptrace.h>
> #include <keys/request_key_auth-type.h>
> #include "internal.h"
>
> @@ -1687,6 +1688,10 @@ long keyctl_session_to_parent(void)
> !gid_eq(pcred->sgid, mycred->egid))
> goto unlock;
>
> + /* The child must be allowed to impersonate its parent process. */
> + if (!ptrace_may_access(parent, PTRACE_MODE_ATTACH_REALCREDS))
> + goto unlock;
> +
> /* the keyrings must have the same UID */
> if ((pcred->session_keyring &&
> !uid_eq(pcred->session_keyring->uid, mycred->euid)) ||
>
> base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b
BR, Jarkko
prev parent reply other threads:[~2024-07-29 14:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-29 12:58 Mickaël Salaün
2024-07-29 13:49 ` Jann Horn
2024-07-29 14:09 ` Mickaël Salaün
2024-07-29 14:21 ` Jann Horn
2024-07-29 15:02 ` Mickaël Salaün
2024-07-29 15:06 ` Jann Horn
2024-07-29 15:17 ` Mickaël Salaün
2024-07-31 20:29 ` Paul Moore
2024-07-31 20:53 ` Jann Horn
2024-07-31 21:27 ` Paul Moore
2024-07-31 21:33 ` Jann Horn
2024-08-01 15:34 ` Mickaël Salaün
2024-08-02 13:12 ` Jann Horn
2024-07-29 14:06 ` Jarkko Sakkinen [this message]
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=D322X0D8UBYG.3FIRWQEBNURZF@iki.fi \
--to=jarkko.sakkinen@iki.fi \
--cc=dhowells@redhat.com \
--cc=gnoack@google.com \
--cc=jannh@google.com \
--cc=jarkko@kernel.org \
--cc=jmorris@namei.org \
--cc=kees@kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=paul@paul-moore.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
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
all inboxes | Powered by JetHome®