Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1640998 > unrolled thread

Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

Started byMatt Brown <matt@nmatt.com>
First post2017-05-13 22:00 +0200
Last post2017-05-19 16:40 +0200
Articles 16 — 6 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require  CAP_SYS_ADMIN Matt Brown <matt@nmatt.com> - 2017-05-13 22:00 +0200
    Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require  CAP_SYS_ADMIN Alan Cox <gnomes@lxorguk.ukuu.org.uk> - 2017-05-15 23:00 +0200
      Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN Peter Dolding <oiaohm@gmail.com> - 2017-05-16 01:20 +0200
        Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require  CAP_SYS_ADMIN Matt Brown <matt@nmatt.com> - 2017-05-16 06:20 +0200
          Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN Peter Dolding <oiaohm@gmail.com> - 2017-05-16 11:10 +0200
            Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require  CAP_SYS_ADMIN Matt Brown <matt@nmatt.com> - 2017-05-16 14:30 +0200
              Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN Kees Cook <keescook@chromium.org> - 2017-05-16 16:30 +0200
                Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make  TIOCSTI ioctl require CAP_SYS_ADMIN "Serge E. Hallyn" <serge@hallyn.com> - 2017-05-16 17:50 +0200
                  Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI  ioctl require CAP_SYS_ADMIN Peter Dolding <oiaohm@gmail.com> - 2017-05-17 00:10 +0200
                Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN Peter Dolding <oiaohm@gmail.com> - 2017-05-16 23:50 +0200
                  Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require  CAP_SYS_ADMIN Matt Brown <matt@nmatt.com> - 2017-05-17 00:00 +0200
                Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require  CAP_SYS_ADMIN Alan Cox <gnomes@lxorguk.ukuu.org.uk> - 2017-05-17 18:50 +0200
                  Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make  TIOCSTI ioctl require CAP_SYS_ADMIN Daniel Micay <danielmicay@gmail.com> - 2017-05-17 20:30 +0200
                    Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI  ioctl require CAP_SYS_ADMIN Kees Cook <keescook@chromium.org> - 2017-05-18 05:20 +0200
                      Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI  ioctl require CAP_SYS_ADMIN Peter Dolding <oiaohm@gmail.com> - 2017-05-19 04:50 +0200
                        Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make  TIOCSTI ioctl require CAP_SYS_ADMIN "Serge E. Hallyn" <serge@hallyn.com> - 2017-05-19 16:40 +0200

#1640998 — Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

FromMatt Brown <matt@nmatt.com>
Date2017-05-13 22:00 +0200
SubjectRe: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tGLmN-88a-9@gated-at.bofh.it>
On 05/10/2017 04:29 PM, Alan Cox wrote:
> On Fri,  5 May 2017 19:20:16 -0400
> Matt Brown <matt@nmatt.com> wrote:
>
>> This patchset introduces the tiocsti_restrict sysctl, whose default is
>> controlled via CONFIG_SECURITY_TIOCSTI_RESTRICT. When activated, this
>> control restricts all TIOCSTI ioctl calls from non CAP_SYS_ADMIN users.
>>
>> This patch was inspired from GRKERNSEC_HARDEN_TTY.
>>
>> This patch would have prevented
>> https://bugzilla.redhat.com/show_bug.cgi?id=1411256 under the following
>> conditions:
>> * non-privileged container
>> * container run inside new user namespace
>>
>> Possible effects on userland:
>>
>> There could be a few user programs that would be effected by this
>> change.
>> See: <https://codesearch.debian.net/search?q=ioctl%5C%28.*TIOCSTI>
>> notable programs are: agetty, csh, xemacs and tcsh
>>
>> However, I still believe that this change is worth it given that the
>> Kconfig defaults to n.
>
> And it still doesn't deal with the fact that there are hundreds of other
> ways to annoy the owner of a tty if it's passed to a lower privilege
> child from framebuffer reprogramming through keyboard remaps.
>
> The proper way to handle those cases is to create a pty/tty pair and use
> that. Your patch is pure snake oil and if anything implies safety that
> doesn't exist.
>

I'm not implying that my patch is supposed to provide safety for
"hundreds of other" issues. I'm looking to provide a way to lock down a
single TTY ioctl that has caused real security issues to arise. For
this reason, it's completely incorrect to say that this feature is
snake oil. My patch does exactly what it claims to do. No more no less.

> In addition your change to allow it to be used by root in the guest
> completely invalidates any protection you have because I can push
>
> "rm -rf /\n"
>
> as root in my namespace and exit
>
> The tty buffers are not flushed across the context change so the shell
> you return to gets the input and oh dear....

This is precisely what my patch prevents! With my protection enabled, a
container will only be able to use the TIOCSTI ioctl on a tty if that
container has CAP_SYS_ADMIN in the user namespace in which the tty was
created.

>
> Alan
>

[toc] | [next] | [standalone]


#1642055

FromAlan Cox <gnomes@lxorguk.ukuu.org.uk>
Date2017-05-15 23:00 +0200
Message-ID<tHvfX-4zw-5@gated-at.bofh.it>
In reply to#1640998
O> I'm not implying that my patch is supposed to provide safety for
> "hundreds of other" issues. I'm looking to provide a way to lock down a
> single TTY ioctl that has caused real security issues to arise. For

In other words you are not actually fixing anything.

> this reason, it's completely incorrect to say that this feature is
> snake oil. My patch does exactly what it claims to do. No more no less.
> 
> > In addition your change to allow it to be used by root in the guest
> > completely invalidates any protection you have because I can push
> >
> > "rm -rf /\n"
> >
> > as root in my namespace and exit
> >
> > The tty buffers are not flushed across the context change so the shell
> > you return to gets the input and oh dear....  
> 
> This is precisely what my patch prevents! With my protection enabled, a
> container will only be able to use the TIOCSTI ioctl on a tty if that
> container has CAP_SYS_ADMIN in the user namespace in which the tty was
> created.

Which is not necessarily the namespace of the process that next issues a
read().

This is snake oil. There is a correct and proper process for this use
case. That proper process is to create a new pty/tty pair. There are two
cases

- processes that do it right in which case the attacker is screwed and we
  don't need to mess up TIOCSTI handling for no reason.

- processes that do it wrong. If they do it wrong then they'll also use
  all the other holes and attacks available via the same path which are
  completely unfixable without making your system basically unusable.


So can we please apply the minimum of common sense reasoning to this and
drop the patch.

Alan

[toc] | [prev] | [next] | [standalone]


#1642119 — Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

FromPeter Dolding <oiaohm@gmail.com>
Date2017-05-16 01:20 +0200
SubjectRe: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tHxrr-6b0-9@gated-at.bofh.it>
In reply to#1642055
On Tue, May 16, 2017 at 6:57 AM, Alan Cox <gnomes@lxorguk.ukuu.org.uk> wrote:
> O> I'm not implying that my patch is supposed to provide safety for
>> "hundreds of other" issues. I'm looking to provide a way to lock down a
>> single TTY ioctl that has caused real security issues to arise. For
>
> In other words you are not actually fixing anything.
>
>> this reason, it's completely incorrect to say that this feature is
>> snake oil. My patch does exactly what it claims to do. No more no less.
>>
>> > In addition your change to allow it to be used by root in the guest
>> > completely invalidates any protection you have because I can push
>> >
>> > "rm -rf /\n"
>> >
>> > as root in my namespace and exit
>> >
>> > The tty buffers are not flushed across the context change so the shell
>> > you return to gets the input and oh dear....
>>
>> This is precisely what my patch prevents! With my protection enabled, a
>> container will only be able to use the TIOCSTI ioctl on a tty if that
>> container has CAP_SYS_ADMIN in the user namespace in which the tty was
>> created.
>
> Which is not necessarily the namespace of the process that next issues a
> read().
>
> This is snake oil. There is a correct and proper process for this use
> case. That proper process is to create a new pty/tty pair. There are two
> cases
>
> - processes that do it right in which case the attacker is screwed and we
>   don't need to mess up TIOCSTI handling for no reason.
>
> - processes that do it wrong. If they do it wrong then they'll also use
>   all the other holes and attacks available via the same path which are
>   completely unfixable without making your system basically unusable.
>
>
> So can we please apply the minimum of common sense reasoning to this and
> drop the patch.
>
> Alan
You missed some important.

From: http://man7.org/linux/man-pages/man7/capabilities.7.html
Don't choose CAP_SYS_ADMIN if you can possibly avoid it!
A vast  proportion of existing capability checks are associated with this
capability (see the partial list above).  It can plausibly be
called "the new root", since on the one hand, it confers a wide
range of powers, and on the other hand, its broad scope means that
 this is the capability that is required by many privileged
programs.  Don't make the problem worse.  The only new features
that should be associated with CAP_SYS_ADMIN are ones that closely
match existing uses in that silo.

This not only a improper fix the attempted fix is breach do
documentation.   CAP_SYS_ADMIN is that far overloaded it does not
require any more thrown in it direction.

This is one of the grsecurity patches mistakes.   GRKERNSEC_HARDEN_TTY
 is from 18 Feb 2016 this documentation as in place at the time they
wrote this.  Yes GRKERNSEC_HARDEN_TTY does exactly the same thing.
Yes Grsecurity guys did the same error and the grsecurity patches are
filled with this error.

The result is from the TIOCSTI patch done this way is you have to use
CAP_SYS_ADMIN to use TIOSCTI so opening up every exploit that
Grsecurity has added and every exploit CAP_SYS_ADMIN can do what is
quite a few.

Now I don't know if CAP_SYS_TTY_CONFIG what is an existing capability
might be what TIOCSTI should own under.

The reality here is CAP_SYS_ADMIN as become the Linux kernel security
equal what big kernel lock was for multi threading.

 In a ideal world CAP_SYS_ADMIN would not be used directly in most
cases.  Instead CAP_SYS_ADMIN would have a stack of sub capabilities
groups under it.

The excuse for doing it wrong grsecurity is
https://forums.grsecurity.net/viewtopic.php?f=7&t=2522

Yes most capabilities open up possibility of exploiting the system.
They are not in fact designed to prevent this.   They are designed to
limit the damage in case of malfunction so that a program/user has
only limited methods of damaging the system.  Like a program
malfunctioning with only limit capabilities if it does an action those
capabilities don't allow no damage will happen.   Now CAP_SYS_ADMIN is
for sure not limited.

But since grsecurity developers took the point of view these are False
Boundaries they then proceed to stack item after item under
CAP_SYS_ADMIN because the boundary made no sense to them.    Also some
mainline Linux Kernel developers are guilty of the same sin of
overloading CAP_SYS_ADMIN.

From my point of view any new patching containing CAP_SYS_ADMIN
directly used should be bounced just for that.   If features need to
be added to CAP_SYS_ADMIN now they should have to go into another
capability that is enabled when  CAP_SYS_ADMIN is and hopeful if we do
this over time we will be able to clean up CAP_SYS_ADMIN into sanity.


Peter

[toc] | [prev] | [next] | [standalone]


#1642197

FromMatt Brown <matt@nmatt.com>
Date2017-05-16 06:20 +0200
Message-ID<tHC7L-GS-1@gated-at.bofh.it>
In reply to#1642119
On 05/15/2017 07:10 PM, Peter Dolding wrote:
> On Tue, May 16, 2017 at 6:57 AM, Alan Cox <gnomes@lxorguk.ukuu.org.uk> wrote:
>> O> I'm not implying that my patch is supposed to provide safety for
>>> "hundreds of other" issues. I'm looking to provide a way to lock down a
>>> single TTY ioctl that has caused real security issues to arise. For
>>
>> In other words you are not actually fixing anything.
>>
>>> this reason, it's completely incorrect to say that this feature is
>>> snake oil. My patch does exactly what it claims to do. No more no less.
>>>
>>>> In addition your change to allow it to be used by root in the guest
>>>> completely invalidates any protection you have because I can push
>>>>
>>>> "rm -rf /\n"
>>>>
>>>> as root in my namespace and exit
>>>>
>>>> The tty buffers are not flushed across the context change so the shell
>>>> you return to gets the input and oh dear....
>>>
>>> This is precisely what my patch prevents! With my protection enabled, a
>>> container will only be able to use the TIOCSTI ioctl on a tty if that
>>> container has CAP_SYS_ADMIN in the user namespace in which the tty was
>>> created.
>>
>> Which is not necessarily the namespace of the process that next issues a
>> read().
>>
>> This is snake oil. There is a correct and proper process for this use
>> case. That proper process is to create a new pty/tty pair. There are two
>> cases
>>
>> - processes that do it right in which case the attacker is screwed and we
>>   don't need to mess up TIOCSTI handling for no reason.
>>
>> - processes that do it wrong. If they do it wrong then they'll also use
>>   all the other holes and attacks available via the same path which are
>>   completely unfixable without making your system basically unusable.
>>
>>
>> So can we please apply the minimum of common sense reasoning to this and
>> drop the patch.
>>
>> Alan
> You missed some important.
>
> From: http://man7.org/linux/man-pages/man7/capabilities.7.html
> Don't choose CAP_SYS_ADMIN if you can possibly avoid it!
> A vast  proportion of existing capability checks are associated with this
> capability (see the partial list above).  It can plausibly be
> called "the new root", since on the one hand, it confers a wide
> range of powers, and on the other hand, its broad scope means that
>  this is the capability that is required by many privileged
> programs.  Don't make the problem worse.  The only new features
> that should be associated with CAP_SYS_ADMIN are ones that closely
> match existing uses in that silo.
>

That last sentence is the key. CAP_SYS_ADMIN is already associated with
the TIOCSTI ioctl!

 From the same capabilities man page you quote above
under the CAP_SYS_ADMIN section:
employ the TIOCSTI ioctl(2) to insert characters into the input queue
of a terminal other than the caller's controlling terminal;

> This not only a improper fix the attempted fix is breach do
> documentation.   CAP_SYS_ADMIN is that far overloaded it does not
> require any more thrown in it direction.
>

See my comment above. This is clearly following the capabilities
documentation since CAP_SYS_ADMIN is already closely linked with the
TIOCSTI ioctl.

> This is one of the grsecurity patches mistakes.   GRKERNSEC_HARDEN_TTY
>  is from 18 Feb 2016 this documentation as in place at the time they
> wrote this.  Yes GRKERNSEC_HARDEN_TTY does exactly the same thing.
> Yes Grsecurity guys did the same error and the grsecurity patches are
> filled with this error.
>
> The result is from the TIOCSTI patch done this way is you have to use
> CAP_SYS_ADMIN to use TIOSCTI so opening up every exploit that
> Grsecurity has added and every exploit CAP_SYS_ADMIN can do what is
> quite a few.
>
> Now I don't know if CAP_SYS_TTY_CONFIG what is an existing capability
> might be what TIOCSTI should own under.
>

I could see a case being make for CAP_SYS_TTY_CONFIG. However I still
choose to do with CAP_SYS_ADMIN because it is already in use in the
TIOCSTI ioctl.

> The reality here is CAP_SYS_ADMIN as become the Linux kernel security
> equal what big kernel lock was for multi threading.
>
>  In a ideal world CAP_SYS_ADMIN would not be used directly in most
> cases.  Instead CAP_SYS_ADMIN would have a stack of sub capabilities
> groups under it.
>
> The excuse for doing it wrong grsecurity is
> https://forums.grsecurity.net/viewtopic.php?f=7&t=2522
>
> Yes most capabilities open up possibility of exploiting the system.
> They are not in fact designed to prevent this.   They are designed to
> limit the damage in case of malfunction so that a program/user has
> only limited methods of damaging the system.  Like a program
> malfunctioning with only limit capabilities if it does an action those
> capabilities don't allow no damage will happen.   Now CAP_SYS_ADMIN is
> for sure not limited.
>
> But since grsecurity developers took the point of view these are False
> Boundaries they then proceed to stack item after item under
> CAP_SYS_ADMIN because the boundary made no sense to them.    Also some
> mainline Linux Kernel developers are guilty of the same sin of
> overloading CAP_SYS_ADMIN.
>
> From my point of view any new patching containing CAP_SYS_ADMIN
> directly used should be bounced just for that.   If features need to
> be added to CAP_SYS_ADMIN now they should have to go into another
> capability that is enabled when  CAP_SYS_ADMIN is and hopeful if we do
> this over time we will be able to clean up CAP_SYS_ADMIN into sanity.
>

You might be right that CAP_SYS_ADMIN is overloaded, but my patch
barely adds anything to it since TIOCSTI already falls under its
control. It seems extreme to say this patch ought to be rejected just
because it contains CAP_SYS_ADMIN. If we want to fix the state of Linux
capabilities, then I suggest that should be a separate patchset to
reorganize them into a more modular set of controls.

>
> Peter
>

[toc] | [prev] | [next] | [standalone]


#1642325 — Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

FromPeter Dolding <oiaohm@gmail.com>
Date2017-05-16 11:10 +0200
SubjectRe: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tHGEq-3GY-23@gated-at.bofh.it>
In reply to#1642197
>
> I could see a case being make for CAP_SYS_TTY_CONFIG. However I still
> choose to do with CAP_SYS_ADMIN because it is already in use in the
> TIOCSTI ioctl.
>
Matt Brown don't give me existing behaviour.    CAP_SYS_ADMIN is
overload.   The documentation tells you that you are not to expand it
and you openly admit you have.

Does anything of TIOSCTI functionally say that it really should be in
CAP_SYS_ADMIN.

If functionality is going to cause security for containers maybe it
should be not in CAP_SYS_ADMIN but in its own capability that can
enabled on file by file base.

>
> You might be right that CAP_SYS_ADMIN is overloaded, but my patch
> barely adds anything to it since TIOCSTI already falls under its
> control. It seems extreme to say this patch ought to be rejected just
> because it contains CAP_SYS_ADMIN. If we want to fix the state of Linux
> capabilities, then I suggest that should be a separate patchset to
> reorganize them into a more modular set of controls.
>
We have end up with CAP_SYS_ADMIN a mess by the of a death by a
thousand cuts.   Each person to extend CAP_SYS_ADMIN to it current
mess said the same thing.   My patch barely added anything times that
by a few thousand and you end up with what we have today.   At some
point no more has to be said.

There is no point attempting to tidy it up of the rules are not put in
place so it does not turn into a mess again.

This is not something that is suitable to be done as one large
patchset.   This is better done in the same kind of method that made
it.  So every time people want to alter something associated with
CAP_SYS_ADMIN it has to get assessed and the patch has to be one that
partly corrects the existing mess.    Do this enough times and we will
no longer have a mess on CAP_SYS_ADMIN.

https://www.freedesktop.org/software/systemd/man/systemd.exec.html
Please note the CapabilityBoundingSet=

Your current patch adds no extra controls for me running a service
under systemd or anything else like it to say I don't want the
processes having the means to-do this even that they are running with
CAP_SYS_ADMIN to perform other tasks..

--employ the TIOCSTI ioctl(2) to insert characters into the input
queue of a terminal other than the caller's controlling terminal;--
This currently under CAP_SYS_ADMIN is vastly more powerful than the
one you are attempt to take away with your patch.  This one can send
messages into other terminals.   This is a vastly more powerful
version of TIOSCTI.

I fact this usage of TIOCSTI I personally think should require two
capabilities flags set.   CAP_SYS_ADMIN section left as it is at this
stage.   With TIOSCTI stuck behind another capability.

If you had added a new capability flag you could set file capabilities
on any of the old applications depending on the now secured behaviour.

https://github.com/lxc/lxc/commit/e986ea3dfa4a2957f71ae9bfaed406dd6e1ffff6

Also the general user TIOCSTI issue can be handled a different way as
LXC fix shows.  Where they uses a pty to isolate so meaning in their
fixed setup user TIOSCTI was not harmful but CAP_SYS_ADMIN TIOSCTI
still could be.  You patch as not address this problem because you
shoved everything under CAP_SYS_ADMIN.   But if you add different
capability to use TIOSCIT that is not CAP_SYS_ADMIN  to allow
CAP_SYS_ADMiN TIOSCTI functionality to be disabled.

This is what you see more often than not when you dig into this
patches adding more CAP_SYS_ADMIN.  Adding CAP_SYS_ADMIN is not fixing
a problem in most cases.   Breaking CAP_SYS_ADMIN functionality up
should be the goal not expand it.

Basically you have done something documentation has a note to
developer not to-do.   If you start looking at the problem what you
doing is not helping.   If people end up using CAP_SYS_ADMIN to access
TIOSCTI its giving the program a more powerful version of TIOSCTI to
do more harm with so reduced containment.  Totally anti to what you
are meant to be doing with capabilities..

[toc] | [prev] | [next] | [standalone]


#1642520

FromMatt Brown <matt@nmatt.com>
Date2017-05-16 14:30 +0200
Message-ID<tHJM0-5yL-71@gated-at.bofh.it>
In reply to#1642325
On 05/16/2017 05:01 AM, Peter Dolding wrote:
>>
>> I could see a case being make for CAP_SYS_TTY_CONFIG. However I still
>> choose to do with CAP_SYS_ADMIN because it is already in use in the
>> TIOCSTI ioctl.
>>
> Matt Brown don't give me existing behaviour.    CAP_SYS_ADMIN is
> overload.   The documentation tells you that you are not to expand it
> and you openly admit you have.
>

This is not true that I'm openly going against what the documentation
instructs. The part of the email chain where I show this got removed
somehow. Again I will refer to the capabilities man page that you
quoted.

 From http://man7.org/linux/man-pages/man7/capabilities.7.html

"Don't choose CAP_SYS_ADMIN if you can possibly avoid it!
...
The only new features that should be associated with CAP_SYS_ADMIN are
ones that closely match existing uses in that silo."

My feature affects the TIOCSTI ioctl. The TIOCSTI ioctl already falls
under CAP_SYS_ADMIN, therefore I actually *am* following the
documentation.

> Does anything of TIOSCTI functionally say that it really should be in
> CAP_SYS_ADMIN.
>
> If functionality is going to cause security for containers maybe it
> should be not in CAP_SYS_ADMIN but in its own capability that can
> enabled on file by file base.
>
>>
>> You might be right that CAP_SYS_ADMIN is overloaded, but my patch
>> barely adds anything to it since TIOCSTI already falls under its
>> control. It seems extreme to say this patch ought to be rejected just
>> because it contains CAP_SYS_ADMIN. If we want to fix the state of Linux
>> capabilities, then I suggest that should be a separate patchset to
>> reorganize them into a more modular set of controls.
>>
> We have end up with CAP_SYS_ADMIN a mess by the of a death by a
> thousand cuts.   Each person to extend CAP_SYS_ADMIN to it current
> mess said the same thing.   My patch barely added anything times that
> by a few thousand and you end up with what we have today.   At some
> point no more has to be said.
>
> There is no point attempting to tidy it up of the rules are not put in
> place so it does not turn into a mess again.
>
> This is not something that is suitable to be done as one large
> patchset.   This is better done in the same kind of method that made
> it.  So every time people want to alter something associated with
> CAP_SYS_ADMIN it has to get assessed and the patch has to be one that
> partly corrects the existing mess.    Do this enough times and we will
> no longer have a mess on CAP_SYS_ADMIN.
>
> https://www.freedesktop.org/software/systemd/man/systemd.exec.html
> Please note the CapabilityBoundingSet=
>
> Your current patch adds no extra controls for me running a service
> under systemd or anything else like it to say I don't want the
> processes having the means to-do this even that they are running with
> CAP_SYS_ADMIN to perform other tasks..
>
> --employ the TIOCSTI ioctl(2) to insert characters into the input
> queue of a terminal other than the caller's controlling terminal;--
> This currently under CAP_SYS_ADMIN is vastly more powerful than the
> one you are attempt to take away with your patch.  This one can send
> messages into other terminals.   This is a vastly more powerful
> version of TIOSCTI.
>
> I fact this usage of TIOCSTI I personally think should require two
> capabilities flags set.   CAP_SYS_ADMIN section left as it is at this
> stage.   With TIOSCTI stuck behind another capability.
>
> If you had added a new capability flag you could set file capabilities
> on any of the old applications depending on the now secured behaviour.
>
> https://github.com/lxc/lxc/commit/e986ea3dfa4a2957f71ae9bfaed406dd6e1ffff6
>
> Also the general user TIOCSTI issue can be handled a different way as
> LXC fix shows.  Where they uses a pty to isolate so meaning in their
> fixed setup user TIOSCTI was not harmful but CAP_SYS_ADMIN TIOSCTI
> still could be.  You patch as not address this problem because you
> shoved everything under CAP_SYS_ADMIN.   But if you add different
> capability to use TIOSCIT that is not CAP_SYS_ADMIN  to allow
> CAP_SYS_ADMiN TIOSCTI functionality to be disabled.
>
> This is what you see more often than not when you dig into this
> patches adding more CAP_SYS_ADMIN.  Adding CAP_SYS_ADMIN is not fixing
> a problem in most cases.   Breaking CAP_SYS_ADMIN functionality up
> should be the goal not expand it.
>
> Basically you have done something documentation has a note to
> developer not to-do.   If you start looking at the problem what you
> doing is not helping.   If people end up using CAP_SYS_ADMIN to access
> TIOSCTI its giving the program a more powerful version of TIOSCTI to
> do more harm with so reduced containment.  Totally anti to what you
> are meant to be doing with capabilities..
>

[toc] | [prev] | [next] | [standalone]


#1642580 — Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

FromKees Cook <keescook@chromium.org>
Date2017-05-16 16:30 +0200
SubjectRe: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tHLE5-6Kq-7@gated-at.bofh.it>
In reply to#1642520
On Tue, May 16, 2017 at 5:22 AM, Matt Brown <matt@nmatt.com> wrote:
> On 05/16/2017 05:01 AM, Peter Dolding wrote:
>>>
>>>
>>> I could see a case being make for CAP_SYS_TTY_CONFIG. However I still
>>> choose to do with CAP_SYS_ADMIN because it is already in use in the
>>> TIOCSTI ioctl.
>>>
>> Matt Brown don't give me existing behaviour.    CAP_SYS_ADMIN is
>> overload.   The documentation tells you that you are not to expand it
>> and you openly admit you have.
>>
>
> This is not true that I'm openly going against what the documentation
> instructs. The part of the email chain where I show this got removed
> somehow. Again I will refer to the capabilities man page that you
> quoted.
>
> From http://man7.org/linux/man-pages/man7/capabilities.7.html
>
> "Don't choose CAP_SYS_ADMIN if you can possibly avoid it!
> ...
> The only new features that should be associated with CAP_SYS_ADMIN are
> ones that closely match existing uses in that silo."
>
> My feature affects the TIOCSTI ioctl. The TIOCSTI ioctl already falls
> under CAP_SYS_ADMIN, therefore I actually *am* following the
> documentation.

CAP_SYS_ADMIN is the right choice here, I agree with Matt: it is
already in use for TIOCSTI. We can't trivially add new capabilities
flags (see the various giant threads debating this, the most recently
that I remember from the kernel lock-down series related to Secure
Boot).

>> I fact this usage of TIOCSTI I personally think should require two
>> capabilities flags set.   CAP_SYS_ADMIN section left as it is at this
>> stage.   With TIOSCTI stuck behind another capability.
>>
>> If you had added a new capability flag you could set file capabilities
>> on any of the old applications depending on the now secured behaviour.

If we're adjusting applications, they should be made to avoid TIOSCTI
completely. This looks to me a lot like the symlink restrictions: yes,
userspace should be fixed to the do the right thing, but why not
provide support to userspace to avoid the problem entirely?

-Kees

-- 
Kees Cook
Pixel Security

[toc] | [prev] | [next] | [standalone]


#1642621 — Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

From"Serge E. Hallyn" <serge@hallyn.com>
Date2017-05-16 17:50 +0200
SubjectRe: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tHMTw-7r2-5@gated-at.bofh.it>
In reply to#1642580
Quoting Kees Cook (keescook@chromium.org):
> On Tue, May 16, 2017 at 5:22 AM, Matt Brown <matt@nmatt.com> wrote:
> > On 05/16/2017 05:01 AM, Peter Dolding wrote:
> >>>
> >>>
> >>> I could see a case being make for CAP_SYS_TTY_CONFIG. However I still
> >>> choose to do with CAP_SYS_ADMIN because it is already in use in the
> >>> TIOCSTI ioctl.
> >>>
> >> Matt Brown don't give me existing behaviour.    CAP_SYS_ADMIN is
> >> overload.   The documentation tells you that you are not to expand it
> >> and you openly admit you have.
> >>
> >
> > This is not true that I'm openly going against what the documentation
> > instructs. The part of the email chain where I show this got removed
> > somehow. Again I will refer to the capabilities man page that you
> > quoted.
> >
> > From http://man7.org/linux/man-pages/man7/capabilities.7.html
> >
> > "Don't choose CAP_SYS_ADMIN if you can possibly avoid it!
> > ...
> > The only new features that should be associated with CAP_SYS_ADMIN are
> > ones that closely match existing uses in that silo."
> >
> > My feature affects the TIOCSTI ioctl. The TIOCSTI ioctl already falls
> > under CAP_SYS_ADMIN, therefore I actually *am* following the
> > documentation.
> 
> CAP_SYS_ADMIN is the right choice here, I agree with Matt: it is
> already in use for TIOCSTI. We can't trivially add new capabilities
> flags (see the various giant threads debating this, the most recently
> that I remember from the kernel lock-down series related to Secure
> Boot).

Consideer that if we use CAP_SYS_TTY_CONFIG now, then any applications
which are currently being given CAP_SYS_ADMIN would need to be updated
with a second capability.  Not acceptable.  Even when we split up
CAP_SYSLOG, we took care to avoid that (by having the original capability
also suffice, so either capability worked).

> >> I fact this usage of TIOCSTI I personally think should require two
> >> capabilities flags set.   CAP_SYS_ADMIN section left as it is at this
> >> stage.   With TIOSCTI stuck behind another capability.
> >>
> >> If you had added a new capability flag you could set file capabilities
> >> on any of the old applications depending on the now secured behaviour.
> 
> If we're adjusting applications, they should be made to avoid TIOSCTI
> completely. This looks to me a lot like the symlink restrictions: yes,
> userspace should be fixed to the do the right thing, but why not
> provide support to userspace to avoid the problem entirely?
> 
> -Kees
> 
> -- 
> Kees Cook
> Pixel Security

[toc] | [prev] | [next] | [standalone]


#1642865 — Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

FromPeter Dolding <oiaohm@gmail.com>
Date2017-05-17 00:10 +0200
SubjectRe: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tHSPh-31N-25@gated-at.bofh.it>
In reply to#1642621
On Wed, May 17, 2017 at 1:48 AM, Serge E. Hallyn <serge@hallyn.com> wrote:
> Quoting Kees Cook (keescook@chromium.org):
>> On Tue, May 16, 2017 at 5:22 AM, Matt Brown <matt@nmatt.com> wrote:
>> > On 05/16/2017 05:01 AM, Peter Dolding wrote:
>> >>>
>> >>>
>> >>> I could see a case being make for CAP_SYS_TTY_CONFIG. However I still
>> >>> choose to do with CAP_SYS_ADMIN because it is already in use in the
>> >>> TIOCSTI ioctl.
>> >>>
>> >> Matt Brown don't give me existing behaviour.    CAP_SYS_ADMIN is
>> >> overload.   The documentation tells you that you are not to expand it
>> >> and you openly admit you have.
>> >>
>> >
>> > This is not true that I'm openly going against what the documentation
>> > instructs. The part of the email chain where I show this got removed
>> > somehow. Again I will refer to the capabilities man page that you
>> > quoted.
>> >
>> > From http://man7.org/linux/man-pages/man7/capabilities.7.html
>> >
>> > "Don't choose CAP_SYS_ADMIN if you can possibly avoid it!
>> > ...
>> > The only new features that should be associated with CAP_SYS_ADMIN are
>> > ones that closely match existing uses in that silo."
>> >
>> > My feature affects the TIOCSTI ioctl. The TIOCSTI ioctl already falls
>> > under CAP_SYS_ADMIN, therefore I actually *am* following the
>> > documentation.
>>
>> CAP_SYS_ADMIN is the right choice here, I agree with Matt: it is
>> already in use for TIOCSTI. We can't trivially add new capabilities
>> flags (see the various giant threads debating this, the most recently
>> that I remember from the kernel lock-down series related to Secure
>> Boot).
>
> Consideer that if we use CAP_SYS_TTY_CONFIG now, then any applications
> which are currently being given CAP_SYS_ADMIN would need to be updated
> with a second capability.  Not acceptable.  Even when we split up
> CAP_SYSLOG, we took care to avoid that (by having the original capability
> also suffice, so either capability worked).
>
There is another option create a security bit.

That could be called SECBIT_CONTAINER.   This turns off functionally
like TIOCSTI that can be used to it break out with.

This case the mainlined code the TIOCSTI currently in CAP_SYS_ADMIN is
a container breaker its designed to allow reaching cross users and
TTYs.   SECBIT is a inverted capability so when it enabled it disables
something and once enabled it cannot be disabled.   So the lxc
addressed to the user TIOCSTI causing a breakout does not work against
the CAP_SYS_ADMIN one.   If there was a security bit that disabled
TIOCSTI completely that prevents all the escape paths by TIOCSTI.

There would also be room for a SECBIT_NO_OBSOLETE what is quite simple
make using obsolete functions application fatal.   Now with CAP_SYSLOG
if SECBIT_NO_OBSOLETE programs using the old capability could find the
feature removed.   So over time we can systematically remove the multi
entry path we have now as userspace updates and stops requiring the
second path.

There is more than 1 way to skin this cat.   There is no need to add
more to CAP_SYS_ADMIN and it particular bad when you consider having
to obey the Linux Rule of user-space compatibly would result in having
apply CAP_SYS_ADMIN to existing applications with Matts patch.

Peter

.

[toc] | [prev] | [next] | [standalone]


#1642850 — Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

FromPeter Dolding <oiaohm@gmail.com>
Date2017-05-16 23:50 +0200
SubjectRe: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tHSvU-2D0-17@gated-at.bofh.it>
In reply to#1642580
On Wed, May 17, 2017 at 12:28 AM, Kees Cook <keescook@chromium.org> wrote:
> On Tue, May 16, 2017 at 5:22 AM, Matt Brown <matt@nmatt.com> wrote:
>> On 05/16/2017 05:01 AM, Peter Dolding wrote:
>>>>
>>>>
>>>> I could see a case being make for CAP_SYS_TTY_CONFIG. However I still
>>>> choose to do with CAP_SYS_ADMIN because it is already in use in the
>>>> TIOCSTI ioctl.
>>>>
>>> Matt Brown don't give me existing behaviour.    CAP_SYS_ADMIN is
>>> overload.   The documentation tells you that you are not to expand it
>>> and you openly admit you have.
>>>
>>
>> This is not true that I'm openly going against what the documentation
>> instructs. The part of the email chain where I show this got removed
>> somehow. Again I will refer to the capabilities man page that you
>> quoted.
>>
>> From http://man7.org/linux/man-pages/man7/capabilities.7.html
>>
>> "Don't choose CAP_SYS_ADMIN if you can possibly avoid it!
>> ...
>> The only new features that should be associated with CAP_SYS_ADMIN are
>> ones that closely match existing uses in that silo."
>>
>> My feature affects the TIOCSTI ioctl. The TIOCSTI ioctl already falls
>> under CAP_SYS_ADMIN, therefore I actually *am* following the
>> documentation.
>
> CAP_SYS_ADMIN is the right choice here, I agree with Matt: it is
> already in use for TIOCSTI. We can't trivially add new capabilities
> flags (see the various giant threads debating this, the most recently
> that I remember from the kernel lock-down series related to Secure
> Boot).

We cannot just keep on expanding CAP_SYS_ADMIN either.
>
>>> I fact this usage of TIOCSTI I personally think should require two
>>> capabilities flags set.   CAP_SYS_ADMIN section left as it is at this
>>> stage.   With TIOSCTI stuck behind another capability.
>>>
>>> If you had added a new capability flag you could set file capabilities
>>> on any of the old applications depending on the now secured behaviour.
>
> If we're adjusting applications, they should be made to avoid TIOSCTI
> completely. This looks to me a lot like the symlink restrictions: yes,
> userspace should be fixed to the do the right thing, but why not
> provide support to userspace to avoid the problem entirely?
>
Kees I like but you have forgot the all important rule.   The Linus
Rule.    Existing applications must  have a method work.
  So modify applications  binary is not way out of problem.

Please note making CAP_SYS_ADMIN the only way to use TIOCSTI also
means setting CAP_SYS_ADMIN on all the existing applications to obey
the Linus Rule of not break userspace.   So this is why the patch is
strictly no as this means elevating privilege of existing applications
and possibly opening up more security flaws.

Reality any patch like the one we are talking about due to the Linus
Rule and the security risk it will open up obey this it just be
rejected.   There is another kind of way I will cover with Serge.

Peter Dolding.

[toc] | [prev] | [next] | [standalone]


#1642856

FromMatt Brown <matt@nmatt.com>
Date2017-05-17 00:00 +0200
Message-ID<tHSFA-2Gq-11@gated-at.bofh.it>
In reply to#1642850
On 05/16/2017 05:43 PM, Peter Dolding wrote:
> On Wed, May 17, 2017 at 12:28 AM, Kees Cook <keescook@chromium.org> wrote:
>> On Tue, May 16, 2017 at 5:22 AM, Matt Brown <matt@nmatt.com> wrote:
>>> On 05/16/2017 05:01 AM, Peter Dolding wrote:
>>>>>
>>>>>
>>>>> I could see a case being make for CAP_SYS_TTY_CONFIG. However I still
>>>>> choose to do with CAP_SYS_ADMIN because it is already in use in the
>>>>> TIOCSTI ioctl.
>>>>>
>>>> Matt Brown don't give me existing behaviour.    CAP_SYS_ADMIN is
>>>> overload.   The documentation tells you that you are not to expand it
>>>> and you openly admit you have.
>>>>
>>>
>>> This is not true that I'm openly going against what the documentation
>>> instructs. The part of the email chain where I show this got removed
>>> somehow. Again I will refer to the capabilities man page that you
>>> quoted.
>>>
>>> From http://man7.org/linux/man-pages/man7/capabilities.7.html
>>>
>>> "Don't choose CAP_SYS_ADMIN if you can possibly avoid it!
>>> ...
>>> The only new features that should be associated with CAP_SYS_ADMIN are
>>> ones that closely match existing uses in that silo."
>>>
>>> My feature affects the TIOCSTI ioctl. The TIOCSTI ioctl already falls
>>> under CAP_SYS_ADMIN, therefore I actually *am* following the
>>> documentation.
>>
>> CAP_SYS_ADMIN is the right choice here, I agree with Matt: it is
>> already in use for TIOCSTI. We can't trivially add new capabilities
>> flags (see the various giant threads debating this, the most recently
>> that I remember from the kernel lock-down series related to Secure
>> Boot).
>
> We cannot just keep on expanding CAP_SYS_ADMIN either.
>>
>>>> I fact this usage of TIOCSTI I personally think should require two
>>>> capabilities flags set.   CAP_SYS_ADMIN section left as it is at this
>>>> stage.   With TIOSCTI stuck behind another capability.
>>>>
>>>> If you had added a new capability flag you could set file capabilities
>>>> on any of the old applications depending on the now secured behaviour.
>>
>> If we're adjusting applications, they should be made to avoid TIOSCTI
>> completely. This looks to me a lot like the symlink restrictions: yes,
>> userspace should be fixed to the do the right thing, but why not
>> provide support to userspace to avoid the problem entirely?
>>
> Kees I like but you have forgot the all important rule.   The Linus
> Rule.    Existing applications must  have a method work.
>   So modify applications  binary is not way out of problem.
>
> Please note making CAP_SYS_ADMIN the only way to use TIOCSTI also
> means setting CAP_SYS_ADMIN on all the existing applications to obey
> the Linus Rule of not break userspace.   So this is why the patch is
> strictly no as this means elevating privilege of existing applications
> and possibly opening up more security flaws.

This feature is not required so it is not "making CAP_SYS_ADMIN the
only way to use TIOCSTI". It defaults to no as to not break some
existing programs that use it.

>
> Reality any patch like the one we are talking about due to the Linus
> Rule and the security risk it will open up obey this it just be
> rejected.   There is another kind of way I will cover with Serge.
>
> Peter Dolding.
>

Matt

[toc] | [prev] | [next] | [standalone]


#1643511

FromAlan Cox <gnomes@lxorguk.ukuu.org.uk>
Date2017-05-17 18:50 +0200
Message-ID<tIaj8-5vV-19@gated-at.bofh.it>
In reply to#1642580
> If we're adjusting applications, they should be made to avoid TIOSCTI
> completely. This looks to me a lot like the symlink restrictions: yes,
> userspace should be fixed to the do the right thing, but why not
> provide support to userspace to avoid the problem entirely?

We do it's called pty/tty. There isn't any other way to do this correctly
because TIOCSTI is just one hundreds of things the attacker can do to
make your life miserable in the case you create a child process of lower
security privilege and give it your tty file handle or worse (like some
container crapware) your X11 socket fd.

Does it really matter any more or less if I reprogram your enter key, use
TIOCSTI, set the baud rate, change all your fonts ?

The mainstream tools like sudo get this right (*). Blocking TIOCSTI fixes
nothing and breaks apps. If it magically fixed the problem it might make
sense but it doesn't. You actually have to get an adult to write the
relevant code.

Alan
(*) Almost. There's an old world trick of sending "+++" "ATE1" "rm -rf
*\r\n" to try and attack improperly configured remote modem sessions but
the stuff that matters is handled.

[toc] | [prev] | [next] | [standalone]


#1643571 — Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

FromDaniel Micay <danielmicay@gmail.com>
Date2017-05-17 20:30 +0200
SubjectRe: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tIbRU-6Bk-1@gated-at.bofh.it>
In reply to#1643511
On Wed, 2017-05-17 at 17:41 +0100, Alan Cox wrote:
> > If we're adjusting applications, they should be made to avoid
> > TIOSCTI
> > completely. This looks to me a lot like the symlink restrictions:
> > yes,
> > userspace should be fixed to the do the right thing, but why not
> > provide support to userspace to avoid the problem entirely?
> 
> We do it's called pty/tty. There isn't any other way to do this
> correctly
> because TIOCSTI is just one hundreds of things the attacker can do to
> make your life miserable in the case you create a child process of
> lower
> security privilege and give it your tty file handle or worse (like
> some
> container crapware) your X11 socket fd.
> 
> Does it really matter any more or less if I reprogram your enter key,
> use
> TIOCSTI, set the baud rate, change all your fonts ?
> 
> The mainstream tools like sudo get this right (*). Blocking TIOCSTI
> fixes
> nothing and breaks apps. If it magically fixed the problem it might
> make
> sense but it doesn't. You actually have to get an adult to write the
> relevant code.

It gets it right because it was reported as a vulnerability and fixed,
which is the cycle many of these tools have gone through. It looks like
sudo and coreutils / shadow su were fixed in 2005, but there are more of
these tools.

CVE-2005-4890 (coreutils su, shadow su, sudo), CVE-2016-7545 (SELinux
sandbox utility), CVE-2016-2781 (chroot --userspec), CVE-2016-2779
(util-linux runuser), CVE-2016-2568 (pkexec)

I am not sure if the pkexec vulnerability is even fixed:

https://bugzilla.redhat.com/show_bug.cgi?id=1300746

CVE-2017-5226 is for bubblewrap/flatpak this year, and I'm sure there
were a lot more as I didn't bother to dig very deep.

I completely agree that it should be solved by doing things properly in
each application. However, it isn't solved properly everywhere and each
new application is making the same mistake. Providing this feature does
not break anything that people use in practice and it doesn't need to
solve every issue to be quite useful, it only needs to prevent local
privilege escalation in the form of code execution in many cases. Is
there another way to get code execution via that bubblewrap/flatpak bug
with this feature implemented? As far as I can tell, there isn't. It's a
problem even with this feature but a significantly less serious one.

[toc] | [prev] | [next] | [standalone]


#1643759 — Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

FromKees Cook <keescook@chromium.org>
Date2017-05-18 05:20 +0200
SubjectRe: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tIk8O-3UF-5@gated-at.bofh.it>
In reply to#1643571
On Wed, May 17, 2017 at 11:25 AM, Daniel Micay <danielmicay@gmail.com> wrote:
> On Wed, 2017-05-17 at 17:41 +0100, Alan Cox wrote:
>> > If we're adjusting applications, they should be made to avoid
>> > TIOSCTI
>> > completely. This looks to me a lot like the symlink restrictions:
>> > yes,
>> > userspace should be fixed to the do the right thing, but why not
>> > provide support to userspace to avoid the problem entirely?
>>
>> We do it's called pty/tty. There isn't any other way to do this
>> correctly
>> because TIOCSTI is just one hundreds of things the attacker can do to
>> make your life miserable in the case you create a child process of
>> lower
>> security privilege and give it your tty file handle or worse (like
>> some
>> container crapware) your X11 socket fd.
>>
>> Does it really matter any more or less if I reprogram your enter key,
>> use
>> TIOCSTI, set the baud rate, change all your fonts ?
>>
>> The mainstream tools like sudo get this right (*). Blocking TIOCSTI
>> fixes
>> nothing and breaks apps. If it magically fixed the problem it might
>> make
>> sense but it doesn't. You actually have to get an adult to write the
>> relevant code.
>
> It gets it right because it was reported as a vulnerability and fixed,
> which is the cycle many of these tools have gone through. It looks like
> sudo and coreutils / shadow su were fixed in 2005, but there are more of
> these tools.
>
> CVE-2005-4890 (coreutils su, shadow su, sudo), CVE-2016-7545 (SELinux
> sandbox utility), CVE-2016-2781 (chroot --userspec), CVE-2016-2779
> (util-linux runuser), CVE-2016-2568 (pkexec)
>
> I am not sure if the pkexec vulnerability is even fixed:
>
> https://bugzilla.redhat.com/show_bug.cgi?id=1300746
>
> CVE-2017-5226 is for bubblewrap/flatpak this year, and I'm sure there
> were a lot more as I didn't bother to dig very deep.
>
> I completely agree that it should be solved by doing things properly in
> each application. However, it isn't solved properly everywhere and each
> new application is making the same mistake. Providing this feature does
> not break anything that people use in practice and it doesn't need to
> solve every issue to be quite useful, it only needs to prevent local
> privilege escalation in the form of code execution in many cases. Is
> there another way to get code execution via that bubblewrap/flatpak bug
> with this feature implemented? As far as I can tell, there isn't. It's a
> problem even with this feature but a significantly less serious one.

This patch solves a real problem when userspace does things wrong. For
those that do not want it, a sysctl exists (and is even default off).
Arguments about how userspace needs to be fixed is a total red
herring. Like symlink protections before, this should be available for
those that want it because it solves an interface problem that gets
regularly misused and causes real damage. The kernel has a
responsibility to protect userspace.

As Daniel mentions, there is a history of mistakes that appear to be
becoming even more common:
http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=TIOCSTI

There are people who want this feature that do not care about xemacs
breaking. The default cannot be enabled because of the golden rule of
never breaking userspace, but entirely refusing to fix a regularly
misused feature is wrong-headed. We must accept that not only are bug
lifetimes long, but that bugs will keep getting reintroduced. When
there is a chance to kill a class of bugs or exploit techniques, it's
the kernel responsibility to do so. This is a clear case of that, and
the solution is concise.

If there is some better solution that the kernel can provide to
mitigate processes misusing ttys, then by all means, we can add that
too, but has nothing to do with refusing this change. This solves a
specific problem that in many cases is the only path to privilege
escalation (as Daniel mentioned). Refusing this change is nonsense.
"Your car shouldn't have seat belts because maybe something will stab
you through the windshield" isn't a reasonable argument to make.

-Kees

-- 
Kees Cook
Pixel Security

[toc] | [prev] | [next] | [standalone]


#1645142 — Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

FromPeter Dolding <oiaohm@gmail.com>
Date2017-05-19 04:50 +0200
SubjectRe: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tIG9k-3ZH-9@gated-at.bofh.it>
In reply to#1643759
On Thu, May 18, 2017 at 1:18 PM, Kees Cook <keescook@chromium.org> wrote:
> On Wed, May 17, 2017 at 11:25 AM, Daniel Micay <danielmicay@gmail.com> wrote:
>> On Wed, 2017-05-17 at 17:41 +0100, Alan Cox wrote:
>>> > If we're adjusting applications, they should be made to avoid
>>> > TIOSCTI
>>> > completely. This looks to me a lot like the symlink restrictions:
>>> > yes,
>>> > userspace should be fixed to the do the right thing, but why not
>>> > provide support to userspace to avoid the problem entirely?
>>>
>>> We do it's called pty/tty. There isn't any other way to do this
>>> correctly
>>> because TIOCSTI is just one hundreds of things the attacker can do to
>>> make your life miserable in the case you create a child process of
>>> lower
>>> security privilege and give it your tty file handle or worse (like
>>> some
>>> container crapware) your X11 socket fd.
>>>
>>> Does it really matter any more or less if I reprogram your enter key,
>>> use
>>> TIOCSTI, set the baud rate, change all your fonts ?
>>>
>>> The mainstream tools like sudo get this right (*). Blocking TIOCSTI
>>> fixes
>>> nothing and breaks apps. If it magically fixed the problem it might
>>> make
>>> sense but it doesn't. You actually have to get an adult to write the
>>> relevant code.
>>
>> It gets it right because it was reported as a vulnerability and fixed,
>> which is the cycle many of these tools have gone through. It looks like
>> sudo and coreutils / shadow su were fixed in 2005, but there are more of
>> these tools.
>>
>> CVE-2005-4890 (coreutils su, shadow su, sudo), CVE-2016-7545 (SELinux
>> sandbox utility), CVE-2016-2781 (chroot --userspec), CVE-2016-2779
>> (util-linux runuser), CVE-2016-2568 (pkexec)
>>
>> I am not sure if the pkexec vulnerability is even fixed:
>>
>> https://bugzilla.redhat.com/show_bug.cgi?id=1300746
>>
>> CVE-2017-5226 is for bubblewrap/flatpak this year, and I'm sure there
>> were a lot more as I didn't bother to dig very deep.
>>
>> I completely agree that it should be solved by doing things properly in
>> each application. However, it isn't solved properly everywhere and each
>> new application is making the same mistake. Providing this feature does
>> not break anything that people use in practice and it doesn't need to
>> solve every issue to be quite useful, it only needs to prevent local
>> privilege escalation in the form of code execution in many cases. Is
>> there another way to get code execution via that bubblewrap/flatpak bug
>> with this feature implemented? As far as I can tell, there isn't. It's a
>> problem even with this feature but a significantly less serious one.
>
> This patch solves a real problem when userspace does things wrong. For
> those that do not want it, a sysctl exists (and is even default off).
> Arguments about how userspace needs to be fixed is a total red
> herring. Like symlink protections before, this should be available for
> those that want it because it solves an interface problem that gets
> regularly misused and causes real damage. The kernel has a
> responsibility to protect userspace.
>
> As Daniel mentions, there is a history of mistakes that appear to be
> becoming even more common:
> http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=TIOCSTI
>
> There are people who want this feature that do not care about xemacs
> breaking. The default cannot be enabled because of the golden rule of
> never breaking userspace, but entirely refusing to fix a regularly
> misused feature is wrong-headed. We must accept that not only are bug
> lifetimes long, but that bugs will keep getting reintroduced. When
> there is a chance to kill a class of bugs or exploit techniques, it's
> the kernel responsibility to do so. This is a clear case of that, and
> the solution is concise.

True but what is usage of TIOCSTI that is wrong in these CVE.   Is it
not when the returned input values values to tty crosses process
boundaries.  Like if when process terminated everything the process
had pushed back to TTY and Input it has received was lost those CVE
would not be possible.

Could those exist CVE when exploit happens have CAP_SYS_ADMIN as the
process being used to break out the answer is yes.   So restricting
TIOCSTI to CAP_SYS_ADMIN could be pointless.   Remember you have suid
bit applications one of those might have  bug that someone is able to
exploit to use the TIOCSTI.   So pushing to CAP_SYS_ADMIN make exploit
rarer does not remove it.

Please note you see TIOCSTI using in libc when they implement
ungetc().   So this is something that is quite well used.   I see
ungetc as kind of a bad idea to be implemented kernel level going to
tty shareable between processes.

> If there is some better solution that the kernel can provide to
> mitigate processes misusing ttys, then by all means, we can add that
> too, but has nothing to do with refusing this change. This solves a
> specific problem that in many cases is the only path to privilege
> escalation (as Daniel mentioned). Refusing this change is nonsense.
> "Your car shouldn't have seat belts because maybe something will stab
> you through the windshield" isn't a reasonable argument to make.

Using cap_sys_admin as fix is like removing car windsheld because
vision is being blocked by a rock hitting it.

Kees the problem with accepting a security fix that is wrong the
proper change never gets worked on.

I am not saying there is not a real problem here.   The fix is not
push it to CAP_SYS_ADMIN.   Due to TIOCSTI that cross process and tty
boundaries been used in security breaks and limit applications that
uses use as either Administrator or as normal User means this ability
does not own in CAP_SYS_ADMIN either.

The same is true of obsolete function calls that have been shoved into
CAP_SYS_ADMIN already there comes point where no valid userspace
application is using that function.   At that point the only thing
using that function is exploits so then really CAP_SYS_ADMIN should
not have access to those obsolete functions.   There is a real need
for CAP_SYS_OBSOLETE.   If a program has to ahve CAP_SYS_OBSOLETE set
on it this means it using functionally that is known busted in some
way..

This is the biggest problem here.   There is no real agreement how we
exterminate/restrict flawed functions to progressive reduce the number
of applications and users who can access the flawed functions to allow
them to be fully disabled for 99.99 percent of people using systems.

That is what people are not getting CAP_SYS_ADMIN has too many users
to be counted and mitigation as well.

Yes we must not break userspace but we also must mitigate against
userspace issues.   We do need a clear rules on how to fix these
security problem user-space is allowed to be broken and of course made
part of the Linux kernel documentation.   Altering the binary is for
sure out because the person operating the system may not have that
right.   Placing a flag on a binary so it works I would see as
acceptable as long as that flag was not grant a stack of other
privileges that application would have never had before..

Peter Dolding

[toc] | [prev] | [next] | [standalone]


#1645648 — Re: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN

From"Serge E. Hallyn" <serge@hallyn.com>
Date2017-05-19 16:40 +0200
SubjectRe: [kernel-hardening] Re: [PATCH v6 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Message-ID<tIRep-3xO-1@gated-at.bofh.it>
In reply to#1645142
On Fri, May 19, 2017 at 12:48:17PM +1000, Peter Dolding wrote:
> Using cap_sys_admin as fix is like removing car windsheld because
> vision is being blocked by a rock hitting it.

Nonsense.  If the application has cap_sys_admin then it is less contained and
more trusted anyway.  If I went to the trouble to run an application in a
private user namespace (where it can have cap_sys_admin, but not targeted
at my tty) then it should be more contained.  That's the point of targeted
capabilities.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web