linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serge@hallyn.com>
To: Matt Brown <matt@nmatt.com>
Cc: Alan Cox <gnomes@lxorguk.ukuu.org.uk>,
	Kees Cook <keescook@chromium.org>,
	Casey Schaufler <casey@schaufler-ca.com>,
	Boris Lukashev <blukashev@sempervictus.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"kernel-hardening@lists.openwall.com" 
	<kernel-hardening@lists.openwall.com>,
	linux-security-module <linux-security-module@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [kernel-hardening] Re: [PATCH v7 2/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN
Date: Fri, 2 Jun 2017 10:36:47 -0500	[thread overview]
Message-ID: <20170602153647.GA2688@mail.hallyn.com> (raw)
In-Reply-To: <2d0ad49c-886e-1caf-771a-d251957f614c@nmatt.com>

Quoting Matt Brown (matt@nmatt.com):
> On 6/1/17 5:24 PM, Alan Cox wrote:
> >> There's a difference between "bugs" and "security bugs". Letting
> > 
> > Not really, it's merely a matter of severity of result. A non security
> > bug that hoses your hard disk is to anyone but security nutcases at
> > least as bad as a security hole.
> > 
> >> security bugs continue to get exploited because we want to flush out
> >> bugs seems insensitive to the people getting attacked. I'd rather
> >> protect against a class of bug than have to endless fix each bug.
> > 
> > The others are security bugs too to varying degree
> > 
> >>> I'm not against doing something to protect the container folks, but that
> >>> something as with Android is a whitelist of ioctls. And if we need to do
> >>> this with a kernel hook lets do it properly.
> >>>
> >>> Remember the namespace of the tty on creation
> >>> If the magic security flag is set then
> >>>         Apply a whitelist to *any* tty ioctl call where the ns doesn't
> >>>                 match
> >>>
> >>> and we might as well just take the Android whitelist since they've kindly
> >>> built it for us all!
> >>>
> >>> In the tty layer it ends up being something around 10 lines of code and
> >>> some other file somewhere in security/ that's just a switch or similar
> >>> with the whitelisted ioctl codes in it.
> >>>
> >>> That (or a similar SELinux ruleset) would actually fix the problem.
> >>> SELinux would be better because it can also apply the rules when doing
> >>> things like su/sudo/...  
> >>
> >> Just to play devil's advocate, wouldn't such a system continue to not
> >> address your physical-console concerns? I wouldn't want to limit the
> > 
> > It would for the cases that a whitelist and container check covers -
> > because the whitelist wouldn't allow you to do anything but boring stuff
> > on the tty. TIOCSTI is just one of a whole range of differently stupid
> > and annoying opportunities. Containers do not and should not be able to
> > set the keymap, change the video mode, use console selection, make funny
> > beepy noises, access video I/O registers and all the other stuff like
> > that. Nothing is going to break if we have a fairly conservative
> > whitelist.
> > 
> >> protection to only containers (but it's a good start), since it
> >> wouldn't protect people not using containers that still have a
> >> privileged TTY attached badly somewhere.
> > 
> > How are you going to magically fix the problem. I'm not opposed to fixing
> > the real problem but right now it appears to be a product of wishful
> > thinking not programming. What's the piece of security code that
> > magically discerns the fact you are running something untrusted at the
> > other end of your tty. SELinux can do it via labelling but I don't see
> > any generic automatic way for the kernel to magically work out when to
> > whitelist and when not to. If there is a better magic rule than
> > differing-namespace then provide the code.
> > 
> > You can't just disable TIOCSTI, it has users deal with it. You can
> > get away with disabling it for namespace crossing I think but if you do
> > that you need to disable a pile of others.
> > 
> > (If it breaks containers blocking TIOCSTI then we need to have a good
> > look at algorithms for deciding when to flush the input queue on exiting
> > a container or somesuch)
> > 
> >> If you're talking about wholistic SELinux policy, sure, I could
> >> imagine a wholistic fix. But for the tons of people without a
> >> comprehensive SELinux policy, the proposed protection continues to
> >> make sense.
> > 
> > No it doesn't. It's completely useless unless you actually bother to
> > address the other exploit opportunities.
> > 
> > Right now the proposal is a hack to do 
> > 
> > 	if (TIOCSTI && different_namespace && magic_flag)
> > 
> 
> 
> This is not what my patch does. Mine is like:
> 
> 	if (TIOCSTI && !ns_capable(tty->owner_user_ns, CAP_SYS_ADMIN) &&
> 		magic_flag)
> 
> in other words:
> 	if (TIOCSTI && (different_owner_user_ns || !CAP_SYS_ADMIN) &&
> 		magic_flag)
> 
> can you specify what you mean by different_namespace? which namespace?

I think you're focusing on the wrong thing.  Your capable check (apart
from the fact that I think I've been convinced CAP_SYS_ADMIN is wrong)
is fine.

The key point is to not only check for TIOCSTI, but instead check for
a whitelisted ioctl.

What would the whitelist look like?  Should configuing that be the way
that you enable/disable, instead of the sysctl in this patchset?  So
by default the whitelist includes all ioctls (no change), but things
like sandboxes/sudo/container-starts can clear out the whitelist?

  reply	other threads:[~2017-06-02 15:36 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-29 21:37 [PATCH v7 0/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN Matt Brown
2017-05-29 21:37 ` [PATCH v7 1/2] security: tty: Add owner user namespace to tty_struct Matt Brown
2017-05-29 21:38 ` [PATCH v7 2/2] security: tty: make TIOCSTI ioctl require CAP_SYS_ADMIN Matt Brown
2017-05-29 22:26   ` Alan Cox
2017-05-29 23:51     ` [kernel-hardening] " Boris Lukashev
2017-05-30  0:27       ` Casey Schaufler
2017-05-30  2:00         ` Matt Brown
2017-05-30  2:46           ` Casey Schaufler
2017-05-30  3:18             ` Matt Brown
2017-05-30 12:24               ` Alan Cox
2017-05-30 16:28                 ` Matt Brown
2017-05-30 16:44                   ` Daniel Micay
2017-05-30 18:32                   ` Stephen Smalley
2017-05-30 18:44                     ` Nick Kralevich
2017-05-30 18:57                       ` Matt Brown
2017-05-30 20:22                         ` Daniel Micay
2017-05-30 23:00                           ` Matt Brown
2017-05-30 23:40                             ` Daniel Micay
2017-05-30 23:59                               ` Matt Brown
2017-05-30 22:51                   ` Alan Cox
2017-05-30 23:19                     ` Matt Brown
2017-05-30 23:56                       ` Alan Cox
2017-06-01  2:35                         ` Kees Cook
2017-06-01 13:08                           ` Alan Cox
2017-06-01 17:18                             ` Serge E. Hallyn
2017-06-01 21:26                               ` Alan Cox
2017-06-01 18:58                             ` Kees Cook
2017-06-01 21:24                               ` Alan Cox
2017-06-02 14:46                                 ` Matt Brown
2017-06-02 15:36                                   ` Serge E. Hallyn [this message]
2017-06-02 16:02                                     ` Matt Brown
2017-06-02 16:57                                       ` Serge E. Hallyn
2017-06-02 17:32                                         ` Matt Brown
2017-06-02 18:18                                           ` Serge E. Hallyn
2017-06-02 19:22                                             ` Matt Brown
2017-06-02 19:25                                               ` Kees Cook
2017-06-02 19:26                                                 ` Matt Brown
2017-06-02 20:05                                       ` Alan Cox
2017-06-02 20:11                                         ` Nick Kralevich
2017-06-02 20:46                                         ` Matt Brown
2017-06-03 22:00                                           ` Alan Cox
2017-06-03 22:22                                             ` Matt Brown
2017-06-04  3:37                                               ` Peter Dolding
2017-05-30 15:20               ` Casey Schaufler
2017-05-30 16:09                 ` Matt Brown
2017-06-04  6:29         ` Boris Lukashev
2017-05-31  2:48       ` James Morris
2017-05-31  4:10         ` Matt Brown
2017-05-30  0:15     ` Matt Brown

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=20170602153647.GA2688@mail.hallyn.com \
    --to=serge@hallyn.com \
    --cc=blukashev@sempervictus.com \
    --cc=casey@schaufler-ca.com \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=matt@nmatt.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;
as well as URLs for NNTP newsgroup(s).