Regression in mfsymlink handling introduced by "cifs: only set ops for inodes in I_NEW state"
Subsystems (2)
The following commit included in 3.10, and copied to some table-series kernels:
commit: c2b93e0699723700f886ce17bb65ffd771195a6d
cifs: only set ops for inodes in I_NEW state
... causes a regression in mfsymlink handling under some circumstances.
Specifically, this patch modified cifs_fattr_to_inode() to only invoke cifs_set_ops() if that inode still had the I_NEW flag set --- preventing an inode's ops-set from from being changed after it had been initialized, preventing an oops if another thread of execution was already chasing that pointer.
However, mfsymlinks are also affected by this commit. In the cold-cache case, a user invoking stat() on an mfsymlink will still see the correct results. But, if the dentry cache is instead populated via cifs_readdir/filldir, then inode property population operates in a two stage mode:
- First, the inode is initialized as a regular file, with the CIFS_FATTR_NEED_REVAL flag set.
- Later, when the file is stat()'d, then correct operation depends on the (re)validation steps from being able to update the inode's properties --- including the set of file operations permitted.
(A comment explains: "trying to get the type and mode can be slow, so
just call those regular files for now, and mark for reval")
With the above commit, this second revalidation step never updates the operations field, resulting in symlinks not having the readlink(), etc. functions correctly hooked up.
A naïve fix-up is to modify the conditional to also permit (re)setting ops on S_IFLNK-mode files; however, I suspect a correct fix lies elsewhere?
Cheers,
David
Signature · 2 lines
David McBride <dwm37-KWPb1pKIrIJaa/[email protected]> Unix Specialist, University Computing Service
A message that is not in the archive (sent off-list or not yet received): 51F92F0B.7030504-KWPb1pKIrIJaa/[email protected]
Hi David,
Quoted 30 lines
The following commit included in 3.10, and copied to some table-series kernels:
commit:
c2b93e0699723700f886ce17bb65ffd771195a6d
cifs: only set ops for inodes inI_NEWstate... causes a regression in mfsymlink handling under some circumstances.
Specifically, this patch modified
cifs_fattr_to_inode()to only invokecifs_set_ops()if that inode still had theI_NEWflag set --- preventing an inode's ops-set from from being changed after it had been initialized, preventing an oops if another thread of execution was already chasing that pointer.However, mfsymlinks are also affected by this commit. In the cold-cache case, a user invoking
stat()on an mfsymlink will still see the correct results. But, if the dentry cache is instead populated via cifs_readdir/filldir, then inode property population operates in a two stage mode:- First, the inode is initialized as a regular file, with the
CIFS_FATTR_NEED_REVALflag set.- Later, when the file is stat()'d, then correct operation depends on the (re)validation steps from being able to update the inode's properties --- including the set of file operations permitted.
(A comment explains: "trying to get the type and mode can be slow, so
just call those regular files for now, and mark for reval")
Quoted 6 lines
With the above commit, this second revalidation step never updates the operations field, resulting in symlinks not having the
readlink(), etc. functions correctly hooked up.A naïve fix-up is to modify the conditional to also permit (re)setting ops on S_IFLNK-mode files; however, I suspect a correct fix lies elsewhere?
I guess 'if (inode->i_state & I_NEW)' should be changed to
'if ((inode->i_state & I_NEW) || (fattr->cf_flags & CIFS_FATTR_NEED_REVAL))'
Would that solve the problem?
Jeff/Steve, any comment on this?
metze
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 39 lines · On Tue, 06 Aug 2013 16:30:52 +0200 "Stefan (metze) Metzmacher"…
Hi David,
Quoted 30 lines
The following commit included in 3.10, and copied to some table-series kernels:
commit:
c2b93e0699723700f886ce17bb65ffd771195a6d
cifs: only set ops for inodes inI_NEWstate... causes a regression in mfsymlink handling under some circumstances.
Specifically, this patch modified
cifs_fattr_to_inode()to only invokecifs_set_ops()if that inode still had theI_NEWflag set --- preventing an inode's ops-set from from being changed after it had been initialized, preventing an oops if another thread of execution was already chasing that pointer.However, mfsymlinks are also affected by this commit. In the cold-cache case, a user invoking
stat()on an mfsymlink will still see the correct results. But, if the dentry cache is instead populated via cifs_readdir/filldir, then inode property population operates in a two stage mode:- First, the inode is initialized as a regular file, with the
CIFS_FATTR_NEED_REVALflag set.- Later, when the file is stat()'d, then correct operation depends on the (re)validation steps from being able to update the inode's properties --- including the set of file operations permitted.
(A comment explains: "trying to get the type and mode can be slow, so
just call those regular files for now, and mark for reval")Quoted 6 lines
With the above commit, this second revalidation step never updates the operations field, resulting in symlinks not having the
readlink(), etc. functions correctly hooked up.A naïve fix-up is to modify the conditional to also permit (re)setting ops on S_IFLNK-mode files; however, I suspect a correct fix lies elsewhere?
Quoted 9 lines
I guess 'if (
inode->i_state&I_NEW)' should be changed to
'if ((inode->i_state&I_NEW) || (fattr->cf_flags&CIFS_FATTR_NEED_REVAL))'Would that solve the problem?
Jeff/Steve, any comment on this?
metze
I don't think so...
Once an inode's operations are set, you really don't want to go changing them. That opens the door for a malicious server to change the file type out from under you and cause oopses. The bug report that Sachin worked on originally had such an oops. In that case it was caused by something else, but a malicious server could wreak similar havoc...
The right solution is probably to ensure that the dentry fails d_revalidate if there's a chance it could turn out to be a mfsymlink. I think that the easiest way to ensure that would probably be to set the dentry->d_time to 0 in the readdir code.
Signature · 1 line
Jeff Layton <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 20130806105623.322d32a6-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org
Quoted 61 lines · On Tue, 6 Aug 2013 10:56:23 -0400 Jeff Layton…
Quoted 39 lines · On Tue, 06 Aug 2013 16:30:52 +0200 "Stefan (metze) Metzmacher"…
Hi David,
Quoted 30 lines
The following commit included in 3.10, and copied to some table-series kernels:
commit:
c2b93e0699723700f886ce17bb65ffd771195a6d
cifs: only set ops for inodes inI_NEWstate... causes a regression in mfsymlink handling under some circumstances.
Specifically, this patch modified
cifs_fattr_to_inode()to only invokecifs_set_ops()if that inode still had theI_NEWflag set --- preventing an inode's ops-set from from being changed after it had been initialized, preventing an oops if another thread of execution was already chasing that pointer.However, mfsymlinks are also affected by this commit. In the cold-cache case, a user invoking
stat()on an mfsymlink will still see the correct results. But, if the dentry cache is instead populated via cifs_readdir/filldir, then inode property population operates in a two stage mode:- First, the inode is initialized as a regular file, with the
CIFS_FATTR_NEED_REVALflag set.- Later, when the file is stat()'d, then correct operation depends on the (re)validation steps from being able to update the inode's properties --- including the set of file operations permitted.
(A comment explains: "trying to get the type and mode can be slow, so
just call those regular files for now, and mark for reval")Quoted 6 lines
With the above commit, this second revalidation step never updates the operations field, resulting in symlinks not having the
readlink(), etc. functions correctly hooked up.A naïve fix-up is to modify the conditional to also permit (re)setting ops on S_IFLNK-mode files; however, I suspect a correct fix lies elsewhere?
Quoted 9 lines
I guess 'if (
inode->i_state&I_NEW)' should be changed to
'if ((inode->i_state&I_NEW) || (fattr->cf_flags&CIFS_FATTR_NEED_REVAL))'Would that solve the problem?
Jeff/Steve, any comment on this?
metze
I don't think so...
Once an inode's operations are set, you really don't want to go changing them. That opens the door for a malicious server to change the file type out from under you and cause oopses. The bug report that Sachin worked on originally had such an oops. In that case it was caused by something else, but a malicious server could wreak similar havoc...
Quoted 5 lines
The right solution is probably to ensure that the dentry fails
d_revalidateif there's a chance it could turn out to be a mfsymlink. I think that the easiest way to ensure that would probably be to set thedentry->d_timeto 0 in the readdir code.
Specifically, I think the logic in cifs_d_revalidate is just plain wrong. Currently, the dentry->d_time check and the check for lookupCacheEnabled is only done for negative dentries. Shouldn't that be affecting positive dentries as well?
If so, then you could simply set the dentries that are possible mfsymlinks with a d_time of 0. They'd fail revalidation at that step and get recreated when you stat them.
Sachin, Steve, thoughts?
Signature · 1 line
Jeff Layton <[email protected]>
PATCH 1/1 cifs: don't instantiate new dentries in readdir for inodes that need to be revalidated immediately
In reply to a message not in the archiveDavid reported that commit c2b93e06 (cifs: only set ops for inodes in I_NEW state) caused a regression with mfsymlinks. If a mfsymlink dentry was instantiated at readdir time, then it would not be properly tossed out of the cache and reinstantiated when a stat or readlink call came about.
This patch addresses this by simply skipping instantiating dentries when we *know* that they will need to be immediately revalidated. The next attempt to use that dentry will cause a new lookup to occur (which is basically what we want to happen anyway).
--- fs/cifs/readdir.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/cifs/readdir.c +8 -0
@@ -111,6 +111,14 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,return ; } +/* +* If we know that the inode will need to be revalidated immediately, +* then don't create a new dentry for it. We'll end up doing an on +* the wire call either way and this spares us an invalidation. +*/ +if (fattr->cf_flags &CIFS_FATTR_NEED_REVAL ) +return ; + dentry =d_alloc (parent, name);if (!dentry)return ;
Signature · 1 line
1.8.3.1
A message that is not in the archive (sent off-list or not yet received): 1375880647-22512-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [PATCH] cifs: don't instantiate new dentries in readdir for inodes that need to be revalidated immediately
Quoted 26 lines · On Wed, 7 Aug 2013 09:04:07 -0400 Jeff Layton…
David reported that commit
c2b93e06(cifs: only set ops for inodes inI_NEWstate) caused a regression with mfsymlinks. If a mfsymlink dentry was instantiated at readdir time, then it would not be properly tossed out of the cache and reinstantiated when a stat or readlink call came about.This patch addresses this by simply skipping instantiating dentries when we *know* that they will need to be immediately revalidated. The next attempt to use that dentry will cause a new lookup to occur (which is basically what we want to happen anyway).
Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/readdir.c | 8 ++++++++ 1 file changed, 8 insertions(+)fs/cifs/readdir.c +1
-0@@ -111,6 +111,14 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,return ; } +/*
fs/cifs/readdir.c cifs_prime_dcache(struct dentry *parent, struct qstr *name, · line 124
Quoted 10 lines
fs/cifs/readdir.c +7
-0+* If we know that the inode will need to be revalidated immediately, +* then don't create a new dentry for it. We'll end up doing an on +* the wire call either way and this spares us an invalidation. +*/ +if (fattr->cf_flags &CIFS_FATTR_NEED_REVAL ) +return ; + dentry =d_alloc (parent, name);if (!dentry)return ;
This patch is untested (other than for compilation), but I think it'll do the right thing. Metze, David could you test it and let us know if it helps?
Thanks,
Signature · 1 line
Jeff Layton <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 20130807090616.6ba44d6c-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org
David McBride
Tested-byRe: [PATCH] cifs: don't instantiate new dentries in readdir for inodes that need to be revalidated immediately
Quoted 3 lines · Jeff Layton
This patch is untested (other than for compilation), but I think it'll do the right thing. Metze, David could you test it and let us know if it helps?
Hi Jeff,
Seems to work nicely; many thanks!
(Caveat: I'm testing this on a backported version of the 3.10 driver on top of Ubuntu's 3.8 kernel.)
Cheers,
David
Signature · 2 lines
David McBride <dwm37-KWPb1pKIrIJaa/[email protected]> Unix Specialist, University Computing Service
A message that is not in the archive (sent off-list or not yet received): 52024EC3.2070504-KWPb1pKIrIJaa/[email protected]
Re: [PATCH] cifs: don't instantiate new dentries in readdir for inodes that need to be revalidated immediately
Am 07.08.2013 15:42, schrieb David McBride:
Quoted 5 lines · Jeff Layton
Quoted 4 lines
This patch is untested (other than for compilation), but I think it'll do the right thing. Metze, David could you test it and let us know if it helps?
Just to verify: could it be that mfsymlink is already broken in 3.9.6-301.fc19? At least links created with fedora 18 are no longer readable there. Newly created links seems to work fine (at least till now).
Greets
Marcus
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH] cifs: don't instantiate new dentries in readdir for inodes that need to be revalidated immediately
Quoted 7 lines · On Thu, 08 Aug 2013 16:05:44 +0200 Marcus Moeller…
Am 07.08.2013 15:42, schrieb David McBride:
Quoted 5 lines · Jeff Layton
Quoted 4 lines
This patch is untested (other than for compilation), but I think it'll do the right thing. Metze, David could you test it and let us know if it helps?
Quoted 7 lines
Just to verify: could it be that mfsymlink is already broken in 3.9.6-301.fc19? At least links created with fedora 18 are no longer readable there. Newly created links seems to work fine (at least till now).
Greets
Marcus
Yes, 3.9.6 has the patch that broke it.
What matters is how the (in memory) inode is created after mounting. If you first run across an mfsymlink with a readdir() call, then you'll get an inode that's "stuck" as a regular file. If you instead do something like stat() it before ever running a readdir over the containing directory, it should work just fine.
This patch probably is probably reasonable for stable, given that the original one also went there.
Steve, want to mark as such?
Signature · 1 line
Jeff Layton <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 20130808102236.44424bf3-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org
Re: [PATCH] cifs: don't instantiate new dentries in readdir for inodes that need to be revalidated immediately
Quoted 26 lines · Jeff Layton
Quoted 7 lines · On Thu, 08 Aug 2013 16:05:44 +0200 Marcus Moeller…
Am 07.08.2013 15:42, schrieb David McBride:
Quoted 5 lines · Jeff Layton
Quoted 4 lines
This patch is untested (other than for compilation), but I think it'll do the right thing. Metze, David could you test it and let us know if it helps?
Quoted 7 lines
Just to verify: could it be that mfsymlink is already broken in 3.9.6-301.fc19? At least links created with fedora 18 are no longer readable there. Newly created links seems to work fine (at least till now).
Greets
MarcusYes, 3.9.6 has the patch that broke it.
What matters is how the (in memory) inode is created after mounting. If you first run across an mfsymlink with a
readdir()call, then you'll get an inode that's "stuck" as a regular file. If you instead do something likestat()it before ever running a readdir over the containing directory, it should work just fine.
Quoted 4 lines
This patch probably is probably reasonable for stable, given that the original one also went there.
Steve, want to mark as such?
It is already marked for stable
Signature · 3 lines
Thanks, Steve
A message that is not in the archive (sent off-list or not yet received): CAH2r5muc+5xpabeQYNJq5Vb2_2nAMof2EUUFbkMpoBsUX7MC+g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH] cifs: don't instantiate new dentries in readdir for inodes that need to be revalidated immediately
Am 08.08.2013 17:33, schrieb Steve French:
Quoted 27 lines · Jeff Layton
Quoted 26 lines
Quoted 7 lines · On Thu, 08 Aug 2013 16:05:44 +0200 Marcus Moeller…
Am 07.08.2013 15:42, schrieb David McBride:
Quoted 5 lines · Jeff Layton
Quoted 4 lines
This patch is untested (other than for compilation), but I think it'll do the right thing. Metze, David could you test it and let us know if it helps?
Quoted 7 lines
Just to verify: could it be that mfsymlink is already broken in 3.9.6-301.fc19? At least links created with fedora 18 are no longer readable there. Newly created links seems to work fine (at least till now).
Greets
MarcusYes, 3.9.6 has the patch that broke it.
What matters is how the (in memory) inode is created after mounting. If you first run across an mfsymlink with a
readdir()call, then you'll get an inode that's "stuck" as a regular file. If you instead do something likestat()it before ever running a readdir over the containing directory, it should work just fine.
Quoted 4 lines
Quoted 4 lines
This patch probably is probably reasonable for stable, given that the original one also went there.
Steve, want to mark as such?
@Jeff, could you please do me a favor and let me know, when this is stable/made it to Fedora, as we are in need of that patch.
Thanks
Marcus