NFSv4.2: Update mode bits after ALLOCATE and DEALLOCATE
Subsystems (2)
Anna Schumaker
maintainerPATCH v2 1/1 NFSv4.2: Update mode bits after ALLOCATE and DEALLOCATE
From: Anna Schumaker <[email protected]>
The fallocate call invalidates suid and sgid bits as part of normal operation. We need to mark the mode bits as invalid when using fallocate with an suid so these will be updated the next time the user looks at them.
This fixes xfstests generic/683 and generic/684.
--- fs/nfs/internal.h | 25 +++++++++++++++++++++++++ fs/nfs/nfs42proc.c | 13 ++++++++++++- fs/nfs/write.c | 25 ------------------------- 3 files changed, 37 insertions(+), 26 deletions(-)
fs/nfs/internal.h +25 -0
@@ -606,6 +606,31 @@ static inline gfp_t nfs_io_gfp_mask(void)return GFP_KERNEL ; } +/* +* Special version of should_remove_suid() that ignores capabilities. +*/ +static inline int nfs_should_remove_suid (const struct inode *inode) +{ +umode_t mode = inode->i_mode; +int kill =0 ; + +/* suid always must be killed */ +if (unlikely (mode &S_ISUID )) + kill =ATTR_KILL_SUID ; + +/* +* sgid without any exec bits is just a mandatory locking mark; leave +* it alone. If some exec bits are set, it's a real sgid; kill it. +*/ +if (unlikely ((mode &S_ISGID ) && (mode &S_IXGRP ))) + kill |=ATTR_KILL_SGID ; + +if (unlikely (kill &&S_ISREG (mode))) +return kill; + +return 0 ; +} +/* unlink.c */ extern struct rpc_task * nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
fs/nfs/nfs42proc.c +12 -1
@@ -56,6 +56,7 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,struct nfs42_falloc_res res = { .falloc_server = server, }; +unsigned int invalid =0 ;int status; msg->rpc_argp = &args;
@@ -78,10 +79,20 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, status =nfs4_call_sync (server->client, server, msg, &args.seq_args, &res.seq_res,0 ); + +if (!res.falloc_fattr->valid) + invalid |=NFS_INO_INVALID_ATTR ; +if (nfs_should_remove_suid (inode)) + invalid |=NFS_INO_INVALID_MODE ; +if (invalid) { +spin_lock (&inode->i_lock); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_MODE ); +spin_unlock (&inode->i_lock); + } +if (status ==0 ) status =nfs_post_op_update_inode_force_wcc (inode, res.falloc_fattr); -if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE ])trace_nfs4_fallocate (inode, &args, status);else
fs/nfs/write.c +0 -25
@@ -1496,31 +1496,6 @@ void nfs_commit_prepare(struct rpc_task *task, void *calldata)NFS_PROTO (data->inode)->commit_rpc_prepare (task, data); } -/* -* Special version of should_remove_suid() that ignores capabilities. -*/ -static int nfs_should_remove_suid (const struct inode *inode) -{ -umode_t mode = inode->i_mode; -int kill =0 ; - -/* suid always must be killed */ -if (unlikely (mode &S_ISUID )) - kill =ATTR_KILL_SUID ; - -/* -* sgid without any exec bits is just a mandatory locking mark; leave -* it alone. If some exec bits are set, it's a real sgid; kill it. -*/ -if (unlikely ((mode &S_ISGID ) && (mode &S_IXGRP ))) - kill |=ATTR_KILL_SGID ; - -if (unlikely (kill &&S_ISREG (mode))) -return kill; - -return 0 ; -} -static void nfs_writeback_check_extend (struct nfs_pgio_header *hdr,struct nfs_fattr *fattr) {
Signature · 1 line
2.37.2
Quoted 79 lines · Anna Schumaker
From: Anna Schumaker <[email protected]>
The fallocate call invalidates suid and sgid bits as part of normal operation. We need to mark the mode bits as invalid when using fallocate
with an suid so these will be updated the next time the user looks at them.This fixes xfstests generic/683 and generic/684.
Reported-by Yue Cui <[email protected]>Fixes 913eca1aea87 ("NFS: Fallocate should use the
nfs4_fattr_bitmap")Signed-off-by Anna Schumaker <[email protected]>---
fs/nfs/internal.h | 25 +++++++++++++++++++++++++fs/nfs/nfs42proc.c| 13 ++++++++++++- fs/nfs/write.c | 25 -------------------------3 files changed, 37 insertions(+), 26 deletions(-)fs/nfs/internal.h +0
-0@@ -606,6 +606,31 @@ static inline gfp_t nfs_io_gfp_mask(void) return GFP_KERNEL; }
+/*
+ * Special version ofshould_remove_suid()that ignores capabilities.
+ */fs/nfs/internal.h +11
-0+static inline int nfs_should_remove_suid (const struct inode *inode) +{ + umode_t mode = inode->i_mode; + int kill = 0; + + /* suid always must be killed */ + if (unlikely(mode & S_ISUID)) + kill = ATTR_KILL_SUID; + + /* +* sgid without any exec bits is just a mandatory locking mark; leave
+ * it alone. If some exec bits are set, it's a real sgid; kill it.
+ */
+ if (unlikely((mode & S_ISGID) && (mode & S_IXGRP))) + kill |=ATTR_KILL_SGID;fs/nfs/internal.h +7
-0+ + if (unlikely(kill && S_ISREG(mode))) + return kill; + + return 0; +} +/*
unlink.c*/
extern structrpc_task*
nfs_async_rename(struct inode*old_dir, struct inode*new_dir,fs/nfs/nfs42proc.c +1
-0@@ -56,6 +56,7 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, struct nfs42_falloc_res res = { .falloc_server = server, }; + unsigned int invalid = 0; int status;
msg->rpc_argp = &args;fs/nfs/nfs42proc.c +0
-0@@ -78,10 +79,20 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
status =nfs4_call_sync(server->client, server, msg, &args.seq_args, &res.seq_res, 0); +
+ if (!res.falloc_fattr->valid)
Quoted 8 lines
+ invalid |=
NFS_INO_INVALID_ATTR;
+ if (nfs_should_remove_suid(inode))
+ invalid |=NFS_INO_INVALID_MODE;
+ if (invalid) {
+ spin_lock(&inode->i_lock);
+ nfs_set_cache_invalid(inode,NFS_INO_INVALID_MODE); + spin_unlock(&inode->i_lock);
+ }
This all really wants to go into the 'if (status == 0)' below.
Quoted 47 lines
+
if (status == 0)
status = nfs_post_op_update_inode_force_wcc(inode,
res.falloc_fattr);
-
if (msg->rpc_proc== &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE])trace_nfs4_fallocate(inode, &args, status); elsefs/nfs/write.c +0
-0@@ -1496,31 +1496,6 @@ void nfs_commit_prepare(struct rpc_task *task, void *calldata) NFS_PROTO(data->inode)->commit_rpc_prepare(task, data); }
-/*
- * Special version ofshould_remove_suid()that ignores capabilities.
- */fs/nfs/write.c +0
-11-static int nfs_should_remove_suid (const struct inode *inode) -{ - umode_t mode = inode->i_mode; - int kill = 0; - - /* suid always must be killed */ - if (unlikely(mode & S_ISUID)) - kill = ATTR_KILL_SUID; - - /* -* sgid without any exec bits is just a mandatory locking mark; leave
- * it alone. If some exec bits are set, it's a real sgid; kill it.
- */
- if (unlikely((mode & S_ISGID) && (mode & S_IXGRP))) - kill |=ATTR_KILL_SGID;fs/nfs/write.c +0
-7- - if (unlikely(kill && S_ISREG(mode))) - return kill; - - return 0; -} -
Quoted 3 lines
static void
nfs_writeback_check_extend(struct nfs_pgio_header *hdr, struct nfs_fattr *fattr)
{
Otherwise, looks OK.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 76 lines · Trond Myklebust
Quoted 75 lines · Anna Schumaker
From: Anna Schumaker <[email protected]>
The fallocate call invalidates suid and sgid bits as part of normal operation. We need to mark the mode bits as invalid when using fallocate
with an suid so these will be updated the next time the user looks at
them.This fixes xfstests generic/683 and generic/684.
Reported-by Yue Cui <[email protected]>Fixes 913eca1aea87 ("NFS: Fallocate should use the
nfs4_fattr_bitmap")Signed-off-by Anna Schumaker <[email protected]>---
fs/nfs/internal.h | 25 +++++++++++++++++++++++++fs/nfs/nfs42proc.c| 13 ++++++++++++- fs/nfs/write.c | 25 -------------------------3 files changed, 37 insertions(+), 26 deletions(-)fs/nfs/internal.h +0
-0@@ -606,6 +606,31 @@ static inline gfp_t nfs_io_gfp_mask(void) return GFP_KERNEL; }
+/*
+ * Special version ofshould_remove_suid()that ignores capabilities.
+ */
+static inline intnfs_should_remove_suid(const struct inode *inode)fs/nfs/internal.h +10
-0+{ + umode_t mode = inode->i_mode; + int kill = 0; + + /* suid always must be killed */ + if (unlikely(mode & S_ISUID)) + kill = ATTR_KILL_SUID; + + /* +* sgid without any exec bits is just a mandatory locking mark; leave
+ * it alone. If some exec bits are set, it's a real sgid; kill it.
+ */
+ if (unlikely((mode & S_ISGID) && (mode & S_IXGRP))) + kill |=ATTR_KILL_SGID;fs/nfs/internal.h +7
-0+ + if (unlikely(kill && S_ISREG(mode))) + return kill; + + return 0; +} +/*
unlink.c*/
extern structrpc_task*
nfs_async_rename(struct inode*old_dir, struct inode*new_dir,fs/nfs/nfs42proc.c +0
-0@@ -56,6 +56,7 @@ static int _nfs42_proc_fallocate(struct
rpc_message
*msg, struct file *filep,
structnfs42_falloc_resres = {
.falloc_server = server,
};
+ unsigned int invalid = 0;
int status;
msg->rpc_argp = &args;
Quoted 8 lines
Quoted 8 lines
fs/nfs/nfs42proc.c +0
-0@@ -78,10 +79,20 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
status =nfs4_call_sync(server->client, server, msg, &args.seq_args, &res.seq_res, 0); +
+ if (!res.falloc_fattr->valid)
+ invalid |=NFS_INO_INVALID_ATTR;
Oh wait... We shouldn't need this.^^^^^^^^^ nfs_post_op_update_inode_force_wcc() will do the right thing for you here.
Quoted 64 lines
Quoted 7 lines
+ if (
nfs_should_remove_suid(inode))
+ invalid |=NFS_INO_INVALID_MODE;
+ if (invalid) {
+ spin_lock(&inode->i_lock);
+ nfs_set_cache_invalid(inode,NFS_INO_INVALID_MODE); + spin_unlock(&inode->i_lock);
+ }This all really wants to go into the 'if (status == 0)' below.
Quoted 48 lines
+
if (status == 0)
status = nfs_post_op_update_inode_force_wcc(inode,
res.falloc_fattr);
-
if (msg->rpc_proc== &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE])trace_nfs4_fallocate(inode, &args, status); elsefs/nfs/write.c +0
-0@@ -1496,31 +1496,6 @@ void nfs_commit_prepare(struct rpc_task *task, void *calldata) NFS_PROTO(data->inode)->commit_rpc_prepare(task, data); }
-/*
- * Special version ofshould_remove_suid()that ignores capabilities.
- */fs/nfs/write.c +0
-11-static int nfs_should_remove_suid (const struct inode *inode) -{ - umode_t mode = inode->i_mode; - int kill = 0; - - /* suid always must be killed */ - if (unlikely(mode & S_ISUID)) - kill = ATTR_KILL_SUID; - - /* -* sgid without any exec bits is just a mandatory locking mark; leave
- * it alone. If some exec bits are set, it's a real sgid; kill it.
- */
- if (unlikely((mode & S_ISGID) && (mode & S_IXGRP))) - kill |=ATTR_KILL_SGID;fs/nfs/write.c +0
-7- - if (unlikely(kill && S_ISREG(mode))) - return kill; - - return 0; -} -Quoted 4 lines
static void nfs_writeback_check_extend(struct
nfs_pgio_header*hdr,
structnfs_fattr*fattr)
{Otherwise, looks OK.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Anna Schumaker
maintainerQuoted 81 lines · Trond Myklebust
Quoted 79 lines · Trond Myklebust
Quoted 78 lines · Anna Schumaker
From: Anna Schumaker <[email protected]>
The fallocate call invalidates suid and sgid bits as part of normal operation. We need to mark the mode bits as invalid when using fallocate
with an suid so these will be updated the next time the user looks at
them.This fixes xfstests generic/683 and generic/684.
Reported-by Yue Cui <[email protected]>Fixes 913eca1aea87 ("NFS: Fallocate should use the
nfs4_fattr_bitmap")Signed-off-by Anna Schumaker <[email protected]>--- fs/nfs/internal.h | 25 +++++++++++++++++++++++++ fs/nfs/nfs42proc.c | 13 ++++++++++++- fs/nfs/write.c | 25 ------------------------- 3 files changed, 37 insertions(+), 26 deletions(-)fs/nfs/internal.h +2
-0@@ -606,6 +606,31 @@ static inline gfp_t nfs_io_gfp_mask(void)return GFP_KERNEL ; } +/* +* Special version of should_remove_suid() that ignores capabilities.
+ */
+static inline intnfs_should_remove_suid(const struct inode *inode)fs/nfs/internal.h +10
-0+{ +umode_t mode = inode->i_mode; +int kill =0 ; + +/* suid always must be killed */ +if (unlikely (mode &S_ISUID )) + kill =ATTR_KILL_SUID ; + +/* +* sgid without any exec bits is just a mandatory locking mark; leave
+ * it alone. If some exec bits are set, it's a real sgid;
kill it.fs/nfs/internal.h +10
-0+*/ +if (unlikely ((mode &S_ISGID ) && (mode &S_IXGRP ))) + kill |=ATTR_KILL_SGID ; + +if (unlikely (kill &&S_ISREG (mode))) +return kill; + +return 0 ; +} +/* unlink.c */ extern struct rpc_task * nfs_async_rename(struct inode *old_dir, struct inode *new_dir,fs/nfs/nfs42proc.c +0
-0@@ -56,6 +56,7 @@ static int _nfs42_proc_fallocate(struct
rpc_message
*msg, struct file *filep,struct nfs42_falloc_res res = { .falloc_server = server, };fs/nfs/nfs42proc.c +1
-0+unsigned int invalid =0 ;int status; msg->rpc_argp = &args;@@ -78,10 +79,20 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
Quoted 9 lines
Quoted 5 lines
fs/nfs/nfs42proc.c static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, · line 84
Quoted 5 lines
fs/nfs/nfs42proc.c +3
-0status =nfs4_call_sync (server->client, server, msg, &args.seq_args, &res.seq_res,0 ); + +if (!res.falloc_fattr->valid) + invalid |=NFS_INO_INVALID_ATTR ;Oh wait... We shouldn't need this.^^^^^^^^^
nfs_post_op_update_inode_force_wcc()will do the right thing for you here.
Sure. I can remove that and put everything under the "if (status == 0)".
Anna
Quoted 72 lines
Quoted 56 lines
fs/nfs/nfs42proc.c static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, · line 91
Quoted 8 lines
fs/nfs/nfs42proc.c +7
-0+if (nfs_should_remove_suid (inode)) + invalid |=NFS_INO_INVALID_MODE ; +if (invalid) { +spin_lock (&inode->i_lock); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_MODE ); +spin_unlock (&inode->i_lock); + }This all really wants to go into the 'if (status == 0)' below.
Quoted 46 lines
fs/nfs/nfs42proc.c +1
-1+if (status ==0 ) status =nfs_post_op_update_inode_force_wcc (inode, res.falloc_fattr); - if (msg->rpc_proc ==&nfs4_procedures[NFSPROC4_CLNT_ALLOCATE])
trace_nfs4_fallocate(inode, &args, status); elsefs/nfs/write.c +0
-2@@ -1496,31 +1496,6 @@ void nfs_commit_prepare(struct rpc_task *task, void *calldata)NFS_PROTO (data->inode)->commit_rpc_prepare (task, data); } -/* -* Special version of should_remove_suid() that ignores capabilities.
- */fs/nfs/write.c +0
-11-static int nfs_should_remove_suid (const struct inode *inode) -{ -umode_t mode = inode->i_mode; -int kill =0 ; - -/* suid always must be killed */ -if (unlikely (mode &S_ISUID )) - kill =ATTR_KILL_SUID ; - -/* -* sgid without any exec bits is just a mandatory locking mark; leave
- * it alone. If some exec bits are set, it's a real sgid;
kill it.fs/nfs/write.c +0
-8-*/ -if (unlikely ((mode &S_ISGID ) && (mode &S_IXGRP ))) - kill |=ATTR_KILL_SGID ; - -if (unlikely (kill &&S_ISREG (mode))) -return kill; - -return 0 ;Quoted 9 lines
Quoted 6 lines
fs/nfs/write.c +0
-2-} - static void nfs_writeback_check_extend(struct nfs_pgio_header*hdr,
structnfs_fattr*fattr)
{Otherwise, looks OK.
--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]