Received: by 10.223.185.116 with SMTP id b49csp5264882wrg; Wed, 7 Mar 2018 08:55:29 -0800 (PST) X-Google-Smtp-Source: AG47ELs6wFtjTOnsW91LzI3WYs4uXFERECzQIQLUwhAtrkO1BRTF2Lqo8xAcu2b0xXrYX4Gk6e2J X-Received: by 10.99.66.65 with SMTP id p62mr18220656pga.378.1520441729685; Wed, 07 Mar 2018 08:55:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520441729; cv=none; d=google.com; s=arc-20160816; b=dqJlSbxTzj4qTB/v7vxN/mq0WKmzZsnuLCnIErupF4VRL6I7WpqOWLbkPHIVQ5QjU1 WVJKwJl3VIE1HAhatTF3TgGscm/qcDLitBducPuRG6HLXkbJNAkUkd+p0BizjnzCawzk PtXj3AI5lXaHbiyFLFGSf0mgJ2KAvIy8MqVxImNBNIdrvCPjiL67WOM5e/x0WRTH1MZm dS4qFWfOdFeFqHWMvWUvSlWshluxfBrzgGY1pyO3G+ke3LU3Hnd7b2V64Btw5NXqknIt oVi6psg1jNwaWkKDfpMxQcEbtUXLCk/IsRPjA3FYgwiR3FuGsr39PievWTsy5i32bkSl s3Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=xsQ1lFI+l1KEpm1Fl0Qcp8heR18ZU4r7mzeNrvr+hkM=; b=xqLh2azttjR5bsbKYP8pRPPvN/fvkCNAqJhbWX0LVS9g20pF0XIrqePK+A5F6hV8uN r2CgwneYNzo4mUNxcdSd+sdI/C1d8q26K3erdqtBIXFVcz+CojkMiX7cjfZk4iGzWp4F 4P8iPYF8Nf25Tnvy0ag3AMAxT9S52d1OXYysUFCAraL9eAmG5qvLcDzegsBF1Pj8hUgG IuWpTNsoOsBg8B5EEO4ztgpQfRADIb+7mP6BTc+ofKfDfBxxi7pmTGDE+pLQ5G7OLPIi AyTpC/6Hetca+bvWC9zNR+Kv8Tl543HgsIAlB/HDxKE2+0d9mNhTcQffqa2BuIWbBxDE PJdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@landley-net.20150623.gappssmtp.com header.s=20150623 header.b=F1aKnV4A; 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 n11si11593672pgq.439.2018.03.07.08.55.14; Wed, 07 Mar 2018 08:55:29 -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=@landley-net.20150623.gappssmtp.com header.s=20150623 header.b=F1aKnV4A; 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 S934241AbeCGQxc (ORCPT + 99 others); Wed, 7 Mar 2018 11:53:32 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:51314 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934117AbeCGQvk (ORCPT ); Wed, 7 Mar 2018 11:51:40 -0500 Received: by mail-it0-f67.google.com with SMTP id u66so4061302ith.1 for ; Wed, 07 Mar 2018 08:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=landley-net.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=xsQ1lFI+l1KEpm1Fl0Qcp8heR18ZU4r7mzeNrvr+hkM=; b=F1aKnV4A2n5Hvd7c/k3LweCZGmW8303NKccSLZbnnRo2h/fCeZuvd3GDH7v5YgbY2D U8cJVM0PFYbPGBMJixCEruiEzNLCsSBrP0MjlpO7m9DtRG7Dfb55bTgKHbEtCjmAQXMM BG5yrTgqSjgc0xo7wZhN5oxt00GrfALU4TfsqxD+TtO0Kt1/QboPr4i30uni5HIrXg/q jU/Q/zANWPonpThnvRtAPPfE6YADG8EdsTmFWxCseiGmdx301tXxbFN6rD56F8HaAGw1 PtvXv/UWvVHF70ekV4nRO7SDdia+XDjTxy8lSo6ranBxwc1Jwraecd6oyiRq+MG0whQq 0/zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=xsQ1lFI+l1KEpm1Fl0Qcp8heR18ZU4r7mzeNrvr+hkM=; b=KqfA0VXRT47+Jz5bW1/zHtiN1e3lLyFl75X/gXK41VwUBM679MzJCxM4eAKdTMIWiO LcI83QD4splG1uu2KNGNO+D2r/88cE3zXAJD6ReEuebepJBBiNu6R6pNkqUBJu65JHx/ iyiFxvxFvseRSuZD+2d9r2XceUcgjat/4QXcNHD7sSb3JYQcUj26RKymjR00doyJsgRG e3OCUJ0BdG6Kb/Yi8Pe3MR8ibuiKMUShidduuYbFDtej1gZcJpnepP95SnjgLlYy7P/9 IjWb6+El3PKiYFn7quALeiEWWiMgLueKXiJ6Oy7c3TWkbE21JsUeK3KfFYfv5ILAXPSz yezA== X-Gm-Message-State: AElRT7GECU66O7QWHLdvKk1wNwzR3Asxt5ilyCfddIdXn8dXNjFkgZyW +72ALlGkUYVLQYmOuGh7THntpg== X-Received: by 10.36.88.5 with SMTP id f5mr23611272itb.63.1520441499321; Wed, 07 Mar 2018 08:51:39 -0800 (PST) Received: from [192.168.42.60] ([172.58.139.197]) by smtp.googlemail.com with ESMTPSA id h63sm9127388ith.40.2018.03.07.08.51.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Mar 2018 08:51:38 -0800 (PST) Subject: Re: [PATCH v3 15/15] selinux: delay sid population for rootfs till init is complete To: Stephen Smalley , Taras Kondratiuk , "H. Peter Anvin" , Al Viro , Arnd Bergmann , Mimi Zohar , Jonathan Corbet , James McMechan Cc: initramfs@vger.kernel.org, Victor Kamensky , 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 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> From: Rob Landley Message-ID: Date: Wed, 7 Mar 2018 10:51:36 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1519152994.14218.15.camel@tycho.nsa.gov> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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? Do those doesn't files have bad default contexts forever now? Where does the selinux ruleset come from during the cpio extract? 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? (It has xattr annotations, but they have no _meaning_ without rules...? Confused, Rob