linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Jann Horn <jannh@google.com>
Cc: Kees Cook <keescook@chromium.org>,
	Linus Torvalds <torvalds@linuxfoundation.org>,
	stable <stable@vger.kernel.org>, Paul Moore <paul@paul-moore.com>,
	Casey Schaufler <casey@schaufler-ca.com>,
	Oleg Nesterov <oleg@redhat.com>, James Morris <jmorris@namei.org>,
	John Johansen <john.johansen@canonical.com>,
	Stephen Smalley <sds@tycho.nsa.gov>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	kernel list <linux-kernel@vger.kernel.org>,
	linux-security-module <linux-security-module@vger.kernel.org>
Subject: Re: [PATCH] proc: Check /proc/$pid/attr/ writes against file opener
Date: Tue, 25 May 2021 16:24:52 -0500	[thread overview]
Message-ID: <m1r1humrq3.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <CAG48ez2PdgpUj3GYRLDJ9MS1uKMZ4SU77i__vhXvmbzqudzuzA@mail.gmail.com> (Jann Horn's message of "Tue, 25 May 2021 22:49:29 +0200")

Jann Horn <jannh@google.com> writes:

> On Tue, May 25, 2021 at 9:37 PM Kees Cook <keescook@chromium.org> wrote:
>> Fix another "confused deputy" weakness[1]. Writes to /proc/$pid/attr/
>> files need to check the opener credentials, since these fds do not
>> transition state across execve(). Without this, it is possible to
>> trick another process (which may have different credentials) to write
>> to its own /proc/$pid/attr/ files, leading to unexpected and possibly
>> exploitable behaviors.
>>
>> [1] https://www.kernel.org/doc/html/latest/security/credentials.html?highlight=confused#open-file-credentials
>>
>> Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>>  fs/proc/base.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/fs/proc/base.c b/fs/proc/base.c
>> index 3851bfcdba56..58bbf334265b 100644
>> --- a/fs/proc/base.c
>> +++ b/fs/proc/base.c
>> @@ -2703,6 +2703,10 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
>>         void *page;
>>         int rv;
>>
>> +       /* A task may only write when it was the opener. */
>> +       if (file->f_cred != current_real_cred())
>> +               return -EPERM;
>
> With this, if a task forks, the child will then still be able to open
> its parent's /proc/$pid/attr/current and trick the parent into writing
> to that, right? Is that acceptable? If not, the ->open handler should
> probably also check for "current->thread_pid == proc_pid(inode)", or
> something like that?

Currently exec always allocates a new cred.  So you can only ``trick''
another process that was forked from you.  I don't think it counts as
tricking or any kind of danger if you are simply confusing yourself.

Eric


      reply	other threads:[~2021-05-25 21:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25 19:37 [PATCH] proc: Check /proc/$pid/attr/ writes against file opener Kees Cook
2021-05-25 20:49 ` Jann Horn
2021-05-25 21:24   ` Eric W. Biederman [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=m1r1humrq3.fsf@fess.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=casey@schaufler-ca.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jannh@google.com \
    --cc=jmorris@namei.org \
    --cc=john.johansen@canonical.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=sds@tycho.nsa.gov \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linuxfoundation.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).