nfsd: Fix possible BUG_ON firing in set_change_info
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 3 lines · Neil Brown
If
vfs_getattrinfill_post_wccreturns an error, we don't setfh_post_change.
^^^ Did you mean fh_post_saved?
Quoted 9 lines
For NFSv4, this can result in
set_change_infotriggering aBUG_ON. i.e.fh_post_savedbeing zero isn't really a bug.So:
- instead of BUGging whenfh_post_savedis zero, just clear ->atomic.
- ifvfs_getattrfails infill_post_wcc, take a copy ofi_ctimeanyway. This will be used iseg_change_info, but not overly trusted.
- While we are there, remove the pointless 'if' statements inset_change_info. There is no harm setting all the values.
The 'if' statement was introduced when ext4 i_version support was added via commit c654b8a9. While there is no harm setting all the values, it may not really be required.
Quoted 1 line
From the spec:
"For a client to use the change_info4 information
appropriately and correctly, the server must report the pre- and post-operation change attribute values atomically. When the server is unable to report the before and after values atomically with respect to the directory operation, the server must indicate that fact in the change_info4 return value. When the information is not atomically reported, the client should not assume that other clients have not changed the directory."
Though the spec doesn't talk about the case we have specifically, it appears to me that the proposed behavior is the best we could aim for.
Quoted 60 lines
Signed-off-by NeilBrown <[email protected]>--
If you think the code is clearer with the
if()structure, feel free to leave that part unchanged.NeilBrown
fs/nfsd/nfs3xdr.c +4
-2@@ -260,9 +260,11 @@ void fill_post_wcc(struct svc_fh *fhp) err =vfs_getattr (fhp->fh_export->ex_path.mnt, fhp->fh_dentry, &fhp->fh_post_attr); fhp->fh_post_change = fhp->fh_dentry->d_inode->i_version; -if (err) +if (err) { fhp->fh_post_saved =0 ; -else +/* Grab the ctime anyway - set_change_info might use it */ + fhp->fh_post_attr.ctime = fhp->fh_dentry->d_inode->i_ctime; + }else fhp->fh_post_saved =1 ; }fs/nfsd/xdr4.h +10
-11@@ -484,18 +484,17 @@ static inline bool nfsd4_not_cached(struct nfsd4_compoundres *resp)static inline void set_change_info (struct nfsd4_change_info *cinfo,struct svc_fh *fhp) { -BUG_ON (!fhp->fh_pre_saved || !fhp->fh_post_saved); - cinfo->atomic =1 ; +BUG_ON (!fhp->fh_pre_saved); + cinfo->atomic = fhp->fh_post_saved; cinfo->change_supported =IS_I_VERSION (fhp->fh_dentry->d_inode); -if (cinfo->change_supported) { - cinfo->before_change = fhp->fh_pre_change; - cinfo->after_change = fhp->fh_post_change; - }else { - cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec; - cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec; - cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec; - cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec; - } + + cinfo->before_change = fhp->fh_pre_change; + cinfo->after_change = fhp->fh_post_change; + cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec; + cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec; + cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec; + cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec; + }int nfs4svc_encode_voidres (struct svc_rqst *,__be32 *,void *);
Signature · 1 line
Suresh Jayaraman
Quoted 16 lines · Suresh Jayaraman
Quoted 3 lines · Neil Brown
If
vfs_getattrinfill_post_wccreturns an error, we don't setfh_post_change.^^^ Did you mean
fh_post_saved?Quoted 9 lines
For NFSv4, this can result in
set_change_infotriggering aBUG_ON. i.e.fh_post_savedbeing zero isn't really a bug.So:
- instead of BUGging whenfh_post_savedis zero, just clear ->atomic.
- ifvfs_getattrfails infill_post_wcc, take a copy ofi_ctimeanyway. This will be used iseg_change_info, but not overly trusted.
- While we are there, remove the pointless 'if' statements inset_change_info. There is no harm setting all the values.
Quoted 3 lines
The 'if' statement was introduced when ext4
i_versionsupport was added via commitc654b8a9. While there is no harm setting all the values, it may not really be required.
If you mean that you interpret the spec as allowing us to return garbage changeattr values in the non-atomic case, no, I don't agree.
It's true that a client that tries to use them must be aware of the potential pitfalls, but not true that we therefore have license to return inaccurate post-op attributes.
--b.
Quoted 79 lines
Quoted 2 lines
From the spec:
"For a client to use the
change_info4information
appropriately and correctly, the server must report the pre- and post-operation change attribute values atomically. When the server is unable to report the before and after values atomically with respect to the directory operation, the server must indicate that fact in thechange_info4return value. When the information is not atomically reported, the client should not assume that other clients have not changed the directory."Though the spec doesn't talk about the case we have specifically, it appears to me that the proposed behavior is the best we could aim for.
Quoted 60 lines
Signed-off-by NeilBrown <[email protected]>--
If you think the code is clearer with the
if()structure, feel free to leave that part unchanged.NeilBrown
fs/nfsd/nfs3xdr.c +4
-2@@ -260,9 +260,11 @@ void fill_post_wcc(struct svc_fh *fhp) err =vfs_getattr (fhp->fh_export->ex_path.mnt, fhp->fh_dentry, &fhp->fh_post_attr); fhp->fh_post_change = fhp->fh_dentry->d_inode->i_version; -if (err) +if (err) { fhp->fh_post_saved =0 ; -else +/* Grab the ctime anyway - set_change_info might use it */ + fhp->fh_post_attr.ctime = fhp->fh_dentry->d_inode->i_ctime; + }else fhp->fh_post_saved =1 ; }fs/nfsd/xdr4.h +10
-11@@ -484,18 +484,17 @@ static inline bool nfsd4_not_cached(struct nfsd4_compoundres *resp)static inline void set_change_info (struct nfsd4_change_info *cinfo,struct svc_fh *fhp) { -BUG_ON (!fhp->fh_pre_saved || !fhp->fh_post_saved); - cinfo->atomic =1 ; +BUG_ON (!fhp->fh_pre_saved); + cinfo->atomic = fhp->fh_post_saved; cinfo->change_supported =IS_I_VERSION (fhp->fh_dentry->d_inode); -if (cinfo->change_supported) { - cinfo->before_change = fhp->fh_pre_change; - cinfo->after_change = fhp->fh_post_change; - }else { - cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec; - cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec; - cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec; - cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec; - } + + cinfo->before_change = fhp->fh_pre_change; + cinfo->after_change = fhp->fh_post_change; + cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec; + cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec; + cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec; + cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec; + }int nfs4svc_encode_voidres (struct svc_rqst *,__be32 *,void *);Signature · 1 line
Suresh Jayaraman
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 27 lines · Neil Brown
If
vfs_getattrinfill_post_wccreturns an error, we don't setfh_post_change.
For NFSv4, this can result inset_change_infotriggering aBUG_ON. i.e.fh_post_savedbeing zero isn't really a bug.So:
- instead of BUGging whenfh_post_savedis zero, just clear ->atomic.
- ifvfs_getattrfails infill_post_wcc, take a copy ofi_ctimeanyway. This will be used iseg_change_info, but not overly trusted.
- While we are there, remove the pointless 'if' statements inset_change_info. There is no harm setting all the values.Signed-off-by NeilBrown <[email protected]>--
If you think the code is clearer with the
if()structure, feel free to leave that part unchanged.NeilBrown
fs/nfsd/nfs3xdr.c +0
-0
fs/nfsd/nfs3xdr.c void fill_post_wcc(struct svc_fh *fhp) · line 266
Quoted 9 lines
fs/nfsd/nfs3xdr.c +3
-2@@ -260,9 +260,11 @@ void fill_post_wcc(struct svc_fh *fhp) err =vfs_getattr (fhp->fh_export->ex_path.mnt, fhp->fh_dentry, &fhp->fh_post_attr); fhp->fh_post_change = fhp->fh_dentry->d_inode->i_version; -if (err) +if (err) { fhp->fh_post_saved =0 ; -else +/* Grab the ctime anyway - set_change_info might use it */ + fhp->fh_post_attr.ctime = fhp->fh_dentry->d_inode->i_ctime;
Perhaps, a dprintk here would help debugging?
Thanks,
Signature · 1 line
Suresh Jayaraman
Quoted 13 lines · Neil Brown
If
vfs_getattrinfill_post_wccreturns an error, we don't setfh_post_change.
For NFSv4, this can result inset_change_infotriggering aBUG_ON. i.e.fh_post_savedbeing zero isn't really a bug.So:
- instead of BUGging whenfh_post_savedis zero, just clear ->atomic.
- ifvfs_getattrfails infill_post_wcc, take a copy ofi_ctimeanyway. This will be used iseg_change_info, but not overly trusted.
- While we are there, remove the pointless 'if' statements inset_change_info. There is no harm setting all the values.
Quoted 6 lines
Signed-off-by NeilBrown <[email protected]>--
If you think the code is clearer with the
if()structure, feel free to leave that part unchanged.
Looks fine to me as-is; planning to submit for 2.6.37 and -stable unless I hear otherwise.
--b.
Quoted 54 lines
NeilBrown
fs/nfsd/nfs3xdr.c +4
-2@@ -260,9 +260,11 @@ void fill_post_wcc(struct svc_fh *fhp) err =vfs_getattr (fhp->fh_export->ex_path.mnt, fhp->fh_dentry, &fhp->fh_post_attr); fhp->fh_post_change = fhp->fh_dentry->d_inode->i_version; -if (err) +if (err) { fhp->fh_post_saved =0 ; -else +/* Grab the ctime anyway - set_change_info might use it */ + fhp->fh_post_attr.ctime = fhp->fh_dentry->d_inode->i_ctime; + }else fhp->fh_post_saved =1 ; }fs/nfsd/xdr4.h +10
-11@@ -484,18 +484,17 @@ static inline bool nfsd4_not_cached(struct nfsd4_compoundres *resp)static inline void set_change_info (struct nfsd4_change_info *cinfo,struct svc_fh *fhp) { -BUG_ON (!fhp->fh_pre_saved || !fhp->fh_post_saved); - cinfo->atomic =1 ; +BUG_ON (!fhp->fh_pre_saved); + cinfo->atomic = fhp->fh_post_saved; cinfo->change_supported =IS_I_VERSION (fhp->fh_dentry->d_inode); -if (cinfo->change_supported) { - cinfo->before_change = fhp->fh_pre_change; - cinfo->after_change = fhp->fh_post_change; - }else { - cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec; - cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec; - cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec; - cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec; - } + + cinfo->before_change = fhp->fh_pre_change; + cinfo->after_change = fhp->fh_post_change; + cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec; + cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec; + cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec; + cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec; + }int nfs4svc_encode_voidres (struct svc_rqst *,__be32 *,void *);