Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754572AbdFWXmE (ORCPT ); Fri, 23 Jun 2017 19:42:04 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42514 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753397AbdFWXmC (ORCPT ); Fri, 23 Jun 2017 19:42:02 -0400 Subject: Re: [PATCH 3/3] Enable security.selinux in user namespaces To: Stephen Smalley , ebiederm@xmission.com, containers@lists.linux-foundation.org References: <1498157989-11814-1-git-send-email-stefanb@linux.vnet.ibm.com> <1498157989-11814-4-git-send-email-stefanb@linux.vnet.ibm.com> <1498249800.2063.9.camel@tycho.nsa.gov> Cc: lkp@01.org, xiaolong.ye@intel.com, linux-kernel@vger.kernel.org, zohar@linux.vnet.ibm.com, serge@hallyn.com, tycho@docker.com, James.Bottomley@HansenPartnership.com, christian.brauner@mailbox.org, vgoyal@redhat.com, amir73il@gmail.com, linux-security-module@vger.kernel.org, Paul Moore , selinux@tycho.nsa.gov From: Stefan Berger Date: Fri, 23 Jun 2017 19:41:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1498249800.2063.9.camel@tycho.nsa.gov> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17062323-0056-0000-0000-000003932E7C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007279; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00878879; UDB=6.00437974; IPR=6.00659031; BA=6.00005438; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015946; XFM=3.00000015; UTC=2017-06-23 23:41:59 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062323-0057-0000-0000-000007C94833 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-06-23_15:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706230402 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2526 Lines: 56 On 06/23/2017 04:30 PM, Stephen Smalley wrote: > On Thu, 2017-06-22 at 14:59 -0400, Stefan Berger wrote: >> Before the current modifications, SELinux extended attributes were >> visible inside the user namespace but changes in patch 1 hid them. >> This patch enables security.selinux in user namespaces and allows >> them to be written to in the same way as security.capability. >> >> Signed-off-by: Stefan Berger >> --- >> fs/xattr.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/fs/xattr.c b/fs/xattr.c >> index 045be85..37686ee 100644 >> --- a/fs/xattr.c >> +++ b/fs/xattr.c >> @@ -138,6 +138,7 @@ xattr_permission(struct inode *inode, const char >> *name, int mask) >> */ >> static const char *const userns_xattrs[] = { >> XATTR_NAME_CAPS, >> + XATTR_NAME_SELINUX, >> NULL >> }; >> > (cc SELinux maintainers, curiously omitted from these patches) > > I don't think this works for SELinux. You don't deal with actually > supporting multiple security.selinux attributes within SELinux itself > (and I'm not asking you to do so), and without such support, this can't > operate as intended. With these patches applied, IIUC, a setxattr() of > security.selinux within a userns will end up setting only security.seli > nux@uid=1000 on disk, but will then tell SELinux to update its in-core > security label to the new value (via security_inode_post_setxattr). > Meanwhile, on a subsequent getxattr(), you'll call > security_inode_getsecurity() with the security.selinux@uid=1000 name, > which will always fail because SELinux doesn't know anything about your > new scheme, and then you'll call the filesystem handler and returns its > value, which is no longer connected in any way to the actual label > being used by SELinux. Also, SELinux itself makes calls to > __vfs_getxattr() and __vfs_setxattr_noperm(), and I don't think your > name remapping is correct in those cases. > > You also can't hide security.selinux within user namespaces. Today > userspace can get and set security.selinux attributes within user > namespaces (if allowed by policy), and further can specify the label to > use for new files via /proc/self/attr/fscreate, which unsurprisingly > isn't addressed by your changes. Changing that would be a userspace > break. I modified the 1st patch now in such a way that only security.capability is rewritten, security.selinux and all other ones remain untouched. https://github.com/stefanberger/linux/commits/xattr_for_userns.v2 Stefan