Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5585962img; Wed, 27 Mar 2019 11:10:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQjl2tXIVMJpdW0YN2Fi07/BegBUd6/+1PeiTfbwNDxrK/ZRwYNm71AWUiuhQsY4fvJwTx X-Received: by 2002:a65:518b:: with SMTP id h11mr35863693pgq.41.1553710255940; Wed, 27 Mar 2019 11:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553710255; cv=none; d=google.com; s=arc-20160816; b=S+EcJUr46aQdH3U0jKEUldrWgvUycf5SMsCtTTsVGO0WmkIzuOfvIBi0Iq395i90Qr tPPxOjOCKBVJZqWZMzSmtTeV24USv4OdgtNVPcGok+hrnDy5Kavj6OSCYH2xLCpEs6k8 CBs5pIoJA2rlexabTjcqij0Zxz49U0UVDYAOQRhbJ8qdTTar9EdJfEsJRLRROHCerx70 BOLEGHejpgQxgyjmF8m1t3Z8S2+JWr6m86BdeBBB7LV82iO1hWlCzI373m8Rb+JwenoP 4At2CJnjptswtfGoD76rgQhzOkAOxgL91LNdtN/yMS0cVMEJk+1ShpL8u7JW9jLTO6RH 4qvw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fIXCgMmNDOeSfW6LEvJdhUr4qgbkOcio14aLHr3S8tg=; b=wpAqX3RIDONSqrQD7moHX42Pm1Qunz8blnhjLkTVFCc5dWMMTXiiDHNLn2JSsW90ux Ncq5jfsZfslJQnCfcmi0lyy69P+P3iVS4BHQBUq0YtTiuG0Y4+qaY7Z/CsfLHYVQcOrb 8pg+58Biv+fewQMcBxHGqRgOVLhV+oWKn5rY6fcOjLGiA8QXD8gvcevbI6lrWTgvLwy5 DFgptbbZFRm1jAAVtY5AZn+9BLVA0DIGB9zzB+WMPZsSN4j9nDhP5qNMGnlG5joxMgUl p6nomEm6b/bn1UllVK5E5Zg/aWmr+nTejm0ppJh9UbdU5u/kDODFjhCt8ceEKcfW5YbA V2Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zzsP0nyC; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c186si18955629pfg.160.2019.03.27.11.10.40; Wed, 27 Mar 2019 11:10:55 -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=zzsP0nyC; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388246AbfC0SJ4 (ORCPT + 99 others); Wed, 27 Mar 2019 14:09:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:51840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388058AbfC0SJy (ORCPT ); Wed, 27 Mar 2019 14:09:54 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 73712217F5; Wed, 27 Mar 2019 18:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710193; bh=dhB+nJjCKHYyE1/ZbW72elKblZJ8Gnr4w/43IGlIqCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zzsP0nyCapuqndupcxJCP9p+djYXjpe5KGQQJ4dgXnBNxffZvKmarM0Ak9st5UmpF VkVhkpb/CWJyUmXOK4o/T5zk83OpJYpCbRck08hRbQlzuH6xFjDX2hljry1UfaO7Jc YD/rYlvIx83pm7a0FoSpmoRxbjr4bRiVBjbg1YFY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ondrej Mosnacek , Paul Moore , Sasha Levin , selinux@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 244/262] selinux: do not override context on context mounts Date: Wed, 27 Mar 2019 14:01:39 -0400 Message-Id: <20190327180158.10245-244-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ondrej Mosnacek [ 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