nfsd: make a copy of struct iattr before calling notify_change
Subsystems (2)
Jeff Layton
maintainerPATCH 1/1 nfsd: make a copy of struct iattr before calling notify_change
notify_change can modify the iattr structure. In particular it can can end up setting ATTR_MODE when ATTR_KILL_SUID is already set, causing a BUG() if the same iattr is passed to notify_change more than once.
Make a copy of the struct iattr before calling notify_change.
--- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfsd/vfs.c +3 -1
@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap; + + host_err =__nfsd_setattr (dentry, &attrs);if (host_err != -EAGAIN || !retries--)break ;if (!nfsd_wait_for_delegreturn (rqstp, inode))
Signature · 1 line
2.40.1
Quoted 23 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/vfs.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0
fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 541
Quoted 5 lines
fs/nfsd/vfs.c +1
-1@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap;
This construct always makes me queazy. I'm never sure if an initializer inside a loop is "only once" or "every time". I fixed a bug like this once.
But if you've tested it and it addresses the BUG, then let's go with this. I can apply it to nfsd-fixes.
Quoted 8 lines
fs/nfsd/vfs.c +2
-0+ + host_err =__nfsd_setattr (dentry, &attrs);if (host_err != -EAGAIN || !retries--)break ;if (!nfsd_wait_for_delegreturn (rqstp, inode))Signature · 1 line
2.40.1
--
Chuck Lever
Jeff Layton
maintainerQuoted 32 lines · Chuck Lever III
Quoted 22 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/vfs.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 541
Quoted 5 lines
fs/nfsd/vfs.c +1
-1@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap;This construct always makes me queazy. I'm never sure if an initializer inside a loop is "only once" or "every time". I fixed a bug like this once.
Quoted 3 lines
But if you've tested it and it addresses the BUG, then let's go with this. I can apply it to nfsd-fixes.
I've done some light testing with this kernel, but this was found by Zhi while testing with the lustre racer test, so it involves some raciness. I've never hit this myself.
I'm pretty sure though that this has to be initialized every time. The assignment is inside the loop, after all. I'm ok with moving the assignment to a different line if you like though:
struct iattr attrs; attrs = *iap; ...
Quoted 13 lines
Quoted 8 lines
fs/nfsd/vfs.c +2
-0+ + host_err =__nfsd_setattr (dentry, &attrs);if (host_err != -EAGAIN || !retries--)break ;if (!nfsd_wait_for_delegreturn (rqstp, inode))Signature · 1 line
2.40.1--
Chuck Lever
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 37 lines · Jeff Layton
Quoted 32 lines · Chuck Lever III
Quoted 22 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/vfs.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 541
Quoted 5 lines
fs/nfsd/vfs.c +1
-1@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap;This construct always makes me queazy. I'm never sure if an initializer inside a loop is "only once" or "every time". I fixed a bug like this once.
Quoted 8 lines
Quoted 3 lines
But if you've tested it and it addresses the BUG, then let's go with this. I can apply it to nfsd-fixes.
I've done some light testing with this kernel, but this was found by Zhi while testing with the lustre racer test, so it involves some raciness. I've never hit this myself.
Has Zhi tested this fix?
Quoted 8 lines
I'm pretty sure though that this has to be initialized every time. The assignment is inside the loop, after all. I'm ok with moving the assignment to a different line if you like though:
struct iattr attrs;
attrs = *iap;
...
Yeah I could do that. I find that easier to read when a loop is involved; it's unambiguous then what is going on.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
fs/nfsd/vfs.c +2
-0+ + host_err =__nfsd_setattr (dentry, &attrs);if (host_err != -EAGAIN || !retries--)break ;if (!nfsd_wait_for_delegreturn (rqstp, inode))Signature · 1 line
2.40.1
Quoted 7 lines
Quoted 4 lines
--
Chuck LeverSignature · 1 line
Jeff Layton <[email protected]>
--
Chuck Lever
Jeff Layton
maintainerQuoted 41 lines · Chuck Lever III
Quoted 41 lines · Jeff Layton
Quoted 35 lines · Chuck Lever III
Quoted 22 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/vfs.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 541
Quoted 5 lines
fs/nfsd/vfs.c +1
-1@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap;This construct always makes me queazy. I'm never sure if an initializer inside a loop is "only once" or "every time". I fixed a bug like this once.
But if you've tested it and it addresses the BUG, then let's go with this. I can apply it to nfsd-fixes.
Quoted 6 lines
Quoted 3 lines
I've done some light testing with this kernel, but this was found by Zhi while testing with the lustre racer test, so it involves some raciness. I've never hit this myself.
Has Zhi tested this fix?
Not yet. I just cooked it up this morning. I built a test kernel but testing it will take some time since it depends on load.
Quoted 5 lines
Quoted 5 lines
I'm pretty sure though that this has to be initialized every time. The assignment is inside the loop, after all. I'm ok with moving the assignment to a different line if you like though:
Quoted 8 lines
Quoted 4 lines
struct iattr attrs;
attrs = *iap;
...Yeah I could do that. I find that easier to read when a loop is involved; it's unambiguous then what is going on.
Your call. I'm fairly certain that the patch does the right thing as-is, but if you think it makes it more readable, then OK.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 19 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0
fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 546
Quoted 10 lines
fs/nfsd/vfs.c +3
-1@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap; + + host_err =__nfsd_setattr (dentry, &attrs);if (host_err != -EAGAIN || !retries--)break ;if (!nfsd_wait_for_delegreturn (rqstp, inode))
Zhi Li tested the test kernel for this today and this seems to have fixed the issue. I think you can add:
Cheers,
Jeff
Quoted 38 lines · Jeff Layton
Quoted 19 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/vfs.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 546
Quoted 10 lines
fs/nfsd/vfs.c +3
-1@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap; + + host_err =__nfsd_setattr (dentry, &attrs);if (host_err != -EAGAIN || !retries--)break ;if (!nfsd_wait_for_delegreturn (rqstp, inode))Zhi Li tested the test kernel for this today and this seems to have fixed the issue. I think you can add:
Quoted 1 line
Tested-by Zhi Li <[email protected]>
Thanks to you both. Applied to nfsd-fixes for the next 6.4-rc PR.
--
Chuck Lever
Quoted 19 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0
fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 543
Quoted 7 lines
fs/nfsd/vfs.c +3
-1@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap; + + host_err =__nfsd_setattr (dentry, &attrs);
I think this needs something to ensure a well meaning by-passer doesn't try to "optimise" it back to the way it was.
Maybe make "iap" const? Or add a comment? Or both?
NeilBrown
Quoted 7 lines
fs/nfsd/vfs.c +0
-0if (host_err != -EAGAIN || !retries--)break ;if (!nfsd_wait_for_delegreturn (rqstp, inode))Signature · 1 line
2.40.1
Jeff Layton
maintainerQuoted 21 lines · NeilBrown
Quoted 20 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
Quoted 11 lines
fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 543
Quoted 6 lines
fs/nfsd/vfs.c +3
-1inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap; + + host_err =__nfsd_setattr (dentry, &attrs);I think this needs something to ensure a well meaning by-passer doesn't try to "optimise" it back to the way it was.
Maybe make "iap" const? Or add a comment? Or both?
We can't make iap const, as we have to call nfsd_sanitize_attrs on it, and that will change things in it. I think we'll probably have to settle for a comment. Chuck, can we fold the patch below in to this one?
--------------------8<------------------
fs/nfsd/vfs.c +5 -0
@@ -538,6 +538,11 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,for (retries =1 ;;) {struct iattr attrs; +/* +* notify_change can alter the iattr in ways that make it +* unsuitable for submission multiple times. Make a copy +* for every loop. +*/ attrs = *iap; host_err =__nfsd_setattr (dentry, &attrs);if (host_err != -EAGAIN || !retries--)
Chuck Lever
maintainerQuoted 34 lines · Jeff Layton
Quoted 21 lines · NeilBrown
Quoted 20 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,Quoted 11 lines
fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 543
Quoted 6 lines
fs/nfsd/vfs.c +3
-1inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap; + + host_err =__nfsd_setattr (dentry, &attrs);I think this needs something to ensure a well meaning by-passer doesn't try to "optimise" it back to the way it was.
Maybe make "iap" const? Or add a comment? Or both?
Quoted 3 lines
We can't make iap const, as we have to call
nfsd_sanitize_attrson it, and that will change things in it. I think we'll probably have to settle for a comment. Chuck, can we fold the patch below in to this one?
Done, and pushed to nfsd-fixes.
Quoted 19 lines
--------------------8<------------------
fs/nfsd/vfs.c +5
-0@@ -538,6 +538,11 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,for (retries =1 ;;) {struct iattr attrs; +/* +* notify_change can alter the iattr in ways that make it +* unsuitable for submission multiple times. Make a copy +* for every loop. +*/ attrs = *iap; host_err =__nfsd_setattr (dentry, &attrs);if (host_err != -EAGAIN || !retries--)
Quoted 34 lines · Jeff Layton
Quoted 21 lines · NeilBrown
Quoted 20 lines · Jeff Layton
notify_changecan modify the iattr structure. In particular it can can end up settingATTR_MODEwhenATTR_KILL_SUIDis already set, causing aBUG()if the same iattr is passed tonotify_changemore than once.Make a copy of the struct iattr before calling
notify_change.Fixes 34b91dda7124 NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAYReported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/nfsd/vfs.c +0
-0@@ -538,7 +538,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,Quoted 11 lines
fs/nfsd/vfs.c nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 543
Quoted 6 lines
fs/nfsd/vfs.c +3
-1inode_lock (inode);for (retries =1 ;;) { - host_err =__nfsd_setattr (dentry, iap); +struct iattr attrs = *iap; + + host_err =__nfsd_setattr (dentry, &attrs);I think this needs something to ensure a well meaning by-passer doesn't try to "optimise" it back to the way it was.
Maybe make "iap" const? Or add a comment? Or both?
Quoted 3 lines
We can't make iap const, as we have to call
nfsd_sanitize_attrson it, and that will change things in it. I think we'll probably have to settle for a comment. Chuck, can we fold the patch below in to this one?
Thanks :-)
NeilBrown
Quoted 21 lines
--------------------8<------------------
fs/nfsd/vfs.c +5
-0@@ -538,6 +538,11 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,for (retries =1 ;;) {struct iattr attrs; +/* +* notify_change can alter the iattr in ways that make it +* unsuitable for submission multiple times. Make a copy +* for every loop. +*/ attrs = *iap; host_err =__nfsd_setattr (dentry, &attrs);if (host_err != -EAGAIN || !retries--)