FAILED: patch "[PATCH] NFSD: NFSv4 file creation neglects setting ACL" failed to apply to 6.6-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 913f7cf77bf14c13cfea70e89bcb6d0b22239562
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025122941-civic-revered-b250@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 913f7cf77bf14c13cfea70e89bcb6d0b22239562 Mon Sep 17 00:00:00 2001
From: Chuck Lever <[email protected]>
Date: Tue, 18 Nov 2025 19:51:19 -0500
Subject: [PATCH] NFSD: NFSv4 file creation neglects setting ACL
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
An NFSv4 client that sets an ACL with a named principal during file creation retrieves the ACL afterwards, and finds that it is only a default ACL (based on the mode bits) and not the ACL that was requested during file creation. This violates RFC 8881 section 6.4.1.3: "the ACL attribute is set as given".
The issue occurs in nfsd_create_setattr(), which calls nfsd_attrs_valid() to determine whether to call nfsd_setattr(). However, nfsd_attrs_valid() checks only for iattr changes and security labels, but not POSIX ACLs. When only an ACL is present, the function returns false, nfsd_setattr() is skipped, and the POSIX ACL is never applied to the inode.
Subsequently, when the client retrieves the ACL, the server finds no POSIX ACL on the inode and returns one generated from the file's mode bits rather than returning the originally-specified ACL.
fs/nfsd/vfs.h +2 -1
@@ -67,7 +67,8 @@ static inline bool nfsd_attrs_valid(struct nfsd_attrs *attrs)struct iattr *iap = attrs->na_iattr;return (iap->ia_valid || (attrs->na_seclabel && - attrs->na_seclabel->len)); + attrs->na_seclabel->len) || + attrs->na_pacl || attrs->na_dpacl); }__be32 nfserrno (int errno);
Chuck Lever
maintainercover NFSD: NFSv4 file creation neglects setting ACL
From: Chuck Lever <[email protected]>
I received an automated report that patch "NFSD: NFSv4 file creation neglects setting ACL" failed to apply to the 6.6-stable tree. This series is my attempt to address that failure.
- First, applied several pre-requisite patches
- LLM agent review for possible regressions reported no issues
- CI testing reported no regressions
Chuck Lever (4):
nfsd: convert to new timestamp accessors
nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
nfsd: set security label during create operations
NFSD: NFSv4 file creation neglects setting ACL
fs/nfsd/nfs3proc.c | 10 ++++++---- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 11 +++++------ fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 22 ++++++++++++++-------- fs/nfsd/vfs.h | 11 ++++++++++- fs/nfsd/xdr3.h | 2 +- 9 files changed, 42 insertions(+), 29 deletions(-)
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH 1/4 nfsd: convert to new timestamp accessors
From: Chuck Lever <[email protected]>
[ Upstream commit 335a7be84b526861f3deb4fdd5d5c2a48cf1feef ]
[ cel: adjust to the 6.6.y version of fs/nfsd/blocklayout.c ]
Stable-dep-of: 24d92de9186e ("nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()")
--- fs/nfsd/nfs3proc.c | 4 ++-- fs/nfsd/nfs4proc.c | 8 ++++---- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/vfs.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-)
fs/nfsd/nfs3proc.c +2 -2
@@ -294,8 +294,8 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS3_CREATE_EXCLUSIVE : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) {break ; }
fs/nfsd/nfs4proc.c +4 -4
@@ -322,8 +322,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS4_CREATE_EXCLUSIVE : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) { open->op_created = true;break ;/* subtle */
@@ -331,8 +331,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS4_CREATE_EXCLUSIVE4_1 : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) { open->op_created = true; goto set_attr;/* subtle */
fs/nfsd/nfsctl.c +1 -1
@@ -1140,7 +1140,7 @@ static struct inode *nfsd_get_inode(struct super_block *sb, umode_t mode)/* Following advice from simple_fill_super documentation: */ inode->i_ino =iunique (sb, NFSD_MaxReserved); inode->i_mode = mode; - inode->i_atime = inode->i_mtime =inode_set_ctime_current (inode); +simple_inode_init_ts (inode);switch (mode &S_IFMT ) {case S_IFDIR : inode->i_fop = &simple_dir_operations;
fs/nfsd/vfs.c +1 -1
@@ -521,7 +521,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime (inode).tv_sec) +if (check_guard && guardtime !=inode_get_ctime_sec (inode))return nfserr_notsync;/*
Signature · 1 line
2.52.0
Greg Kroah-Hartman
maintainerRe: [PATCH 6.6.y 1/4] nfsd: convert to new timestamp accessors
Quoted 3 lines · Chuck Lever
From: Chuck Lever <[email protected]>
[ Upstream commit
335a7be84b526861f3deb4fdd5d5c2a48cf1feef]
I don't see this git id anywhere in Linus's tree, are you sure it is correct?
thanks,
greg k-h
Chuck Lever
maintainerRe: [PATCH 6.6.y 1/4] nfsd: convert to new timestamp accessors
Quoted 11 lines · Greg Kroah-Hartman
Quoted 3 lines · Chuck Lever
From: Chuck Lever <[email protected]>
[ Upstream commit
335a7be84b526861f3deb4fdd5d5c2a48cf1feef]I don't see this git id anywhere in Linus's tree, are you sure it is correct?
thanks,
greg k-h
If I start from the current upstream master, I find this instead:
commit 11fec9b9fb04fd1b3330a3b91ab9dcfa81ad5ad3
Author: Jeff Layton <[email protected]> AuthorDate: Wed Oct 4 14:52:37 2023 -0400 Commit: Christian Brauner <[email protected]> CommitDate: Wed Oct 18 14:08:24 2023 +0200
nfsd: convert to new timestamp accessors
Convert to using the new inode timestamp accessor functions.
Link:
https://lore.kernel.org/r/[email protected]
I picked up 335a7be84b526861f3deb4fdd5d5c2a48cf1feef from an nfsd-related tag by mistake. Do you want to drop this series and I can rework it properly?
Signature · 1 line
Chuck Lever
Greg Kroah-Hartman
maintainerRe: [PATCH 6.6.y 1/4] nfsd: convert to new timestamp accessors
Quoted 25 lines · Chuck Lever
Quoted 11 lines · Greg Kroah-Hartman
Quoted 3 lines · Chuck Lever
From: Chuck Lever <[email protected]>
[ Upstream commit
335a7be84b526861f3deb4fdd5d5c2a48cf1feef]I don't see this git id anywhere in Linus's tree, are you sure it is correct?
thanks,
greg k-h
If I start from the current upstream master, I find this instead:
commit
11fec9b9fb04fd1b3330a3b91ab9dcfa81ad5ad3Author: Jeff Layton <[email protected]> AuthorDate: Wed Oct 4 14:52:37 2023 -0400 Commit: Christian Brauner <[email protected]> CommitDate: Wed Oct 18 14:08:24 2023 +0200nfsd: convert to new timestamp accessors
Convert to using the new inode timestamp accessor functions.
Quoted 8 lines
Signed-off-by Jeff Layton <[email protected]>Link:
https://lore.kernel.org/r/[email protected]Signed-off-by Christian Brauner <[email protected]>I picked up
335a7be84b526861f3deb4fdd5d5c2a48cf1feeffrom an nfsd-related tag by mistake. Do you want to drop this series and I can rework it properly?
Now dropped, please rework, thanks!
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH 6.6.y 1/4] nfsd: convert to new timestamp accessors
In reply to Chuck LeverQuoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
[ Upstream commit
335a7be84b526861f3deb4fdd5d5c2a48cf1feef][ cel: adjust to the 6.6.y version of
fs/nfsd/blocklayout.c]
Stable-dep-of:24d92de9186e("nfsd: Fix NFSv3 atomicity bugs innfsd_setattr()")Signed-off-by Chuck Lever <[email protected]>---
Is this really commit 11fec9b9fb04 ("nfsd: convert to new timestamp accessors")? if so, what happened to the original authorship and other signed-off-by lines?
thanks,
greg k-h
Chuck Lever
maintainerPATCH 2/4 nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
[ Upstream commit 24d92de9186ebc340687caf7356e1070773e67bc ]
nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
The main point of the guarded SETATTR is to prevent races with other WRITE and SETATTR calls. That requires that the check of the guard time against the inode ctime be done after taking the inode lock.
Furthermore, we need to take into account the 32-bit nature of timestamps in NFSv3, and the possibility that files may change at a faster rate than once a second.
Stable-dep-of: 442d27ff09a2 ("nfsd: set security label during create operations")
--- fs/nfsd/nfs3proc.c | 6 ++++-- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 3 +-- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 20 +++++++++++++------- fs/nfsd/vfs.h | 2 +- fs/nfsd/xdr3.h | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-)
fs/nfsd/nfs3proc.c +4 -2
@@ -71,13 +71,15 @@ nfsd3_proc_setattr(struct svc_rqst *rqstp)struct nfsd_attrs attrs = { .na_iattr = &argp->attrs, }; +const struct timespec64 *guardtime =NULL ;dprintk ("nfsd: SETATTR(3) %s\n" ,SVCFH_fmt (&argp->fh));fh_copy (&resp->fh, &argp->fh); - resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, - argp->check_guard, argp->guardtime); +if (argp->check_guard) + guardtime = &argp->guardtime; + resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, guardtime);return rpc_success; }
fs/nfsd/nfs3xdr.c +1 -4
@@ -295,17 +295,14 @@ svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,static bool svcxdr_decode_sattrguard3 (struct xdr_stream *xdr,struct nfsd3_sattrargs *args) { -__be32 *p;u32 check;if (xdr_stream_decode_bool (xdr, &check) <0 )return false;if (check) { - p =xdr_inline_decode (xdr,XDR_UNIT *2 ); -if (!p) +if (!svcxdr_decode_nfstime3 (xdr, &args->guardtime))return false; args->check_guard =1 ; - args->guardtime =be32_to_cpup (p); }else args->check_guard =0 ;
fs/nfsd/nfs4proc.c +1 -2
@@ -1160,8 +1160,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; save_no_wcc = cstate->current_fh.fh_no_wcc; cstate->current_fh.fh_no_wcc = true; - status =nfsd_setattr (rqstp, &cstate->current_fh, &attrs, -0 , (time64_t )0 ); + status =nfsd_setattr (rqstp, &cstate->current_fh, &attrs,NULL ); cstate->current_fh.fh_no_wcc = save_no_wcc;if (!status) status =nfserrno (attrs.na_labelerr);
fs/nfsd/nfs4state.c +1 -1
@@ -5223,7 +5223,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,return 0 ;if (!(open->op_share_access &NFS4_SHARE_ACCESS_WRITE ))return nfserr_inval; -return nfsd_setattr (rqstp, fh, &attrs,0 , (time64_t )0 ); +return nfsd_setattr (rqstp, fh, &attrs,NULL ); } static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
fs/nfsd/nfsproc.c +3 -3
@@ -103,7 +103,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp) } } - resp->status =nfsd_setattr (rqstp, fhp, &attrs,0 , (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, fhp, &attrs,NULL );if (resp->status != nfs_ok) goto out;
@@ -390,8 +390,8 @@ nfsd_proc_create(struct svc_rqst *rqstp)*/ attr->ia_valid &=ATTR_SIZE ;if (attr->ia_valid) - resp->status =nfsd_setattr (rqstp, newfhp, &attrs,0 , - (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, newfhp, &attrs, +NULL ); } out_unlock:
fs/nfsd/vfs.c +13 -7
@@ -459,7 +459,6 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)* @rqstp: controlling RPC transaction * @fhp: filehandle of target * @attr: attributes to set -* @check_guard: set to 1 if guardtime is a valid timestamp * @guardtime: do not act if ctime.tv_sec does not match this timestamp * * This call may adjust the contents of @attr (in particular, this
@@ -471,8 +470,7 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)*/ __be32 nfsd_setattr (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct nfsd_attrs *attr, -int check_guard,time64_t guardtime) +struct nfsd_attrs *attr,const struct timespec64 *guardtime) {struct dentry *dentry;struct inode *inode;
@@ -521,9 +519,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime_sec (inode)) -return nfserr_notsync; -/* * The size case is special, it changes the file in addition to the * attributes, and file systems don't expect it to be mixed with
@@ -541,6 +536,16 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, err =fh_fill_pre_attrs (fhp);if (err) goto out_unlock; + +if (guardtime) { +struct timespec64 ctime =inode_get_ctime (inode); +if ((u32 )guardtime->tv_sec != (u32 )ctime.tv_sec || + guardtime->tv_nsec != ctime.tv_nsec) { + err = nfserr_notsync; + goto out_fill_attrs; + } + } +for (retries =1 ;;) {struct iattr attrs;
@@ -568,6 +573,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, attr->na_aclerr =set_posix_acl (&nop_mnt_idmap, dentry,ACL_TYPE_DEFAULT , attr->na_dpacl); +out_fill_attrs:fh_fill_post_attrs (fhp); out_unlock:inode_unlock (inode);
@@ -1374,7 +1380,7 @@ nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,* if the attributes have not changed. */ if (iap->ia_valid) - status =nfsd_setattr (rqstp, resfhp, attrs,0 , (time64_t )0 ); + status =nfsd_setattr (rqstp, resfhp, attrs,NULL );else status =nfserrno (commit_metadata (resfhp));
fs/nfsd/vfs.h +1 -1
@@ -69,7 +69,7 @@ __be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *, const char *, unsigned int, struct svc_export **, struct dentry **);__be32 nfsd_setattr (struct svc_rqst *,struct svc_fh *, -struct nfsd_attrs *,int ,time64_t ); +struct nfsd_attrs *,const struct timespec64 *);int nfsd_mountpoint (struct dentry *,struct svc_export *);#ifdef CONFIG_NFSD_V4 __be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
fs/nfsd/xdr3.h +1 -1
@@ -14,7 +14,7 @@ struct nfsd3_sattrargs {struct svc_fh fh;struct iattr attrs;int check_guard; -time64_t guardtime; +struct timespec64 guardtime; };struct nfsd3_diropargs {
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH 3/4 nfsd: set security label during create operations
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
[ Upstream commit 442d27ff09a218b61020ab56387dbc508ad6bfa6 ]
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.
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 better for SELinux and a similar approach has been used previously (see security_dentry_create_files_as) but perhaps not usable by other LSMs.
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=$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=4.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
Expected output:
<eliding noise from commands run prior to or after the test itself> 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
Actual output:
<eliding noise from commands run prior to or after the test itself> 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
Stable-dep-of: 913f7cf77bf1 ("NFSD: NFSv4 file creation neglects setting ACL")
--- fs/nfsd/vfs.c | 2 +- fs/nfsd/vfs.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
fs/nfsd/vfs.c +1 -1
@@ -1379,7 +1379,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 =nfsd_setattr (rqstp, resfhp, attrs,NULL );else status =nfserrno (commit_metadata (resfhp));
fs/nfsd/vfs.h +8 -0
@@ -60,6 +60,14 @@ static inline void nfsd_attrs_free(struct nfsd_attrs *attrs)posix_acl_release (attrs->na_dpacl); } +static inline bool nfsd_attrs_valid (struct nfsd_attrs *attrs) +{ +struct iattr *iap = 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);
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH 4/4 NFSD: NFSv4 file creation neglects setting ACL
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
[ Upstream commit 913f7cf77bf14c13cfea70e89bcb6d0b22239562 ]
An NFSv4 client that sets an ACL with a named principal during file creation retrieves the ACL afterwards, and finds that it is only a default ACL (based on the mode bits) and not the ACL that was requested during file creation. This violates RFC 8881 section 6.4.1.3: "the ACL attribute is set as given".
The issue occurs in nfsd_create_setattr(), which calls nfsd_attrs_valid() to determine whether to call nfsd_setattr(). However, nfsd_attrs_valid() checks only for iattr changes and security labels, but not POSIX ACLs. When only an ACL is present, the function returns false, nfsd_setattr() is skipped, and the POSIX ACL is never applied to the inode.
Subsequently, when the client retrieves the ACL, the server finds no POSIX ACL on the inode and returns one generated from the file's mode bits rather than returning the originally-specified ACL.
--- fs/nfsd/vfs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/vfs.h +2 -1
@@ -65,7 +65,8 @@ static inline bool nfsd_attrs_valid(struct nfsd_attrs *attrs)struct iattr *iap = attrs->na_iattr;return (iap->ia_valid || (attrs->na_seclabel && - attrs->na_seclabel->len)); + attrs->na_seclabel->len) || + attrs->na_pacl || attrs->na_dpacl); }__be32 nfserrno (int errno);
Signature · 1 line
2.52.0
Chuck Lever
maintainerv2 cover NFSD: NFSv4 file creation neglects setting ACL
In reply to [email protected]From: Chuck Lever <[email protected]>
I received an automated report that patch "NFSD: NFSv4 file creation neglects setting ACL" failed to apply to the 6.6-stable tree. This series is my attempt to address that failure.
- First, applied several pre-requisite patches
- LLM agent review for possible regressions reported no issues
- CI testing reported no regressions
Changes since v1:
- Replace 1/4 with the upstreamed version of that commit
Chuck Lever (1):
NFSD: NFSv4 file creation neglects setting ACL
Jeff Layton (1):
nfsd: convert to new timestamp accessors
Stephen Smalley (1):
nfsd: set security label during create operations
Trond Myklebust (1):
nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
fs/nfsd/blocklayout.c | 4 +++- fs/nfsd/nfs3proc.c | 10 ++++++---- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 11 +++++------ fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 22 ++++++++++++++-------- fs/nfsd/vfs.h | 11 ++++++++++- fs/nfsd/xdr3.h | 2 +- 10 files changed, 45 insertions(+), 30 deletions(-)
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 1/4 nfsd: convert to new timestamp accessors
In reply to [email protected]From: Jeff Layton <[email protected]>
[ Upstream commit 11fec9b9fb04fd1b3330a3b91ab9dcfa81ad5ad3 ]
Convert to using the new inode timestamp accessor functions.
Stable-dep-of: 24d92de9186e ("nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()")
--- fs/nfsd/blocklayout.c | 4 +++- fs/nfsd/nfs3proc.c | 4 ++-- fs/nfsd/nfs4proc.c | 8 ++++---- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/vfs.c | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-)
fs/nfsd/blocklayout.c +3 -1
@@ -117,11 +117,13 @@ static __be32 nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp, struct iomap *iomaps, int nr_iomaps) { + struct timespec64 mtime = inode_get_mtime(inode); +loff_t new_size = lcp->lc_last_wr +1 ;struct iattr iattr = { .ia_valid =0 };int error;if (lcp->lc_mtime.tv_nsec ==UTIME_NOW || -timespec64_compare (&lcp->lc_mtime, &inode->i_mtime) <0 ) +timespec64_compare (&lcp->lc_mtime, &mtime) <0 ) lcp->lc_mtime =current_time (inode); iattr.ia_valid |=ATTR_ATIME |ATTR_CTIME |ATTR_MTIME ; iattr.ia_atime = iattr.ia_ctime = iattr.ia_mtime = lcp->lc_mtime;
fs/nfsd/nfs3proc.c +2 -2
@@ -294,8 +294,8 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS3_CREATE_EXCLUSIVE : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) {break ; }
fs/nfsd/nfs4proc.c +4 -4
@@ -322,8 +322,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS4_CREATE_EXCLUSIVE : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) { open->op_created = true;break ;/* subtle */
@@ -331,8 +331,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS4_CREATE_EXCLUSIVE4_1 : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) { open->op_created = true; goto set_attr;/* subtle */
fs/nfsd/nfsctl.c +1 -1
@@ -1140,7 +1140,7 @@ static struct inode *nfsd_get_inode(struct super_block *sb, umode_t mode)/* Following advice from simple_fill_super documentation: */ inode->i_ino =iunique (sb, NFSD_MaxReserved); inode->i_mode = mode; - inode->i_atime = inode->i_mtime =inode_set_ctime_current (inode); +simple_inode_init_ts (inode);switch (mode &S_IFMT ) {case S_IFDIR : inode->i_fop = &simple_dir_operations;
fs/nfsd/vfs.c +1 -1
@@ -521,7 +521,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime (inode).tv_sec) +if (check_guard && guardtime !=inode_get_ctime_sec (inode))return nfserr_notsync;/*
Signature · 1 line
2.52.0
Chuck Lever
maintainerRe: [PATCH 6.6.y v2 1/4] nfsd: convert to new timestamp accessors
Quoted 10 lines · Chuck Lever
From: Jeff Layton <[email protected]>
[ Upstream commit
11fec9b9fb04fd1b3330a3b91ab9dcfa81ad5ad3]Convert to using the new inode timestamp accessor functions.
Signed-off-by Jeff Layton <[email protected]>Stable-dep-of:
24d92de9186e("nfsd: Fix NFSv3 atomicity bugs innfsd_setattr()")Signed-off-by Christian Brauner <[email protected]>
Quoted 101 lines
--- fs/nfsd/blocklayout.c | 4 +++- fs/nfsd/nfs3proc.c | 4 ++-- fs/nfsd/nfs4proc.c | 8 ++++---- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/vfs.c | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-)fs/nfsd/blocklayout.c +3
-1@@ -117,11 +117,13 @@ static __be32 nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp, struct iomap *iomaps, int nr_iomaps) { + struct timespec64 mtime = inode_get_mtime(inode); +loff_t new_size = lcp->lc_last_wr +1 ;struct iattr iattr = { .ia_valid =0 };int error;if (lcp->lc_mtime.tv_nsec ==UTIME_NOW || -timespec64_compare (&lcp->lc_mtime, &inode->i_mtime) <0 ) +timespec64_compare (&lcp->lc_mtime, &mtime) <0 ) lcp->lc_mtime =current_time (inode); iattr.ia_valid |=ATTR_ATIME |ATTR_CTIME |ATTR_MTIME ; iattr.ia_atime = iattr.ia_ctime = iattr.ia_mtime = lcp->lc_mtime;fs/nfsd/nfs3proc.c +2
-2@@ -294,8 +294,8 @@ nfsd3_create_file(struct svc_rqst *rqstp, structsvc_fh *fhp, status = nfserr_exist;break ;case NFS3_CREATE_EXCLUSIVE : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) {break ;fs/nfsd/nfs3proc.c +0
-0}fs/nfsd/nfs4proc.c +2
-2@@ -322,8 +322,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, structsvc_fh *fhp, status = nfserr_exist;break ;case NFS4_CREATE_EXCLUSIVE : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) { open->op_created = true;fs/nfsd/nfs4proc.c +2
-2break ;/* subtle */ @@ -331,8 +331,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, structsvc_fh *fhp, status = nfserr_exist;break ;case NFS4_CREATE_EXCLUSIVE4_1 : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) { open->op_created = true;fs/nfsd/nfs4proc.c +0
-0goto set_attr;/* subtle */ fs/nfsd/nfsctl.c +1
-1@@ -1140,7 +1140,7 @@ static struct inode *nfsd_get_inode(struct super_block *sb, umode_t mode)/* Following advice from simple_fill_super documentation: */ inode->i_ino = iunique(sb, NFSD_MaxReserved); inode->i_mode = mode; - inode->i_atime = inode->i_mtime =inode_set_ctime_current (inode); +simple_inode_init_ts (inode);switch (mode &S_IFMT ) {case S_IFDIR :fs/nfsd/nfsctl.c +0
-0inode->i_fop = &simple_dir_operations;fs/nfsd/vfs.c +1
-1@@ -521,7 +521,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime (inode).tv_sec) +if (check_guard && guardtime !=inode_get_ctime_sec (inode))return nfserr_notsync;/*
Signature · 1 line
2.52.0
Signature · 1 line
Chuck Lever
Greg Kroah-Hartman
maintainerRe: [PATCH 6.6.y v2 1/4] nfsd: convert to new timestamp accessors
In reply to Chuck LeverQuoted 11 lines · Chuck Lever
From: Jeff Layton <[email protected]>
[ Upstream commit
11fec9b9fb04fd1b3330a3b91ab9dcfa81ad5ad3]Convert to using the new inode timestamp accessor functions.
Signed-off-by Jeff Layton <[email protected]>Stable-dep-of:
24d92de9186e("nfsd: Fix NFSv3 atomicity bugs innfsd_setattr()")Signed-off-by Christian Brauner <[email protected]>Signed-off-by Chuck Lever <[email protected]>
Quoted 7 lines
--- fs/nfsd/blocklayout.c | 4 +++- fs/nfsd/nfs3proc.c | 4 ++-- fs/nfsd/nfs4proc.c | 8 ++++---- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/vfs.c | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-)
Adds a build warning, which breaks the build:
fs/nfsd/blocklayout.c: In function ‘nfsd4_block_commit_blocks’:fs/nfsd/blocklayout.c:123:16: error: unused variable ‘new_size’ [-Werror=unused-variable]
123 | loff_t new_size = lcp->lc_last_wr + 1;
| ^~~~~~~~cc1: all warnings being treated as errors
try a 3rd version?
thanks,
greg k-h
Chuck Lever
maintainerRe: [PATCH 6.6.y v2 1/4] nfsd: convert to new timestamp accessors
Quoted 27 lines · Greg Kroah-Hartman
Quoted 11 lines · Chuck Lever
From: Jeff Layton <[email protected]>
[ Upstream commit
11fec9b9fb04fd1b3330a3b91ab9dcfa81ad5ad3]Convert to using the new inode timestamp accessor functions.
Signed-off-by Jeff Layton <[email protected]>Stable-dep-of:
24d92de9186e("nfsd: Fix NFSv3 atomicity bugs innfsd_setattr()")Signed-off-by Christian Brauner <[email protected]>Signed-off-by Chuck Lever <[email protected]>Quoted 7 lines
--- fs/nfsd/blocklayout.c | 4 +++- fs/nfsd/nfs3proc.c | 4 ++-- fs/nfsd/nfs4proc.c | 8 ++++---- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/vfs.c | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-)Adds a build warning, which breaks the build:
fs/nfsd/blocklayout.c: In function ‘nfsd4_block_commit_blocks’:fs/nfsd/blocklayout.c:123:16: error: unused variable ‘new_size’ [-Werror=unused-variable]123 | loff_t new_size = lcp->lc_last_wr + 1; | ^~~~~~~~
Quoted 7 lines
cc1: all warnings being treated as errors
try a 3rd version?
thanks,
greg k-h
Harumph. I didn't see any warnings before I posted yesterday.
/me trudges back to his drawing board.
Signature · 1 line
Chuck Lever
Chuck Lever
maintainerPATCH v2 2/4 nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
In reply to [email protected]From: Trond Myklebust <[email protected]>
[ Upstream commit 24d92de9186ebc340687caf7356e1070773e67bc ]
nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
The main point of the guarded SETATTR is to prevent races with other WRITE and SETATTR calls. That requires that the check of the guard time against the inode ctime be done after taking the inode lock.
Furthermore, we need to take into account the 32-bit nature of timestamps in NFSv3, and the possibility that files may change at a faster rate than once a second.
Stable-dep-of: 442d27ff09a2 ("nfsd: set security label during create operations")
--- fs/nfsd/nfs3proc.c | 6 ++++-- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 3 +-- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 20 +++++++++++++------- fs/nfsd/vfs.h | 2 +- fs/nfsd/xdr3.h | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-)
fs/nfsd/nfs3proc.c +4 -2
@@ -71,13 +71,15 @@ nfsd3_proc_setattr(struct svc_rqst *rqstp)struct nfsd_attrs attrs = { .na_iattr = &argp->attrs, }; +const struct timespec64 *guardtime =NULL ;dprintk ("nfsd: SETATTR(3) %s\n" ,SVCFH_fmt (&argp->fh));fh_copy (&resp->fh, &argp->fh); - resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, - argp->check_guard, argp->guardtime); +if (argp->check_guard) + guardtime = &argp->guardtime; + resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, guardtime);return rpc_success; }
fs/nfsd/nfs3xdr.c +1 -4
@@ -295,17 +295,14 @@ svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,static bool svcxdr_decode_sattrguard3 (struct xdr_stream *xdr,struct nfsd3_sattrargs *args) { -__be32 *p;u32 check;if (xdr_stream_decode_bool (xdr, &check) <0 )return false;if (check) { - p =xdr_inline_decode (xdr,XDR_UNIT *2 ); -if (!p) +if (!svcxdr_decode_nfstime3 (xdr, &args->guardtime))return false; args->check_guard =1 ; - args->guardtime =be32_to_cpup (p); }else args->check_guard =0 ;
fs/nfsd/nfs4proc.c +1 -2
@@ -1160,8 +1160,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; save_no_wcc = cstate->current_fh.fh_no_wcc; cstate->current_fh.fh_no_wcc = true; - status =nfsd_setattr (rqstp, &cstate->current_fh, &attrs, -0 , (time64_t )0 ); + status =nfsd_setattr (rqstp, &cstate->current_fh, &attrs,NULL ); cstate->current_fh.fh_no_wcc = save_no_wcc;if (!status) status =nfserrno (attrs.na_labelerr);
fs/nfsd/nfs4state.c +1 -1
@@ -5223,7 +5223,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,return 0 ;if (!(open->op_share_access &NFS4_SHARE_ACCESS_WRITE ))return nfserr_inval; -return nfsd_setattr (rqstp, fh, &attrs,0 , (time64_t )0 ); +return nfsd_setattr (rqstp, fh, &attrs,NULL ); } static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
fs/nfsd/nfsproc.c +3 -3
@@ -103,7 +103,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp) } } - resp->status =nfsd_setattr (rqstp, fhp, &attrs,0 , (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, fhp, &attrs,NULL );if (resp->status != nfs_ok) goto out;
@@ -390,8 +390,8 @@ nfsd_proc_create(struct svc_rqst *rqstp)*/ attr->ia_valid &=ATTR_SIZE ;if (attr->ia_valid) - resp->status =nfsd_setattr (rqstp, newfhp, &attrs,0 , - (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, newfhp, &attrs, +NULL ); } out_unlock:
fs/nfsd/vfs.c +13 -7
@@ -459,7 +459,6 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)* @rqstp: controlling RPC transaction * @fhp: filehandle of target * @attr: attributes to set -* @check_guard: set to 1 if guardtime is a valid timestamp * @guardtime: do not act if ctime.tv_sec does not match this timestamp * * This call may adjust the contents of @attr (in particular, this
@@ -471,8 +470,7 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)*/ __be32 nfsd_setattr (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct nfsd_attrs *attr, -int check_guard,time64_t guardtime) +struct nfsd_attrs *attr,const struct timespec64 *guardtime) {struct dentry *dentry;struct inode *inode;
@@ -521,9 +519,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime_sec (inode)) -return nfserr_notsync; -/* * The size case is special, it changes the file in addition to the * attributes, and file systems don't expect it to be mixed with
@@ -541,6 +536,16 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, err =fh_fill_pre_attrs (fhp);if (err) goto out_unlock; + +if (guardtime) { +struct timespec64 ctime =inode_get_ctime (inode); +if ((u32 )guardtime->tv_sec != (u32 )ctime.tv_sec || + guardtime->tv_nsec != ctime.tv_nsec) { + err = nfserr_notsync; + goto out_fill_attrs; + } + } +for (retries =1 ;;) {struct iattr attrs;
@@ -568,6 +573,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, attr->na_aclerr =set_posix_acl (&nop_mnt_idmap, dentry,ACL_TYPE_DEFAULT , attr->na_dpacl); +out_fill_attrs:fh_fill_post_attrs (fhp); out_unlock:inode_unlock (inode);
@@ -1374,7 +1380,7 @@ nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,* if the attributes have not changed. */ if (iap->ia_valid) - status =nfsd_setattr (rqstp, resfhp, attrs,0 , (time64_t )0 ); + status =nfsd_setattr (rqstp, resfhp, attrs,NULL );else status =nfserrno (commit_metadata (resfhp));
fs/nfsd/vfs.h +1 -1
@@ -69,7 +69,7 @@ __be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *, const char *, unsigned int, struct svc_export **, struct dentry **);__be32 nfsd_setattr (struct svc_rqst *,struct svc_fh *, -struct nfsd_attrs *,int ,time64_t ); +struct nfsd_attrs *,const struct timespec64 *);int nfsd_mountpoint (struct dentry *,struct svc_export *);#ifdef CONFIG_NFSD_V4 __be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
fs/nfsd/xdr3.h +1 -1
@@ -14,7 +14,7 @@ struct nfsd3_sattrargs {struct svc_fh fh;struct iattr attrs;int check_guard; -time64_t guardtime; +struct timespec64 guardtime; };struct nfsd3_diropargs {
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 3/4 nfsd: set security label during create operations
In reply to [email protected]From: Stephen Smalley <[email protected]>
[ Upstream commit 442d27ff09a218b61020ab56387dbc508ad6bfa6 ]
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.
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 better for SELinux and a similar approach has been used previously (see security_dentry_create_files_as) but perhaps not usable by other LSMs.
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=$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=4.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
Expected output:
<eliding noise from commands run prior to or after the test itself> 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
Actual output:
<eliding noise from commands run prior to or after the test itself> 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
Stable-dep-of: 913f7cf77bf1 ("NFSD: NFSv4 file creation neglects setting ACL")
--- fs/nfsd/vfs.c | 2 +- fs/nfsd/vfs.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
fs/nfsd/vfs.c +1 -1
@@ -1379,7 +1379,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 =nfsd_setattr (rqstp, resfhp, attrs,NULL );else status =nfserrno (commit_metadata (resfhp));
fs/nfsd/vfs.h +8 -0
@@ -60,6 +60,14 @@ static inline void nfsd_attrs_free(struct nfsd_attrs *attrs)posix_acl_release (attrs->na_dpacl); } +static inline bool nfsd_attrs_valid (struct nfsd_attrs *attrs) +{ +struct iattr *iap = 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);
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 4/4 NFSD: NFSv4 file creation neglects setting ACL
In reply to [email protected]From: Chuck Lever <[email protected]>
[ Upstream commit 913f7cf77bf14c13cfea70e89bcb6d0b22239562 ]
An NFSv4 client that sets an ACL with a named principal during file creation retrieves the ACL afterwards, and finds that it is only a default ACL (based on the mode bits) and not the ACL that was requested during file creation. This violates RFC 8881 section 6.4.1.3: "the ACL attribute is set as given".
The issue occurs in nfsd_create_setattr(), which calls nfsd_attrs_valid() to determine whether to call nfsd_setattr(). However, nfsd_attrs_valid() checks only for iattr changes and security labels, but not POSIX ACLs. When only an ACL is present, the function returns false, nfsd_setattr() is skipped, and the POSIX ACL is never applied to the inode.
Subsequently, when the client retrieves the ACL, the server finds no POSIX ACL on the inode and returns one generated from the file's mode bits rather than returning the originally-specified ACL.
--- fs/nfsd/vfs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/vfs.h +2 -1
@@ -65,7 +65,8 @@ static inline bool nfsd_attrs_valid(struct nfsd_attrs *attrs)struct iattr *iap = attrs->na_iattr;return (iap->ia_valid || (attrs->na_seclabel && - attrs->na_seclabel->len)); + attrs->na_seclabel->len) || + attrs->na_pacl || attrs->na_dpacl); }__be32 nfserrno (int errno);
Signature · 1 line
2.52.0
Chuck Lever
maintainerv3 cover NFSD: NFSv4 file creation neglects setting ACL
In reply to [email protected]From: Chuck Lever <[email protected]>
I received an automated report that patch "NFSD: NFSv4 file creation neglects setting ACL" failed to apply to the 6.6-stable tree. This series is my attempt to address that failure.
- First, applied several pre-requisite patches
- LLM agent review for possible regressions reported no issues
- CI testing reported no regressions
Changes since v2:
- Add a Signed-off-by to 1/4
- Address a build warning introduced in 1/4
- Fix the In-Reply-To header
Changes since v1:
- Replace 1/4 with the upstreamed version of that commit
Chuck Lever (1):
NFSD: NFSv4 file creation neglects setting ACL
Jeff Layton (1):
nfsd: convert to new timestamp accessors
Stephen Smalley (1):
nfsd: set security label during create operations
Trond Myklebust (1):
nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
fs/nfsd/blocklayout.c | 3 ++- fs/nfsd/nfs3proc.c | 10 ++++++---- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 11 +++++------ fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 22 ++++++++++++++-------- fs/nfsd/vfs.h | 11 ++++++++++- fs/nfsd/xdr3.h | 2 +- 10 files changed, 44 insertions(+), 30 deletions(-)
Signature · 1 line
2.52.0
Greg Kroah-Hartman
maintainerRe: [PATCH 6.6.y v3 0/4] NFSD: NFSv4 file creation neglects setting ACL
Quoted 10 lines · Chuck Lever
From: Chuck Lever <[email protected]>
I received an automated report that patch "NFSD: NFSv4 file creation neglects setting ACL" failed to apply to the 6.6-stable tree. This series is my attempt to address that failure.
- First, applied several pre-requisite patches
- LLM agent review for possible regressions reported no issues
- CI testing reported no regressions
Quoted 7 lines
Changes since v2:
- Add a Signed-off-by to 1/4
- Address a build warning introduced in 1/4
- Fix the In-Reply-To headerChanges since v1:
- Replace 1/4 with the upstreamed version of that commit
Nice, this worked, thanks!
greg k-h
Chuck Lever
maintainerPATCH v3 1/4 nfsd: convert to new timestamp accessors
In reply to [email protected]From: Jeff Layton <[email protected]>
[ Upstream commit 11fec9b9fb04fd1b3330a3b91ab9dcfa81ad5ad3 ]
Convert to using the new inode timestamp accessor functions.
Stable-dep-of: 24d92de9186e ("nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()")
--- fs/nfsd/blocklayout.c | 3 ++- fs/nfsd/nfs3proc.c | 4 ++-- fs/nfsd/nfs4proc.c | 8 ++++---- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/vfs.c | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-)
fs/nfsd/blocklayout.c +2 -1
@@ -117,11 +117,12 @@ static __be32 nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp, struct iomap *iomaps, int nr_iomaps) { + struct timespec64 mtime = inode_get_mtime(inode);struct iattr iattr = { .ia_valid =0 };int error;if (lcp->lc_mtime.tv_nsec ==UTIME_NOW || -timespec64_compare (&lcp->lc_mtime, &inode->i_mtime) <0 ) +timespec64_compare (&lcp->lc_mtime, &mtime) <0 ) lcp->lc_mtime =current_time (inode); iattr.ia_valid |=ATTR_ATIME |ATTR_CTIME |ATTR_MTIME ; iattr.ia_atime = iattr.ia_ctime = iattr.ia_mtime = lcp->lc_mtime;
fs/nfsd/nfs3proc.c +2 -2
@@ -294,8 +294,8 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS3_CREATE_EXCLUSIVE : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) {break ; }
fs/nfsd/nfs4proc.c +4 -4
@@ -322,8 +322,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS4_CREATE_EXCLUSIVE : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) { open->op_created = true;break ;/* subtle */
@@ -331,8 +331,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS4_CREATE_EXCLUSIVE4_1 : -if (d_inode (child)->i_mtime.tv_sec == v_mtime && -d_inode (child)->i_atime.tv_sec == v_atime && +if (inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) { open->op_created = true; goto set_attr;/* subtle */
fs/nfsd/nfsctl.c +1 -1
@@ -1140,7 +1140,7 @@ static struct inode *nfsd_get_inode(struct super_block *sb, umode_t mode)/* Following advice from simple_fill_super documentation: */ inode->i_ino =iunique (sb, NFSD_MaxReserved); inode->i_mode = mode; - inode->i_atime = inode->i_mtime =inode_set_ctime_current (inode); +simple_inode_init_ts (inode);switch (mode &S_IFMT ) {case S_IFDIR : inode->i_fop = &simple_dir_operations;
fs/nfsd/vfs.c +1 -1
@@ -521,7 +521,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime (inode).tv_sec) +if (check_guard && guardtime !=inode_get_ctime_sec (inode))return nfserr_notsync;/*
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v3 2/4 nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
In reply to [email protected]From: Trond Myklebust <[email protected]>
[ Upstream commit 24d92de9186ebc340687caf7356e1070773e67bc ]
nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
The main point of the guarded SETATTR is to prevent races with other WRITE and SETATTR calls. That requires that the check of the guard time against the inode ctime be done after taking the inode lock.
Furthermore, we need to take into account the 32-bit nature of timestamps in NFSv3, and the possibility that files may change at a faster rate than once a second.
Stable-dep-of: 442d27ff09a2 ("nfsd: set security label during create operations")
--- fs/nfsd/nfs3proc.c | 6 ++++-- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 3 +-- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 20 +++++++++++++------- fs/nfsd/vfs.h | 2 +- fs/nfsd/xdr3.h | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-)
fs/nfsd/nfs3proc.c +4 -2
@@ -71,13 +71,15 @@ nfsd3_proc_setattr(struct svc_rqst *rqstp)struct nfsd_attrs attrs = { .na_iattr = &argp->attrs, }; +const struct timespec64 *guardtime =NULL ;dprintk ("nfsd: SETATTR(3) %s\n" ,SVCFH_fmt (&argp->fh));fh_copy (&resp->fh, &argp->fh); - resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, - argp->check_guard, argp->guardtime); +if (argp->check_guard) + guardtime = &argp->guardtime; + resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, guardtime);return rpc_success; }
fs/nfsd/nfs3xdr.c +1 -4
@@ -295,17 +295,14 @@ svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,static bool svcxdr_decode_sattrguard3 (struct xdr_stream *xdr,struct nfsd3_sattrargs *args) { -__be32 *p;u32 check;if (xdr_stream_decode_bool (xdr, &check) <0 )return false;if (check) { - p =xdr_inline_decode (xdr,XDR_UNIT *2 ); -if (!p) +if (!svcxdr_decode_nfstime3 (xdr, &args->guardtime))return false; args->check_guard =1 ; - args->guardtime =be32_to_cpup (p); }else args->check_guard =0 ;
fs/nfsd/nfs4proc.c +1 -2
@@ -1160,8 +1160,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; save_no_wcc = cstate->current_fh.fh_no_wcc; cstate->current_fh.fh_no_wcc = true; - status =nfsd_setattr (rqstp, &cstate->current_fh, &attrs, -0 , (time64_t )0 ); + status =nfsd_setattr (rqstp, &cstate->current_fh, &attrs,NULL ); cstate->current_fh.fh_no_wcc = save_no_wcc;if (!status) status =nfserrno (attrs.na_labelerr);
fs/nfsd/nfs4state.c +1 -1
@@ -5223,7 +5223,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,return 0 ;if (!(open->op_share_access &NFS4_SHARE_ACCESS_WRITE ))return nfserr_inval; -return nfsd_setattr (rqstp, fh, &attrs,0 , (time64_t )0 ); +return nfsd_setattr (rqstp, fh, &attrs,NULL ); } static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
fs/nfsd/nfsproc.c +3 -3
@@ -103,7 +103,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp) } } - resp->status =nfsd_setattr (rqstp, fhp, &attrs,0 , (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, fhp, &attrs,NULL );if (resp->status != nfs_ok) goto out;
@@ -390,8 +390,8 @@ nfsd_proc_create(struct svc_rqst *rqstp)*/ attr->ia_valid &=ATTR_SIZE ;if (attr->ia_valid) - resp->status =nfsd_setattr (rqstp, newfhp, &attrs,0 , - (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, newfhp, &attrs, +NULL ); } out_unlock:
fs/nfsd/vfs.c +13 -7
@@ -459,7 +459,6 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)* @rqstp: controlling RPC transaction * @fhp: filehandle of target * @attr: attributes to set -* @check_guard: set to 1 if guardtime is a valid timestamp * @guardtime: do not act if ctime.tv_sec does not match this timestamp * * This call may adjust the contents of @attr (in particular, this
@@ -471,8 +470,7 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)*/ __be32 nfsd_setattr (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct nfsd_attrs *attr, -int check_guard,time64_t guardtime) +struct nfsd_attrs *attr,const struct timespec64 *guardtime) {struct dentry *dentry;struct inode *inode;
@@ -521,9 +519,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime_sec (inode)) -return nfserr_notsync; -/* * The size case is special, it changes the file in addition to the * attributes, and file systems don't expect it to be mixed with
@@ -541,6 +536,16 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, err =fh_fill_pre_attrs (fhp);if (err) goto out_unlock; + +if (guardtime) { +struct timespec64 ctime =inode_get_ctime (inode); +if ((u32 )guardtime->tv_sec != (u32 )ctime.tv_sec || + guardtime->tv_nsec != ctime.tv_nsec) { + err = nfserr_notsync; + goto out_fill_attrs; + } + } +for (retries =1 ;;) {struct iattr attrs;
@@ -568,6 +573,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, attr->na_aclerr =set_posix_acl (&nop_mnt_idmap, dentry,ACL_TYPE_DEFAULT , attr->na_dpacl); +out_fill_attrs:fh_fill_post_attrs (fhp); out_unlock:inode_unlock (inode);
@@ -1374,7 +1380,7 @@ nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,* if the attributes have not changed. */ if (iap->ia_valid) - status =nfsd_setattr (rqstp, resfhp, attrs,0 , (time64_t )0 ); + status =nfsd_setattr (rqstp, resfhp, attrs,NULL );else status =nfserrno (commit_metadata (resfhp));
fs/nfsd/vfs.h +1 -1
@@ -69,7 +69,7 @@ __be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *, const char *, unsigned int, struct svc_export **, struct dentry **);__be32 nfsd_setattr (struct svc_rqst *,struct svc_fh *, -struct nfsd_attrs *,int ,time64_t ); +struct nfsd_attrs *,const struct timespec64 *);int nfsd_mountpoint (struct dentry *,struct svc_export *);#ifdef CONFIG_NFSD_V4 __be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
fs/nfsd/xdr3.h +1 -1
@@ -14,7 +14,7 @@ struct nfsd3_sattrargs {struct svc_fh fh;struct iattr attrs;int check_guard; -time64_t guardtime; +struct timespec64 guardtime; };struct nfsd3_diropargs {
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v3 3/4 nfsd: set security label during create operations
In reply to [email protected]From: Stephen Smalley <[email protected]>
[ Upstream commit 442d27ff09a218b61020ab56387dbc508ad6bfa6 ]
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.
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 better for SELinux and a similar approach has been used previously (see security_dentry_create_files_as) but perhaps not usable by other LSMs.
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=$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=4.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
Expected output:
<eliding noise from commands run prior to or after the test itself> 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
Actual output:
<eliding noise from commands run prior to or after the test itself> 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
Stable-dep-of: 913f7cf77bf1 ("NFSD: NFSv4 file creation neglects setting ACL")
--- fs/nfsd/vfs.c | 2 +- fs/nfsd/vfs.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
fs/nfsd/vfs.c +1 -1
@@ -1379,7 +1379,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 =nfsd_setattr (rqstp, resfhp, attrs,NULL );else status =nfserrno (commit_metadata (resfhp));
fs/nfsd/vfs.h +8 -0
@@ -60,6 +60,14 @@ static inline void nfsd_attrs_free(struct nfsd_attrs *attrs)posix_acl_release (attrs->na_dpacl); } +static inline bool nfsd_attrs_valid (struct nfsd_attrs *attrs) +{ +struct iattr *iap = 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);
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v3 4/4 NFSD: NFSv4 file creation neglects setting ACL
In reply to [email protected]From: Chuck Lever <[email protected]>
[ Upstream commit 913f7cf77bf14c13cfea70e89bcb6d0b22239562 ]
An NFSv4 client that sets an ACL with a named principal during file creation retrieves the ACL afterwards, and finds that it is only a default ACL (based on the mode bits) and not the ACL that was requested during file creation. This violates RFC 8881 section 6.4.1.3: "the ACL attribute is set as given".
The issue occurs in nfsd_create_setattr(), which calls nfsd_attrs_valid() to determine whether to call nfsd_setattr(). However, nfsd_attrs_valid() checks only for iattr changes and security labels, but not POSIX ACLs. When only an ACL is present, the function returns false, nfsd_setattr() is skipped, and the POSIX ACL is never applied to the inode.
Subsequently, when the client retrieves the ACL, the server finds no POSIX ACL on the inode and returns one generated from the file's mode bits rather than returning the originally-specified ACL.
--- fs/nfsd/vfs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/vfs.h +2 -1
@@ -65,7 +65,8 @@ static inline bool nfsd_attrs_valid(struct nfsd_attrs *attrs)struct iattr *iap = attrs->na_iattr;return (iap->ia_valid || (attrs->na_seclabel && - attrs->na_seclabel->len)); + attrs->na_seclabel->len) || + attrs->na_pacl || attrs->na_dpacl); }__be32 nfserrno (int errno);
Signature · 1 line
2.52.0