Received: by 10.223.164.202 with SMTP id h10csp260563wrb; Thu, 30 Nov 2017 09:54:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMbCM8GQ5avf0hEEpvzxo0Uesx8Mc81MDITNYwFlOjAFj89Sa3ehckz2S/d5bdRwlO+qyTNd X-Received: by 10.159.197.5 with SMTP id bj5mr3457779plb.219.1512064458063; Thu, 30 Nov 2017 09:54:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512064458; cv=none; d=google.com; s=arc-20160816; b=08aEN36n5fJ28r5zuBUDbDMVwMqWLvZ0MwbIH1VVcFkHrLiwA2rIIEyKnjTymWTmFt rkK9ZrXG8QSUlXUMqn753iWB6VJukNb1eLSz2iAEFflTzzm0BXdVLyFGd8sHWWbir3h6 zM/Jqlzo+B+Ei3XBdrII7des+uoFhACG7a7T+zdWrDyw6+zHzmCRQDw0F9SQ5NkHNTAS 5XA3JpjojQVASOxaaw2Jr8D95mvNjpVZi21/BoOxp939qLA2n6lCZ5hp8dm1U89D7Hq+ SHeZrgfGRPRz1Bm1H4Ukd6DXZ8uw8bs9zIAk3ZsUdoDKy1rhiNENFuVL6RoI/g9KPxQP sUOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=fy+q3+B+K/zW0lnE3CiEyQBkN5HAy7+Ar8AwQcICPsI=; b=gQpdEdt8EX8TDvrqXOITAPTRjOkE7AIlCI8S2XhqBXBrx094KyCLhz97tg4Xdxrt/o 64/e8Gwzy+6+n4E3Sd4UZrlitdWaZ+VzKYgqAHhDdNb50b7u4+9j/VKu+AZwD8IKaM4M 6d9CGgbzr//uA91STE4Yk7VE8byvBYWV290wjPQHbW4TVZ2Ql/sN/bCfw+LIa92/g/aE jsO9B8M336R+MYfbWLXUCh7+TUxvbccs5nIAgXRa3W3yLG2lCznjROLAdHVCRs+EvnIu MVmFJEEZJ2vOSo5U34SpNGhqGpr1+p+C+/kwZcf5WP9FFiCzcuuEYHQ3g4f9U/PEipds HIww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r10si3559659pli.600.2017.11.30.09.54.03; Thu, 30 Nov 2017 09:54:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753916AbdK3Rv4 (ORCPT + 99 others); Thu, 30 Nov 2017 12:51:56 -0500 Received: from mother.openwall.net ([195.42.179.200]:64777 "HELO mother.openwall.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753813AbdK3Rvy (ORCPT ); Thu, 30 Nov 2017 12:51:54 -0500 Received: (qmail 3729 invoked from network); 30 Nov 2017 17:51:52 -0000 Received: from localhost (HELO pvt.openwall.com) (127.0.0.1) by localhost with SMTP; 30 Nov 2017 17:51:52 -0000 Received: by pvt.openwall.com (Postfix, from userid 503) id D9947AD423; Thu, 30 Nov 2017 18:51:47 +0100 (CET) Date: Thu, 30 Nov 2017 18:51:47 +0100 From: Solar Designer To: David Laight Cc: 'Salvatore Mesoraca' , "linux-kernel@vger.kernel.org" , Kernel Hardening , "linux-fsdevel@vger.kernel.org" , Alexander Viro , Jann Horn , Kees Cook , "Eric W. Biederman" Subject: Re: [PATCH v3 2/2] Protected O_CREAT open in sticky directories Message-ID: <20171130175147.GA4124@openwall.com> References: <1511337706-8297-1-git-send-email-s.mesoraca16@gmail.com> <1511337706-8297-3-git-send-email-s.mesoraca16@gmail.com> <9fe9b2cd312748ddb31f63f9dc1b1ed8@AcuMS.aculab.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9fe9b2cd312748ddb31f63f9dc1b1ed8@AcuMS.aculab.com> User-Agent: Mutt/1.4.2.3i Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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. > 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.) > 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. Alexander From 1585510700273466241@xxx Thu Nov 30 16:53:53 +0000 2017 X-GM-THRID: 1584752529750903902 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread