cifs: fix dentry refcount leak when opening a FIFO on lookup
Subsystems (2)
PATCH 1/1 cifs: fix dentry refcount leak when opening a FIFO on lookup
The cifs code will attempt to open files on lookup under certain circumstances. What happens though if we find that the file we opened was actually a FIFO or other special file?
Currently, the open filehandle just ends up being leaked leading to a dentry refcount mismatch and oops on umount. Fix this by having the code close the filehandle on the server if it turns out not to be a regular file. While we're at it, change this spaghetti if statement into a switch too.
--- fs/cifs/dir.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-)
fs/cifs/dir.c +18 -2
@@ -584,10 +584,26 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,* If either that or op not supported returned, follow * the normal lookup. */ -if ((rc ==0 ) || (rc == -ENOENT )) +switch (rc) { +case 0 : +/* +* The server may allow us to open things like +* FIFOs, but the client isn't set up to deal +* with that. If it's not a regular file, just +* close it and proceed as if it were a normal +* lookup. +*/ +if (newInode && !S_ISREG (newInode->i_mode)) { +CIFSSMBClose (xid, pTcon, fileHandle); +break ; + } +case -ENOENT : posix_open = true; -else if ((rc == -EINVAL ) || (rc != -EOPNOTSUPP )) +case -EOPNOTSUPP : +break ; +default : pTcon->broken_posix_open = true; + } }if (!posix_open) rc = cifs_get_inode_info_unix(&newInode, full_path,
Signature · 1 line
1.7.7.6
A message that is not in the archive (sent off-list or not yet received): 1330007865-19962-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
CAI Qian
Tested-by----- Original Message -----
Quoted 10 lines
The cifs code will attempt to open files on lookup under certain circumstances. What happens though if we find that the file we opened was actually a FIFO or other special file?
Currently, the open filehandle just ends up being leaked leading to a dentry refcount mismatch and oops on umount. Fix this by having the code close the filehandle on the server if it turns out not to be a regular file. While we're at it, change this spaghetti if statement into a switch too.
Quoted 3 lines
Reported-by CAI Qian <[email protected]>Signed-off-by Jeff Layton <[email protected]>
Quoted 47 lines
--- fs/cifs/dir.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-)fs/cifs/dir.c +18
-2@@ -584,10 +584,26 @@ cifs_lookup(struct inode *parent_dir_inode,struct dentry *direntry, * If either that or op not supported returned, follow * the normal lookup. */ -if ((rc ==0 ) || (rc == -ENOENT )) +switch (rc) { +case 0 : +/* +* The server may allow us to open things like +* FIFOs, but the client isn't set up to deal +* with that. If it's not a regular file, just +* close it and proceed as if it were a normal +* lookup. +*/ +if (newInode && !S_ISREG (newInode->i_mode)) { +CIFSSMBClose (xid, pTcon, fileHandle); +break ; + } +case -ENOENT : posix_open = true; -else if ((rc == -EINVAL ) || (rc != -EOPNOTSUPP )) +case -EOPNOTSUPP : +break ; +default : pTcon->broken_posix_open = true; + } }if (!posix_open)rc = cifs_get_inode_info_unix(&newInode,
full_path,
--
1.7.7.6--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 29 lines · Jeff Layton
The cifs code will attempt to open files on lookup under certain circumstances. What happens though if we find that the file we opened was actually a FIFO or other special file?
Currently, the open filehandle just ends up being leaked leading to a dentry refcount mismatch and oops on umount. Fix this by having the code close the filehandle on the server if it turns out not to be a regular file. While we're at it, change this spaghetti if statement into a switch too.
Reported-by CAI Qian <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/dir.c | 20 ++++++++++++++++++--1 files changed, 18 insertions(+), 2 deletions(-)fs/cifs/dir.c +3
-1@@ -584,10 +584,26 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,* If either that or op not supported returned, follow * the normal lookup. */ - if ((rc == 0) || (rc == -ENOENT)) + switch (rc) { + case 0: + /*
fs/cifs/dir.c cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, · line 599
Quoted 10 lines
fs/cifs/dir.c +10
-0+* The server may allow us to open things like +* FIFOs, but the client isn't set up to deal +* with that. If it's not a regular file, just +* close it and proceed as if it were a normal +* lookup. +*/ + if (newInode && !S_ISREG(newInode->i_mode)) { + CIFSSMBClose(xid, pTcon, fileHandle); + break; + }
Should there be else posix_open = true; statement?
Quoted 18 lines
fs/cifs/dir.c +5
-2+ case -ENOENT: posix_open = true; - else if ((rc == -EINVAL) || (rc != -EOPNOTSUPP)) + case -EOPNOTSUPP: + break; + default: pTcon->broken_posix_open = true; + } } if (!posix_open) rc = cifs_get_inode_info_unix(&newInode, full_path, --1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CADT32eJbv7n71sAFx8Tm2qOMsjC24_PM89Ee5VQKV6Dg52-uiw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 34 lines · On Fri, 24 Feb 2012 11:53:27 -0600 Shirish Pargaonkar…
Quoted 33 lines · Jeff Layton
The cifs code will attempt to open files on lookup under certain circumstances. What happens though if we find that the file we opened was actually a FIFO or other special file?
Currently, the open filehandle just ends up being leaked leading to a dentry refcount mismatch and oops on umount. Fix this by having the code close the filehandle on the server if it turns out not to be a regular file. While we're at it, change this spaghetti if statement into a switch too.
Reported-by CAI Qian <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/dir.c | 20 ++++++++++++++++++--1 files changed, 18 insertions(+), 2 deletions(-)fs/cifs/dir.c +7
-1@@ -584,10 +584,26 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,* If either that or op not supported returned, follow * the normal lookup. */ - if ((rc == 0) || (rc == -ENOENT)) + switch (rc) { + case 0: + /* +* The server may allow us to open things like +* FIFOs, but the client isn't set up to deal +* with that. If it's not a regular file, just +* close it and proceed as if it were a normal
Quoted 9 lines
fs/cifs/dir.c cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, · line 599
Quoted 6 lines
fs/cifs/dir.c +6
-0+* lookup. +*/ + if (newInode && !S_ISREG(newInode->i_mode)) { + CIFSSMBClose(xid, pTcon, fileHandle); + break; + }Should there be else
posix_open= true; statement?
No, it'll fall through to the -ENOENT case.
Quoted 18 lines
Quoted 18 lines
fs/cifs/dir.c +5
-2+ case -ENOENT: posix_open = true; - else if ((rc == -EINVAL) || (rc != -EOPNOTSUPP)) + case -EOPNOTSUPP: + break; + default: pTcon->broken_posix_open = true; + } } if (!posix_open) rc = cifs_get_inode_info_unix(&newInode, full_path, --1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 53 lines · Jeff Layton
The cifs code will attempt to open files on lookup under certain circumstances. What happens though if we find that the file we opened was actually a FIFO or other special file?
Currently, the open filehandle just ends up being leaked leading to a dentry refcount mismatch and oops on umount. Fix this by having the code close the filehandle on the server if it turns out not to be a regular file. While we're at it, change this spaghetti if statement into a switch too.
Reported-by CAI Qian <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/dir.c | 20 ++++++++++++++++++--1 files changed, 18 insertions(+), 2 deletions(-)fs/cifs/dir.c +18
-3@@ -584,10 +584,26 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,* If either that or op not supported returned, follow * the normal lookup. */ - if ((rc == 0) || (rc == -ENOENT)) + switch (rc) { + case 0: + /* + * The server may allow us to open things like + * FIFOs, but the client isn't set up to deal + * with that. If it's not a regular file, just + * close it and proceed as if it were a normal + * lookup. + */ + if (newInode && !S_ISREG(newInode->i_mode)) { + CIFSSMBClose(xid, pTcon, fileHandle); + break; + } + case -ENOENT: posix_open = true; - else if ((rc == -EINVAL) || (rc != -EOPNOTSUPP)) + case -EOPNOTSUPP: + break; + default: pTcon->broken_posix_open = true; + } } if (!posix_open) rc = cifs_get_inode_info_unix(&newInode, full_path, --1.7.7.6
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
One more thing, should CIFSPOSIXDelFile should be called to match CIFSPOSIXOpen or CIFSMBClose is just as good enough?
A message that is not in the archive (sent off-list or not yet received): CADT32eLr1B5XPkBqE3Lmj7v1sa1yoXE3MNNiJ+ubPf3t+UJSWg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 54 lines · On Fri, 24 Feb 2012 11:59:25 -0600 Shirish Pargaonkar…
Quoted 53 lines · Jeff Layton
The cifs code will attempt to open files on lookup under certain circumstances. What happens though if we find that the file we opened was actually a FIFO or other special file?
Currently, the open filehandle just ends up being leaked leading to a dentry refcount mismatch and oops on umount. Fix this by having the code close the filehandle on the server if it turns out not to be a regular file. While we're at it, change this spaghetti if statement into a switch too.
Reported-by CAI Qian <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/dir.c | 20 ++++++++++++++++++--1 files changed, 18 insertions(+), 2 deletions(-)fs/cifs/dir.c +18
-3@@ -584,10 +584,26 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,* If either that or op not supported returned, follow * the normal lookup. */ - if ((rc == 0) || (rc == -ENOENT)) + switch (rc) { + case 0: + /* + * The server may allow us to open things like + * FIFOs, but the client isn't set up to deal + * with that. If it's not a regular file, just + * close it and proceed as if it were a normal + * lookup. + */ + if (newInode && !S_ISREG(newInode->i_mode)) { + CIFSSMBClose(xid, pTcon, fileHandle); + break; + } + case -ENOENT: posix_open = true; - else if ((rc == -EINVAL) || (rc != -EOPNOTSUPP)) + case -EOPNOTSUPP: + break; + default: pTcon->broken_posix_open = true; + } } if (!posix_open) rc = cifs_get_inode_info_unix(&newInode, full_path, --1.7.7.6
Quoted 7 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlOne more thing, should CIFSPOSIXDelFile should be called to match CIFSPOSIXOpen or CIFSMBClose is just as good enough?
I don't think so...
If the FIFO was already there, then you clearly don't want to remove it. Note that in this case, we're not failing anything -- just getting rid of the open filehandle and corresponding CIFS open when we realize that it's not a normal file.
Signature · 1 line
Jeff Layton <[email protected]>
A message that is not in the archive (sent off-list or not yet received): [email protected]
merged
Quoted 74 lines · Jeff Layton
Quoted 54 lines · On Fri, 24 Feb 2012 11:59:25 -0600 Shirish Pargaonkar…
Quoted 53 lines · Jeff Layton
The cifs code will attempt to open files on lookup under certain circumstances. What happens though if we find that the file we opened was actually a FIFO or other special file?
Currently, the open filehandle just ends up being leaked leading to a dentry refcount mismatch and oops on umount. Fix this by having the code close the filehandle on the server if it turns out not to be a regular file. While we're at it, change this spaghetti if statement into a switch too.
Reported-by CAI Qian <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/dir.c | 20 ++++++++++++++++++--1 files changed, 18 insertions(+), 2 deletions(-)fs/cifs/dir.c +18
-3@@ -584,10 +584,26 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,* If either that or op not supported returned, follow * the normal lookup. */ - if ((rc == 0) || (rc == -ENOENT)) + switch (rc) { + case 0: + /* + * The server may allow us to open things like + * FIFOs, but the client isn't set up to deal + * with that. If it's not a regular file, just + * close it and proceed as if it were a normal + * lookup. + */ + if (newInode && !S_ISREG(newInode->i_mode)) { + CIFSSMBClose(xid, pTcon, fileHandle); + break; + } + case -ENOENT: posix_open = true; - else if ((rc == -EINVAL) || (rc != -EOPNOTSUPP)) + case -EOPNOTSUPP: + break; + default: pTcon->broken_posix_open = true; + } } if (!posix_open) rc = cifs_get_inode_info_unix(&newInode, full_path, --1.7.7.6
Quoted 7 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlOne more thing, should CIFSPOSIXDelFile should be called to match CIFSPOSIXOpen or CIFSMBClose is just as good enough?
I don't think so...
If the FIFO was already there, then you clearly don't want to remove it. Note that in this case, we're not failing anything -- just getting rid of the open filehandle and corresponding CIFS open when we realize that it's not a normal file.
--
Jeff Layton <[email protected]>
Signature · 3 lines
Thanks, Steve
Shirish Pargaonkar
Reviewed-byQuoted 53 lines · Jeff Layton
The cifs code will attempt to open files on lookup under certain circumstances. What happens though if we find that the file we opened was actually a FIFO or other special file?
Currently, the open filehandle just ends up being leaked leading to a dentry refcount mismatch and oops on umount. Fix this by having the code close the filehandle on the server if it turns out not to be a regular file. While we're at it, change this spaghetti if statement into a switch too.
Reported-by CAI Qian <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/dir.c | 20 ++++++++++++++++++--1 files changed, 18 insertions(+), 2 deletions(-)fs/cifs/dir.c +18
-3@@ -584,10 +584,26 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,* If either that or op not supported returned, follow * the normal lookup. */ - if ((rc == 0) || (rc == -ENOENT)) + switch (rc) { + case 0: + /* + * The server may allow us to open things like + * FIFOs, but the client isn't set up to deal + * with that. If it's not a regular file, just + * close it and proceed as if it were a normal + * lookup. + */ + if (newInode && !S_ISREG(newInode->i_mode)) { + CIFSSMBClose(xid, pTcon, fileHandle); + break; + } + case -ENOENT: posix_open = true; - else if ((rc == -EINVAL) || (rc != -EOPNOTSUPP)) + case -EOPNOTSUPP: + break; + default: pTcon->broken_posix_open = true; + } } if (!posix_open) rc = cifs_get_inode_info_unix(&newInode, full_path, --1.7.7.6
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Code looks correct.