Received: by 10.223.185.116 with SMTP id b49csp5311113wrg; Wed, 7 Mar 2018 09:37:01 -0800 (PST) X-Google-Smtp-Source: AG47ELtNKkAqX57e1T/JOYqlRm+WABfXTBONEEdE8zwSGllNaqCa3cJFUqs5mUSPfWVZvgkfbkKM X-Received: by 10.98.252.22 with SMTP id e22mr23429533pfh.235.1520444221507; Wed, 07 Mar 2018 09:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520444221; cv=none; d=google.com; s=arc-20160816; b=hW6knrBIGukjZFvQiTH2a9VnmS35Ygqt+kdUoryQNktagFnT9HmfrjaQyPXHEBAIn3 oscGz9Ir2YUVcMmyioq737FG6Of7SKJ5NUa6SIzW4lCBQX+QUxD5D3+t45ABjQ9xV/4r T99KPv5WLiUKcF0gcxVPBV8Kp85gtRWTwY1rrRSWvG8Gg8X2lg2sn/EgF4KIesG6yAs3 tC+Jgx2EI97KmlYyoF/i/YKWbZwVk5B1odnsksq39JXAVr3x6wIghYtvXTONlOt/iDqB 0FaJD10SHo3RwzGaltkkbFD06v9Opx1CHoj2LRzFIork9bw0YYfYM1BDP7k0H4UtUIYW CPpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=OAkheI+JT0YbBBoBHWXAb4bFZTSEY0Zc7fx0S+IXtU4=; b=Rphy7XqZTPlTgNuDXKUPuI32uqy/+ExEO70IjUYimFqGPoygsgxL75vTGMaU23SO4D KOHdaeF992GkSqMOu9Ti7/zF+HDlWm1bxsUR5QEf7MHkMMFqvzjJhkYhHf6ZHjPNVmka oPyrdNXEGgK10OHItUPl5d2l9xo3aXJcITyCgDot7s6sLNxC4DBZ4hbKLeUUqxBcBdNK Pb3Ba90Hr8TIk50cQ2dx7ki5Yx2htolpMSC3GuJRw/sodfCbEOY7CV1QfsaGwbeqp9UX 44AG5fWFgajcTZx7F+PWxUp0SnTRfW3aPkDJ1qEsjx01ZnyWIHYinns2fjiAKot56Mf4 ffyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=hYQ2KQYC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1si11732239pgs.208.2018.03.07.09.36.47; Wed, 07 Mar 2018 09:37:01 -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; dkim=pass header.i=@cisco.com header.s=iport header.b=hYQ2KQYC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933768AbeCGRfj (ORCPT + 99 others); Wed, 7 Mar 2018 12:35:39 -0500 Received: from alln-iport-3.cisco.com ([173.37.142.90]:28245 "EHLO alln-iport-3.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933642AbeCGRfe (ORCPT ); Wed, 7 Mar 2018 12:35:34 -0500 X-Greylist: delayed 572 seconds by postgrey-1.27 at vger.kernel.org; Wed, 07 Mar 2018 12:35:34 EST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=4890; q=dns/txt; s=iport; t=1520444134; x=1521653734; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=1gA1q0bMaQG0531TrembWx2x3+ooj6uwmfN0gBtlXQc=; b=hYQ2KQYCrjiD8cZihfqJdT1iJHUpkl8rxZs/2ldV9zRRi9eDZXbjkRO/ /rGbflHYTz6OAyCLp9tIv9dcRjR/hP3UvFdO21Kqj/ClJiP2e+88S9feC gteTctbLaPNOIPlr17qK8HaF6aMaow8cY7HnZeLPQzRjv3Yx8oWDWRyVr Y=; X-IronPort-AV: E=Sophos;i="5.47,436,1515456000"; d="scan'208";a="80800534" Received: from alln-core-12.cisco.com ([173.36.13.134]) by alln-iport-3.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Mar 2018 17:26:02 +0000 Received: from sjc-ads-6991 (sjc-ads-6991.cisco.com [10.30.218.111]) by alln-core-12.cisco.com (8.14.5/8.14.5) with ESMTP id w27HQ10R022639 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 7 Mar 2018 17:26:01 GMT Date: Wed, 7 Mar 2018 09:26:00 -0800 (PST) From: Victor Kamensky To: Rob Landley cc: Stephen Smalley , Taras Kondratiuk , "H. Peter Anvin" , Al Viro , Arnd Bergmann , Mimi Zohar , Jonathan Corbet , James McMechan , initramfs@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, xe-linux-external@cisco.com, Paul Moore , Eric Paris Subject: Re: [PATCH v3 15/15] selinux: delay sid population for rootfs till init is complete In-Reply-To: Message-ID: References: <1518813234-5874-1-git-send-email-takondra@cisco.com> <1518813234-5874-19-git-send-email-takondra@cisco.com> <1519152994.14218.15.camel@tycho.nsa.gov> User-Agent: Alpine 2.00 (LRH 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Auto-Response-Suppress: DR, OOF, AutoReply Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 7 Mar 2018, Rob Landley wrote: > On 02/20/2018 12:56 PM, Stephen Smalley wrote: >> On Fri, 2018-02-16 at 20:33 +0000, Taras Kondratiuk wrote: >>> From: Victor Kamensky >>> >>> With initramfs cpio format that supports extended attributes >>> we need to skip sid population on sys_lsetxattr call from >>> initramfs for rootfs if security server is not initialized yet. >>> >>> Otherwise callback in selinux_inode_post_setxattr will try to >>> translate give security.selinux label into sid context and since >>> security server is not available yet inode will receive default >>> sid (typically kernel_t). Note that in the same time proper >>> label will be stored in inode xattrs. Later, since inode sid >>> would be already populated system will never look back at >>> actual xattrs. But if we skip sid population for rootfs and >>> we have policy that direct use of xattrs for rootfs, proper >>> sid will be filled in from extended attributes one node is >>> accessed and server is initialized. >>> >>> Note new DELAYAFTERINIT_MNT super block flag is introduced >>> to only mark rootfs for such behavior. For other types of >>> tmpfs original logic is still used. >> >> (cc selinux maintainers) >> >> Wondering if we shouldn't just do this always, for all filesystem >> types. Also, I think this should likely also be done in >> selinux_inode_setsecurity() for consistency. Sorry, I did not have time to try out Stephen's suggestion, especially given that core initramfs xattrs acceptance and dicussion looks a bit stalled, and for my use case it is dependency before SELinux changes. I will look for both suggestion this week. Hope to see initramfs xattrs patch series review going again. > I don't understand what selinux thinks it's doing here. > > Initramfs is special because it's populated early, ideally early enough drivers > can load their firmware out of it. This is guaranteed to be before any processes > have launched, before any other filesystems have been mounted. I'm surprised > selinux is trying to do anything this early because A) what is there for it to > do, B) where did it get a ruleset? > > This isn't really a mount flag, this is a "the selinux subsystem isn't > functionally initialized yet" flag. We haven't launched init. In a modular > system the module probably isn't loaded. There are no processes, and the only > files anywhere are the ones we're in the process of extracting. What's there > fore selinux to do? > > When a filesystem is mounted, none of these cached selinux "we already looked at > the xattrs" inode fields are populated yet, correct? It can figure that out when > something accesses the file and do it then, so the point is _not_ doing this now > and thus not cacheing the wrong info. That's what the mount flag is doing, > telling selinux "not yet". So why does selinux not already _know_ "not yet"? > > Why doesn't load_policy flush the cache of the old default contexts? What > happens if you mount an ext2 root and then init reads a dozen files before it > gets to the load_policy? I need to check whether security context caching happens on all file operations, or when setxattr is executed. If latter, setxattr operation before policy load may not be very common use case. Also note there is a second SELinux related patch and corresponding Stephen's comment: if SELinux is enabled in kernel, but policy is not loaded yet, setxattr for security.selinux extended attribute will go for check to SELinux LSM callback, it will be denied. My other patch was relaxing above for "rootfs" only, i.e covering initramfs xattrs case. Stephen's point was that maybe it needs to be relaxed for all cases if policy not loaded yet. I need some time to look at the code and think about what can go wrong, if rule relaxed for all cases. > Do those doesn't files have bad default contexts forever now? > > Where does the selinux ruleset come from during the cpio extract? Yes, in our use case SELinux policy file (/etc/selinux/*/policy/policy.*) comes from cpio initramfs itself. So it is chicken and egg problem. > Was it > hardwired into the driver? It certainly didn't come out of a file, and it wasn't > a process that loaded it. Why is selinux trying to evaluate and cache the > security context of files before it has any rules? Note for ext2 case there is no setxattr first as we have in initramfs xattrs case, so extended attributes values are read from backing persitent storage as they were put there before, and there would not be discrepency what is cached in security context inode data scructure and real "security.selinux" extended attribute value in file system. Thanks, Victor > (It has xattr annotations, > but they have no _meaning_ without rules...? > > Confused, > > Rob >