Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1009656yba; Thu, 4 Apr 2019 02:20:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdJ94fS6LGzSwEaLktLRVO6vZPZaZuOO7IbSf8Cr2C94F4TcPRwnrOhQ+atCwof8mJnPpk X-Received: by 2002:a17:902:2963:: with SMTP id g90mr5228470plb.182.1554369614345; Thu, 04 Apr 2019 02:20:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369614; cv=none; d=google.com; s=arc-20160816; b=yIqmitNrxtPQI/4BlX3nFSMzqmneHHxgBa6JzYt5JuOpnzEdP54lkQhhs08uIYfJuh cCdYLiMS90e1nAusaDsH6+OZDrNiwX5uDAE1LElSlBtCIJl4M4KLsfzORNMCO26d+5n1 Y7zxMJ1FU4ZBwx1Uk+uzxzd39vzeppsyrXfZaXhHCpL7GbhBgJKBbTj1nc3Tvq2MhHbD ygULUJaihw215bl8t/yslh+8wkzMhQivBzFJ3vof+zJUs1kl7Y0N6+ZDZMTB7btBPtLm 0CjajENvIBvQbVhAGFHDbxhUQVnFwHLKAaMT07DLxnSvMD8VEvraQXOR23pbeM9sr68K i87Q== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D3H+ZJClxrrcPydfLxMhSVYdg8h5gAa3fylk35SPjSw=; b=pWe31ovVfs91O1UsLzFELK0Cn2VCK+pv7QBLfgVigePt92hR8nBrui0g5zbvPNHtdb u9eNhXybjsHAD4tuMt9oLq0YMylb2F+SlQ9aW+Y4NXRKwmq7yS00FhG6J26wr4pxoEFg nMJiHfOQPdMqSNDZzfd65Myk5lQLdCh+NB1m6MTP1heHqDYQ8AJWoUnEkrFYMI3MVwCo F5OWnU89jHlLVdkWSig4l/8LzX960poe0nN1byNRacwtmOtu/jfMil8LbOipWf98xSPW iPEk3kfX4c9L8E9NaSCFmCKO60LhnEdI0+jcqNJEclvWvqUW3fJiUomn+4DwQdZh+TSg J8Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="o2B/dV/h"; 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 k126si15790991pgk.109.2019.04.04.02.19.59; Thu, 04 Apr 2019 02:20:14 -0700 (PDT) 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=@kernel.org header.s=default header.b="o2B/dV/h"; 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 S2388334AbfDDJSM (ORCPT + 99 others); Thu, 4 Apr 2019 05:18:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:60256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388096AbfDDJSM (ORCPT ); Thu, 4 Apr 2019 05:18:12 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7511620693; Thu, 4 Apr 2019 09:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554369490; bh=wIhn27Ad3dmZoc+LudQ6V2c88fZYopziN/hPzs7GpfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o2B/dV/hWkSgtuBaLSdz7cH5KoJXTXQT+PNJe7LYi0WylXUPrSnSpO0D5303/WfCy YCSvUJQtXZqXQwu1G7kTrrfRksKS8Z0ouj1/YZbjIyTZK3280JD81LJJ3d9wmTHdI4 ElrSBiQJmfOJr7Q7lsQ/maSR9h2jigtOA5S9y+5c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ondrej Mosnacek , Stephen Smalley , Paul Moore , Sasha Levin Subject: [PATCH 5.0 228/246] selinux: do not override context on context mounts Date: Thu, 4 Apr 2019 10:48:48 +0200 Message-Id: <20190404084627.225938417@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 53e0c2aa9a59a48e3798ef193d573ade85aa80f5 ] Ignore all selinux_inode_notifysecctx() calls on mounts with SBLABEL_MNT flag unset. This is achived by returning -EOPNOTSUPP for this case in selinux_inode_setsecurtity() (because that function should not be called in such case anyway) and translating this error to 0 in selinux_inode_notifysecctx(). This fixes behavior of kernfs-based filesystems when mounted with the 'context=' option. Before this patch, if a node's context had been explicitly set to a non-default value and later the filesystem has been remounted with the 'context=' option, then this node would show up as having the manually-set context and not the mount-specified one. Steps to reproduce: # mount -t cgroup2 cgroup2 /sys/fs/cgroup/unified # chcon unconfined_u:object_r:user_home_t:s0 /sys/fs/cgroup/unified/cgroup.stat # ls -lZ /sys/fs/cgroup/unified total 0 -r--r--r--. 1 root root system_u:object_r:cgroup_t:s0 0 Dec 13 10:41 cgroup.controllers -rw-r--r--. 1 root root system_u:object_r:cgroup_t:s0 0 Dec 13 10:41 cgroup.max.depth -rw-r--r--. 1 root root system_u:object_r:cgroup_t:s0 0 Dec 13 10:41 cgroup.max.descendants -rw-r--r--. 1 root root system_u:object_r:cgroup_t:s0 0 Dec 13 10:41 cgroup.procs -r--r--r--. 1 root root unconfined_u:object_r:user_home_t:s0 0 Dec 13 10:41 cgroup.stat -rw-r--r--. 1 root root system_u:object_r:cgroup_t:s0 0 Dec 13 10:41 cgroup.subtree_control -rw-r--r--. 1 root root system_u:object_r:cgroup_t:s0 0 Dec 13 10:41 cgroup.threads # umount /sys/fs/cgroup/unified # mount -o context=system_u:object_r:tmpfs_t:s0 -t cgroup2 cgroup2 /sys/fs/cgroup/unified Result before: # ls -lZ /sys/fs/cgroup/unified total 0 -r--r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.controllers -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.max.depth -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.max.descendants -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.procs -r--r--r--. 1 root root unconfined_u:object_r:user_home_t:s0 0 Dec 13 10:41 cgroup.stat -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.subtree_control -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.threads Result after: # ls -lZ /sys/fs/cgroup/unified total 0 -r--r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.controllers -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.max.depth -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.max.descendants -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.procs -r--r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.stat -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.subtree_control -rw-r--r--. 1 root root system_u:object_r:tmpfs_t:s0 0 Dec 13 10:41 cgroup.threads Signed-off-by: Ondrej Mosnacek Reviewed-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- security/selinux/hooks.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index cf20dd36a30f..07b11b5aaf1f 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3244,12 +3244,16 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags) { struct inode_security_struct *isec = inode_security_novalidate(inode); + struct superblock_security_struct *sbsec = inode->i_sb->s_security; u32 newsid; int rc; if (strcmp(name, XATTR_SELINUX_SUFFIX)) return -EOPNOTSUPP; + if (!(sbsec->flags & SBLABEL_MNT)) + return -EOPNOTSUPP; + if (!value || !size) return -EACCES; @@ -6398,7 +6402,10 @@ static void selinux_inode_invalidate_secctx(struct inode *inode) */ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) { - return selinux_inode_setsecurity(inode, XATTR_SELINUX_SUFFIX, ctx, ctxlen, 0); + int rc = selinux_inode_setsecurity(inode, XATTR_SELINUX_SUFFIX, + ctx, ctxlen, 0); + /* Do not return error when suppressing label (SBLABEL_MNT not set). */ + return rc == -EOPNOTSUPP ? 0 : rc; } /* -- 2.19.1