Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1000483yba; Thu, 4 Apr 2019 02:07:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxD+XAYNcaGfszX5W6W9Jn41s+R0LNvg+JExyppdJPXPzJWQEJpeAUYTDhDgBKmWjZPSXCW X-Received: by 2002:a17:902:501:: with SMTP id 1mr5077771plf.72.1554368852167; Thu, 04 Apr 2019 02:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368852; cv=none; d=google.com; s=arc-20160816; b=nFhZoBMnZTCVVMDaQK9Iq8Mbpb9mmvJHCSzCKwvfKDecEOl1L/CWTpsBPuVms9SJOI IW2/w3HI4TZGZNENjeCFhouQCP9UiixWbpy/CDWDsxr4dYiNP84TVNmVJt3bcV9y9hfu g8n7JiVvrhEnTP715y7rix4GswuG7Ed7dnHmmuo6socaYHXpi6Wy1osFUzESxJ0uipVr dPLEt6b64UQM4qDnibEyM0DgMJjdgbgoTulY9JKCotfPq3v0gTU5052fC3y4aBnTf8bL W4yPFqlZFCknXaZ8mEEayxEzMwMD4qGkruyaXEWFSTrQjUoTDfBW1GlyHFpcqVMKdn/n 8bpQ== 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=ka7+hMBZj6QglnO6wXyYmaNcdHe6qeBnr9655jtK/GQ=; b=0C5+XV4lYetPudJ4q/67kTnVkR69v4NtaQRwSqp+w1e7otmT/EhwxFn2kRUNAIi2mD vjS/d41p/Lci21uwY5atmIlLBexh1K6GryxfQLJVUNMnralV4DUee8orYLivyyIUunTy b2cFBWb4O43iDjMf8xRNuXNa/3nzHVOJ8HtL9dlq6TGfltOd99g/NeCF4xUfbNib5rKo joYIwa2JrQjDkmXYhMejbelZDl90dbIIgp2LlM7LhT56joOQNnZ0IMK5aQAtQrhgCtUd kk3oj+IxjhoRu7b3gtZ61xvuTsIKeQRNW9Qnx8b/YZ/xi705iyQLqPTYIUDq23XPGPNT oZiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vTg1SOgh; 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 e2si15123807pgv.511.2019.04.04.02.07.16; Thu, 04 Apr 2019 02:07:32 -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=vTg1SOgh; 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 S1732364AbfDDJGl (ORCPT + 99 others); Thu, 4 Apr 2019 05:06:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:45190 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732103AbfDDJGj (ORCPT ); Thu, 4 Apr 2019 05:06:39 -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 69B84214AF; Thu, 4 Apr 2019 09:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368797; bh=3hrN+a90rPNh6Tvydl8pBFmesEKqxOlN/bKcsakY9s4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vTg1SOghu0hOtO5p65I0ec1KDHgdLnRwj5OvEG6y1RSzHjjpAqHy7hkSRzhjuH2/1 h3hKb1mh5+Pq7dN713b/rgjAfCV/v2u4ej2G8Dz0oCkPyP0FLLxsda0cBineiK6bj1 99mvTCRWCeYZ08uUEtRGXLkne1lm+O8PsJJtNENk= 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 4.19 174/187] selinux: do not override context on context mounts Date: Thu, 4 Apr 2019 10:48:31 +0200 Message-Id: <20190404084611.303022741@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@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 4.19-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 6ea3d3aa1a1e..4337b6d9369e 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3458,12 +3458,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; @@ -6612,7 +6616,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