All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Alexey Gladkov <gladkov.alexey@gmail.com>
Subject: Re: [GIT PULL] Please pull proc and exec work for 5.7-rc1
Date: Thu, 2 Apr 2020 21:31:20 +0200	[thread overview]
Message-ID: <AM6PR03MB5170B606F9AC663225EC9609E4C60@AM6PR03MB5170.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <CAHk-=wgYCUbEmwieOBzVNZbSAM9wCZA8Z0665onpNnEcC-UpDg@mail.gmail.com>

On 4/2/20 9:04 PM, Linus Torvalds wrote:
> On Wed, Apr 1, 2020 at 9:16 AM Eric W. Biederman <ebiederm@xmission.com> wrote:
>>
>> The work on exec starts solving a long standing issue with exec that
>> it takes mutexes of blocking userspace applications, which makes exec
>> extremely deadlock prone.  For the moment this adds a second mutex
>> with a narrower scope that handles all of the easy cases.  Which
>> makes the tricky cases easy to spot.  With a little luck the code to
>> solve those deadlocks will be ready by next merge window.
> 
> So this worries me.
> 
> I've pulled it, but I'm not entirely happy about some of it.
> 
> For example, the "rationale" for some of the changes is
> 
>     This should be safe, as the credentials are only used for reading.
> 

What I meant, but did probably not find a good way to say it.

There are places where credentials of other threads are written,
e.g. set no new privs on a thread, that already started to execve
a setuid process.

You always have the right to change the credentials of the own thread,
you dont need a mutex for it.

This is at least what is my impression how the existing mutexes are used,
a mutex called "cred_guard_mutex" is a not very good self explaining name,
in my opinion, it is totally unclear what it does "guard", and why.


Bernd.

> which is just nonsensical. "Only used for reading" is immaterial, and
> there's no explanation for why that would matter at all. Most of the
> credentials are ever used for reading, and the worry about execve() is
> that the credentials can change, and people race with them and use the
> new 'suid' credentials and allow things that shouldn't be allowed. So
> the rationale makes no sense at all.
> 
> Btw, if "this only takes it for reading" is such a big deal, why is
> that mutex not an rw-semaphore?
> 
> The pidfd change at least has a rationale that makes sense:
> 
>     This should be safe, as the credentials do not change
>     before exec_update_mutex is locked.  Therefore whatever
>     file access is possible with holding the cred_guard_mutex
>     here is also possbile with the exec_update_mutex.
> 
> so now you at least have an explanation of why that particular lock
> makes sense and works and is equivalent.
> 
> It's still not a *great* explanation for why it would be equivalent,
> because cred_guard_mutex ends up not just guarding the write of the
> credentials, but makes it atomic wrt *other* data. That's the same
> problem as "I'm only reading".
> 
> Locking is not about *one* value being consistent - if that was the
> case, then you could just do a "get refcount on the credentials, now I
> have a stable set of creds I can read forever". No lock needed.
> 
> So locking is about *multiple* values being consistent, which is why
> that "I'm only reading" is not an explanation for why you can change
> the lock.
> 
> It's also why that second one is questionable: it's a _better_ attempt
> at explaining things, but the point is really that cred_guard_mutex
> protects *other* things too.
> 
> A real explanation would have absolutely *nothing* to do with
> "reading" or "same value of credentials". Both of those are entirely
> immaterial, since - as mentioned - you could just get a snapshot of
> the creds instead.
> 
> A real explanation would be about how there is no other state that
> cred_guard_mutex protects that matters.
> 
> See what I'm saying?
> 
> This code is subtle as h*ll, and we've had bugs in it, and it has a
> series of tens of patches to fix them. But that also means that the
> explanations for the patches should take the subtleties into account,
> and not gloss over them with things like this.
> 
> Ok, enough about the explanations. The actual _code_ is kind of odd
> too. For example, you have that "bprm->called_exec_mmap" flag to say
> "I've taken the exec_update_mutex, and need to drop it".
> 
> But that flag is not set anywhere _near_ actually taking the lock.
> Sure, it is taken after exec_mmap() returns successfully, and that
> makes sense from a naming standpoint, but wouldn't it have been a
> _lot_ more obvious if you just set the flag when you took that lock,
> and instead of naming it by some magical code sequence, you named it
> for what it does?
> 
> Again, this looks all technically correct, but it's written in a way
> that doesn't seem to make a lot of sense. Why is the code literally
> written with a magical assumption of "calling exec_mmap takes this
> lock, so if the flag named called_exec_mmap is set, I have to free
> that lock that is not named that at all".
> 
> I hate conditional locking in the first place, but if it has to exist,
> then the conditional should be named after the lock, and the lock
> getting should be very very explicitly tied to it.
> 
> Wouldn't it have been much clearer if you called that flag
> "exec_update_mutex_taken", and set it WHEN YOU TAKE IT?
> 
> In fact, then you could drop the
> 
>                         mutex_unlock(&tsk->signal->exec_update_mutex);
> 
> in the error case of exec_mmap(), because now the error handling in
> free_bprm() would do the cleanup automatically.
> 
> See what I'm saying? You've made the locking more complex and subtle
> than it needed to be. And since the whole point of the *new* lock is
> that it should replace an old lock that was really complex and subtle,
> that's a problem.
> 
>                    Linus
> 

  reply	other threads:[~2020-04-02 19:31 UTC|newest]

Thread overview: 127+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87blobnq02.fsf@x220.int.ebiederm.org>
2020-04-02 19:04 ` [GIT PULL] Please pull proc and exec work for 5.7-rc1 Linus Torvalds
2020-04-02 19:31   ` Bernd Edlinger [this message]
2020-04-02 19:52     ` Linus Torvalds
2020-04-02 20:59       ` Bernd Edlinger
2020-04-02 21:46         ` Linus Torvalds
2020-04-02 23:01           ` Eric W. Biederman
2020-04-02 23:42             ` Bernd Edlinger
2020-04-02 23:45               ` Eric W. Biederman
2020-04-02 23:49                 ` Bernd Edlinger
2020-04-02 23:45               ` Linus Torvalds
2020-04-02 23:44             ` Linus Torvalds
2020-04-03  0:05               ` Eric W. Biederman
2020-04-07  1:29               ` [RFC][PATCH 0/3] exec_update_mutex related cleanups Eric W. Biederman
2020-04-07  1:31                 ` [PATCH 1/3] binfmt: Move install_exec_creds after setup_new_exec to match binfmt_elf Eric W. Biederman
2020-04-07 15:58                   ` Kees Cook
2020-04-07 16:11                   ` Christian Brauner
2020-04-08 17:25                   ` Linus Torvalds
2020-04-08 19:51                     ` Eric W. Biederman
2020-04-07  1:31                 ` [PATCH 2/3] exec: Make unlocking exec_update_mutex explict Eric W. Biederman
2020-04-07 16:02                   ` Kees Cook
2020-04-07 16:17                   ` Christian Brauner
2020-04-07 16:21                     ` Eric W. Biederman
2020-04-07  1:32                 ` [PATCH 3/3] exec: Rename the flag called_exec_mmap point_of_no_return Eric W. Biederman
2020-04-07 16:03                   ` Kees Cook
2020-04-07 16:21                   ` Christian Brauner
2020-04-07 16:22                 ` [RFC][PATCH 0/3] exec_update_mutex related cleanups Christian Brauner
2020-04-08 17:26                 ` Linus Torvalds
2020-04-03  5:09             ` [GIT PULL] Please pull proc and exec work for 5.7-rc1 Bernd Edlinger
2020-04-03 19:26             ` Linus Torvalds
2020-04-03 20:41               ` Waiman Long
2020-04-03 20:59                 ` Linus Torvalds
2020-04-03 23:16                   ` Waiman Long
2020-04-03 23:23                     ` Waiman Long
2020-04-04  1:30                       ` Linus Torvalds
2020-04-04  2:02                         ` Waiman Long
2020-04-04  2:28                           ` Linus Torvalds
2020-04-04  6:34                             ` Bernd Edlinger
2020-04-05  6:34                               ` Bernd Edlinger
2020-04-05 19:35                                 ` Linus Torvalds
2020-04-05  2:42                             ` Waiman Long
2020-04-05  3:35                               ` Bernd Edlinger
2020-04-05  3:45                                 ` Waiman Long
2020-04-06 13:13                             ` Will Deacon
2020-04-04  4:23                     ` Bernd Edlinger
2020-04-06 22:17               ` Eric W. Biederman
2020-04-07 19:50                 ` Linus Torvalds
2020-04-07 20:29                   ` Bernd Edlinger
2020-04-07 20:47                     ` Linus Torvalds
2020-04-08 15:14                   ` Eric W. Biederman
2020-04-08 15:21                     ` Bernd Edlinger
2020-04-08 16:34                     ` Linus Torvalds
2020-04-09 14:58                       ` Eric W. Biederman
2020-04-09 15:15                         ` Bernd Edlinger
2020-04-09 16:15                         ` Linus Torvalds
2020-04-09 16:24                           ` Linus Torvalds
2020-04-09 17:03                             ` Eric W. Biederman
2020-04-09 17:17                               ` Bernd Edlinger
2020-04-09 17:37                                 ` Linus Torvalds
2020-04-09 17:46                                   ` Bernd Edlinger
2020-04-09 18:36                                     ` Linus Torvalds
2020-04-09 19:42                                       ` Linus Torvalds
2020-04-09 19:57                                         ` Bernd Edlinger
2020-04-09 20:04                                           ` Linus Torvalds
2020-04-09 20:36                                             ` Bernd Edlinger
2020-04-09 21:00                                             ` Eric W. Biederman
2020-04-09 21:17                                               ` Linus Torvalds
2020-04-09 23:52                                                 ` Bernd Edlinger
2020-04-10  0:30                                                 ` Linus Torvalds
2020-04-10  0:32                                                   ` Linus Torvalds
2020-04-11  4:07                                                     ` Bernd Edlinger
2020-04-11 18:20                                                   ` Oleg Nesterov
2020-04-11 18:29                                                     ` Linus Torvalds
2020-04-11 18:31                                                       ` Linus Torvalds
2020-04-11 19:15                                                       ` Bernd Edlinger
2020-04-11 20:07                                                         ` Linus Torvalds
2020-04-11 21:16                                                           ` Bernd Edlinger
     [not found]                                                             ` <CAHk-=wgWHkBzFazWJj57emHPd3Dg9SZHaZqoO7-AD+UbBTJgig@mail.gmail.com>
2020-04-11 21:57                                                               ` Linus Torvalds
2020-04-12  6:01                                                                 ` Bernd Edlinger
2020-04-12 19:50                                                       ` Oleg Nesterov
2020-04-12 20:14                                                         ` Linus Torvalds
2020-04-28  2:56                                                           ` Bernd Edlinger
2020-04-28 17:07                                                             ` Linus Torvalds
2020-04-28 19:08                                                               ` Oleg Nesterov
2020-04-28 20:35                                                                 ` Linus Torvalds
2020-04-28 21:06                                                                   ` Jann Horn
2020-04-28 21:36                                                                     ` Linus Torvalds
2020-04-28 21:53                                                                       ` Jann Horn
2020-04-28 22:14                                                                         ` Linus Torvalds
2020-04-28 23:36                                                                           ` Jann Horn
2020-04-29 17:58                                                                             ` Linus Torvalds
2020-04-29 18:33                                                                               ` Jann Horn
2020-04-29 18:57                                                                                 ` Linus Torvalds
2020-04-29 19:23                                                                               ` Bernd Edlinger
2020-04-29 19:26                                                                                 ` Jann Horn
2020-04-29 20:19                                                                                   ` Bernd Edlinger
2020-04-29 21:06                                                                                     ` Jann Horn
2020-04-29 22:38                                                                                 ` Linus Torvalds
2020-04-29 23:22                                                                                   ` Linus Torvalds
2020-04-29 23:59                                                                                     ` Jann Horn
2020-04-30  1:08                                                                                       ` Bernd Edlinger
2020-04-30  2:20                                                                                         ` Linus Torvalds
2020-04-30  3:00                                                                                           ` Jann Horn
2020-04-30  3:25                                                                                             ` Linus Torvalds
2020-04-30  3:41                                                                                               ` Jann Horn
2020-04-30  3:50                                                                                                 ` Linus Torvalds
2020-04-30 13:37                                                                                               ` Linus Torvalds
2020-04-30  2:16                                                                                       ` Linus Torvalds
2020-04-30 13:39                                                                                         ` Bernd Edlinger
2020-04-30 13:47                                                                                           ` Linus Torvalds
2020-04-30 14:29                                                                                             ` Bernd Edlinger
2020-04-30 16:40                                                                                               ` Linus Torvalds
2020-05-02  4:11                                                                                                 ` Bernd Edlinger
2020-04-09 17:36                               ` Linus Torvalds
2020-04-09 20:34                                 ` Eric W. Biederman
2020-04-09 20:56                                   ` Linus Torvalds
2020-04-02 23:02           ` Bernd Edlinger
2020-04-02 23:22           ` Bernd Edlinger
2020-04-03  7:38           ` Bernd Edlinger
2020-04-03 16:00       ` Bernd Edlinger
2020-04-03 15:09   ` Bernd Edlinger
2020-04-03 16:23     ` Linus Torvalds
2020-04-03 16:36       ` Bernd Edlinger
2020-04-04  5:43       ` Bernd Edlinger
2020-04-04  5:48         ` Bernd Edlinger
2020-04-06  6:41           ` Bernd Edlinger
2020-04-10 13:03 ` [GIT PULL] proc fix " Eric W. Biederman
2020-04-10 20:40   ` pr-tracker-bot

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=AM6PR03MB5170B606F9AC663225EC9609E4C60@AM6PR03MB5170.eurprd03.prod.outlook.com \
    --to=bernd.edlinger@hotmail.de \
    --cc=ebiederm@xmission.com \
    --cc=gladkov.alexey@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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.