Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1939934lqm; Fri, 3 May 2024 10:32:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIN5w4m8xy6P0trDft9Q9k6ofCrGcsEfPgYHtxsO7Zm92PmuQe32vb+g3h07VyW/Izhsa0cmHe6lFVWZx5q0/SomAnfhU5BedAsf3p9Q== X-Google-Smtp-Source: AGHT+IFpYx+9UZ6qqJimuBTUjFF09E4gR0tMhm+d83XTcXWllO/toG2YbdY+91kliJvnYWb5MUnA X-Received: by 2002:a05:6870:d211:b0:23d:3f36:a7e1 with SMTP id g17-20020a056870d21100b0023d3f36a7e1mr3697795oac.43.1714757573903; Fri, 03 May 2024 10:32:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714757573; cv=pass; d=google.com; s=arc-20160816; b=WiDAfQ2dcLtRTGrBPJhaXbl9HjlIGoY2ADJbMfm9UYLqi3tFb2jbgPH4p0YjC2nWe+ B5sJrJCPR6heZNfRmZLM8ECcJSxa9hj+NZu0MKz7Z8diD/iabyTDqUmyQXbae5hmBtM6 wBtWOwj0yv6Xg/HGh/Xx2p5BdFXOyAna0xGO0okE+GhKyFYvBAbCGK5sFjU3gEsJRrff WVAbOnKK3YWaBDeRr17MryQnD7NXsbAgfIBgqHUgHtqqc6ErXxHb1m4rY85wvkhioW2c 7bL5alb3NQOERUHSaTW+Q1MmETLNC0JqSkptgY2dfcZ8cCz4A/R+vsVXReywoOsHNyaX 31WA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=hZxAR463qkxBFk8GFcdCEONYZfjnkJis5lXYFHVjGb4=; fh=xUtARNLoMgV6UrdZSHPYqbzWceM6gunFGjOsW2Wlf6s=; b=bC0BcZgpKC8S/dzRu9sRv8zF2mbbAcTSCk+BekV7MvzkhO4WTpxeoyRq1BuemT9XG9 7BlBjJTWj10WGxaWhiDJ76XXUtH+8nqo33SqtGAvNZkT1plBUAbL51zNPKYvgRoq9LcU jRbZBlV6QuNUo8BcCXTkEISr31lJOVAFi0QdbwQ2vg02OoC8ixro7YqTu31GgofVqplJ mZ3XiRLN1uDMTMmtinRHQ+PxTKQ47vHBh3Rl9DCYSyEC+TemOFpNDTwInUbIK4blbj4F hpcPLa6CfeJw0o3inYmcN+PcSDVdfaCxhMffRU01ZHxrIZx5sfLIpfnV4smNUMK9UZ35 gRGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ymaer843; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-3150-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m8-20020ae9f208000000b00790edbcbf8bsi3570553qkg.176.2024.05.03.10.32.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 10:32:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3150-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ymaer843; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-3150-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4D5411C20FF9 for ; Fri, 3 May 2024 17:31:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D4C8E157E6B; Fri, 3 May 2024 17:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ymaer843" X-Original-To: linux-nfs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA08013B593; Fri, 3 May 2024 17:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714757511; cv=none; b=PWu6CAzctSvX32glWmxRdywHcZI8m2Pofa59a90N5MbkjH6XmxfhL9/Ah3iJBVg6Eqwq7U8EDepbFNfx+4XAQT0jJKOwHHW1SBGHk9Oj0hy99ArdUFIXNLKiuZZw21YqFKvd54FzOnkKlR68PwdO+ZRxQ4/ZZmGGP6lPG3Ll9ZY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714757511; c=relaxed/simple; bh=NA8Lb6bNRP/z+eXkOqMJbaWB5ZBHyOdDEvk7/px99vE=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=Txh4cZtuM+F9KYoUA8zevIK3v+IBrb9Ygbniyvs05WsPqvayOrJN8l5zzfRNbzNMU8v7Peylb0hw+u0A3wZM5R5t3nF/7/1qFYbRVzqpBDma6kDlwN/AhrB8pp7w2rCYGYYAZXc64vEZEVzDEm6zIRcyopFtY6QpVe38ltO47Xo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ymaer843; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EE06C116B1; Fri, 3 May 2024 17:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714757511; bh=NA8Lb6bNRP/z+eXkOqMJbaWB5ZBHyOdDEvk7/px99vE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Ymaer8435Ebdaect7lbFLXNBCiCR7vefJwiSLtATML7X7AB9Y42zxiCxjCi8i0uhl x4Ofqfee+0612S+XyoA8TMbb6bHWc5IKCWo8mboFDL//wPCgSBay1iONOqgvEIaD2/ kWwkzsOmrVo4QvTGrx+3u4sZqDjVvbggmV2fgWIFt2sSGc6R9pnT5UKI50WAvfD4ss lUxVGlbu5FVlZPX7HHPCA+YNZksr5qOAk+2SSbllflaBk2Pt+510BOOAF9VnvjufuH 0AODC+0ZUQCZIZbi+xockPgylcSkKIhBloGpqLn9CC5sxrQSD+NlOIXiWrmYnSxYCm ClyFqNcJKehaw== Message-ID: <53810d77218a7a67fc35f5977584664d54d0e575.camel@kernel.org> Subject: Re: [PATCH v3] nfsd: set security label during create operations From: Jeffrey Layton To: Stephen Smalley , selinux@vger.kernel.org, linux-nfs@vger.kernel.org, chuck.lever@oracle.com, neilb@suse.de Cc: paul@paul-moore.com, omosnace@redhat.com, linux-security-module@vger.kernel.org Date: Fri, 03 May 2024 13:31:49 -0400 In-Reply-To: <20240503130905.16823-1-stephen.smalley.work@gmail.com> References: <20240503130905.16823-1-stephen.smalley.work@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.0 (3.52.0-1.fc40app1) Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Fri, 2024-05-03 at 09:09 -0400, Stephen Smalley wrote: > When security labeling is enabled, the client can pass a file security > label as part of a create operation for the new file, similar to mode > and other attributes. At present, the security label is received by nfsd > and passed down to nfsd_create_setattr(), but nfsd_setattr() is never > called and therefore the label is never set on the new file. This bug > may have been introduced on or around commit d6a97d3f589a ("NFSD: > add security label to struct nfsd_attrs"). Looking at nfsd_setattr() > I am uncertain as to whether the same issue presents for > file ACLs and therefore requires a similar fix for those. >=20 > An alternative approach would be to introduce a new LSM hook to set the > "create SID" of the current task prior to the actual file creation, which > would atomically label the new inode at creation time. This would be bett= er > for SELinux and a similar approach has been used previously > (see security_dentry_create_files_as) but perhaps not usable by other LSM= s. >=20 > Reproducer: > 1. Install a Linux distro with SELinux - Fedora is easiest > 2. git clone https://github.com/SELinuxProject/selinux-testsuite > 3. Install the requisite dependencies per selinux-testsuite/README.md > 4. Run something like the following script: > MOUNT=3D$HOME/selinux-testsuite > sudo systemctl start nfs-server > sudo exportfs -o rw,no_root_squash,security_label localhost:$MOUNT > sudo mkdir -p /mnt/selinux-testsuite > sudo mount -t nfs -o vers=3D4.2 localhost:$MOUNT /mnt/selinux-testsuite > pushd /mnt/selinux-testsuite/ > sudo make -C policy load > pushd tests/filesystem > sudo runcon -t test_filesystem_t ./create_file -f trans_test_file \ > -e test_filesystem_filetranscon_t -v > sudo rm -f trans_test_file > popd > sudo make -C policy unload > popd > sudo umount /mnt/selinux-testsuite > sudo exportfs -u localhost:$MOUNT > sudo rmdir /mnt/selinux-testsuite > sudo systemctl stop nfs-server >=20 > Expected output: > > Process context: > unconfined_u:unconfined_r:test_filesystem_t:s0-s0:c0.c1023 > Created file: trans_test_file > File context: unconfined_u:object_r:test_filesystem_filetranscon_t:s0 > File context is correct >=20 > Actual output: > > Process context: > unconfined_u:unconfined_r:test_filesystem_t:s0-s0:c0.c1023 > Created file: trans_test_file > File context: system_u:object_r:test_file_t:s0 > File context error, expected: > test_filesystem_filetranscon_t > got: > test_file_t >=20 > Signed-off-by: Stephen Smalley > --- > v3 removes the erroneous and unnecessary change to NFSv2 and updates the > description to note the possible origin of the bug. I did not add a=20 > Fixes tag however as I have not yet tried confirming that. >=20 > fs/nfsd/vfs.c | 2 +- > fs/nfsd/vfs.h | 8 ++++++++ > 2 files changed, 9 insertions(+), 1 deletion(-) >=20 > diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c > index 2e41eb4c3cec..29b1f3613800 100644 > --- a/fs/nfsd/vfs.c > +++ b/fs/nfsd/vfs.c > @@ -1422,7 +1422,7 @@ nfsd_create_setattr(struct svc_rqst *rqstp, struct = svc_fh *fhp, > * Callers expect new file metadata to be committed even > * if the attributes have not changed. > */ > - if (iap->ia_valid) > + if (nfsd_attrs_valid(attrs)) > status =3D nfsd_setattr(rqstp, resfhp, attrs, NULL); > else > status =3D nfserrno(commit_metadata(resfhp)); > diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h > index c60fdb6200fd..57cd70062048 100644 > --- a/fs/nfsd/vfs.h > +++ b/fs/nfsd/vfs.h > @@ -60,6 +60,14 @@ static inline void nfsd_attrs_free(struct nfsd_attrs *= attrs) > posix_acl_release(attrs->na_dpacl); > } > =20 > +static inline bool nfsd_attrs_valid(struct nfsd_attrs *attrs) > +{ > + struct iattr *iap =3D attrs->na_iattr; > + > + return (iap->ia_valid || (attrs->na_seclabel && > + attrs->na_seclabel->len)); > +} > + > __be32 nfserrno (int errno); > int nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp, > struct svc_export **expp); Reviewed-by: Jeff Layton