From: David Laight <David.Laight@ACULAB.COM>
To: "'Solar Designer'" <solar@openwall.com>
Cc: "'Salvatore Mesoraca'" <s.mesoraca16@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Kernel Hardening" <kernel-hardening@lists.openwall.com>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
Jann Horn <jannh@google.com>, Kees Cook <keescook@chromium.org>,
"Eric W. Biederman" <ebiederm@xmission.com>
Subject: RE: [PATCH v3 2/2] Protected O_CREAT open in sticky directories
Date: Fri, 1 Dec 2017 09:46:28 +0000 [thread overview]
Message-ID: <c5d9dd814f14467a8b756ebd27a07a75@AcuMS.aculab.com> (raw)
In-Reply-To: <20171130175147.GA4124@openwall.com>
From: Solar Designer
> Sent: 30 November 2017 17:52
>
> On Thu, Nov 30, 2017 at 04:53:06PM +0000, David Laight wrote:
> > From: Salvatore Mesoraca
> > > if a program tries to open a file, in a sticky directory,
> > > with the O_CREAT flag and without the O_EXCL, it probably has a bug.
> > > This feature allows to detect and potentially block programs that
> > > act this way, it can be used to find vulnerabilities (like those
> > > prevented by patch #1) and to do policy enforcement.
>
> > I presume the 'vulnerabilities' are related to symlinks being created
> > just before the open?
>
> That's one way to exploit them. We already have a sysctl to try and
> block that specific attack, and we're considering adding more, for other
> attacks. But we'd also like an easy way to learn of the vulnerabilities
> without anyone trying to exploit them yet, hence this patch.
>
> > Trouble is this change breaks a lot of general use of /tmp.
>
> That's general misuse of /tmp. Things like "command > /tmp/file"
> without having pre-created the file with O_EXCL e.g. by mktemp(1).
I'm sorry, I've been using Unix for over 30 years.
/tmp is a place that temporary files were created - nothing special.
Traditionally it was emptied on every boot.
There was never anything that required files be created in any
specific way.
> > I always assumed that code that cared would use O_EXCL and
> > everything else wasn't worth subverting.
>
> Opinions will vary on whether it's worth subverting or not, and someone
> may reasonably want to configure this differently on different systems.
>
> > I found code in vi (and elsewhere) that subverted these checks
> > by opening with O_WRONLY if stat() showed the file existed and
> > O_CREAT|O_EXCL if it didn't.
>
> Yes, such misuses of /tmp and the like by use of those programs - where
> the potential consequences would often be less severe (if your example
> above is correct, it sounds like it'd be data spoofing but not
> overwriting another file over a link) - could remain unnoticed.
It seemed to me that code had been added to avoid issues caused by
this policing of opens.
But the code added is itself racy - so makes the whole thing pointless.
> > I'm pretty sure that traditionally a lot of these opens were done
> > with O_CREAT|O_TRUNC.
> > Implementing that as unlink() followed by a create would stop
> > 'random' (ok all) symlinks being followed.
>
> That's racy. We have O_EXCL, and it must be used along with O_CREAT
> when the directory is untrusted. (If it were only about symlinks, we
> also already have O_NOFOLLOW.)
Not racy if done in the kernel itself.
> > Overall I'm pretty sure this change will break things badly somewhere.
>
> Sure. We want it to visibly break what was subtly broken, so that the
> breakage can be seen and corrected without an attempted attack.
Maybe, but it will break some user system when they do a kernel update.
It won't necessarily break a developer's system first.
And, AFAICT, there is already code that subverts any tests by doing
a check for the file existing and then selecting between two different
types on open.
David
next prev parent reply other threads:[~2017-12-01 9:46 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-22 8:01 [PATCH v3 0/2] Restrict dangerous " Salvatore Mesoraca
2017-11-22 8:01 ` [PATCH v3 1/2] Protected FIFOs and regular files Salvatore Mesoraca
2017-11-23 22:43 ` [kernel-hardening] " Tobin C. Harding
2017-11-24 8:24 ` Salvatore Mesoraca
2017-11-22 8:01 ` [PATCH v3 2/2] Protected O_CREAT open in sticky directories Salvatore Mesoraca
2017-11-22 13:22 ` Matthew Wilcox
2017-11-24 8:29 ` Salvatore Mesoraca
2017-11-22 16:51 ` Alan Cox
2017-11-24 8:31 ` Salvatore Mesoraca
2017-11-24 10:53 ` David Laight
2017-11-24 11:43 ` Salvatore Mesoraca
2017-11-24 11:53 ` David Laight
2017-11-26 11:29 ` Salvatore Mesoraca
2017-11-27 0:26 ` Solar Designer
2017-11-30 14:39 ` Salvatore Mesoraca
2017-11-30 14:57 ` [kernel-hardening] " Ian Campbell
2017-11-30 16:30 ` [kernel-hardening] " Solar Designer
2017-12-05 10:21 ` Salvatore Mesoraca
2017-12-07 21:47 ` Solar Designer
2017-12-11 12:08 ` Salvatore Mesoraca
2017-11-23 22:57 ` Tobin C. Harding
2017-11-24 8:34 ` Salvatore Mesoraca
2017-11-30 16:53 ` David Laight
2017-11-30 17:51 ` Solar Designer
2017-12-01 9:46 ` David Laight [this message]
2017-12-01 15:52 ` Alan Cox
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=c5d9dd814f14467a8b756ebd27a07a75@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=ebiederm@xmission.com \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=s.mesoraca16@gmail.com \
--cc=solar@openwall.com \
--cc=viro@zeniv.linux.org.uk \
/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
Powered by JetHome