CIFS: Fix ERR_PTR dereference in cifs_get_root
Subsystems (2)
PATCH 1/1 CIFS: Fix ERR_PTR dereference in cifs_get_root
move it to the beginning of the loop.
--- fs/cifs/cifsfs.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +6 -4
@@ -559,6 +559,12 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)struct inode *dir = dentry->d_inode;struct dentry *child; +if (!dir) { +dput (dentry); + dentry =ERR_PTR (-ENOENT ); +break ; + } +/* skip separators */ while (*s == sep) s++;
@@ -574,10 +580,6 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)mutex_unlock (&dir->i_mutex);dput (dentry); dentry = child; -if (!dentry->d_inode) { -dput (dentry); - dentry =ERR_PTR (-ENOENT ); - } }while (!IS_ERR (dentry));_FreeXid (xid);kfree (full_path);
Signature · 1 line
1.7.1
Quoted 25 lines · On Sun, 21 Aug 2011 19:30:15 +0400 Pavel Shilovsky…
move it to the beginning of the loop.
Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/cifsfs.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)fs/cifs/cifsfs.c +6
-0@@ -559,6 +559,12 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)struct inode *dir = dentry->d_inode;struct dentry *child; +if (!dir) { +dput (dentry); + dentry =ERR_PTR (-ENOENT ); +break ; + } +/* skip separators */ while (*s == sep) s++;
fs/cifs/cifsfs.c cifs_get_root(struct smb_vol *vol, struct super_block *sb) · line 585
Quoted 10 lines
fs/cifs/cifsfs.c +0
-4@@ -574,10 +580,6 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)mutex_unlock (&dir->i_mutex);dput (dentry); dentry = child; -if (!dentry->d_inode) { -dput (dentry); - dentry =ERR_PTR (-ENOENT ); - } }while (!IS_ERR (dentry));_FreeXid (xid);kfree (full_path);
What exactly does this fix? The only possible thing I could see it is if sb->s_root was a negative dentry, and I'm not sure that would ever happen. Would it?
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
Reviewed-byQuoted 34 lines · On Sun, 21 Aug 2011 12:22:51 -0400 Jeff Layton…
Quoted 31 lines · On Sun, 21 Aug 2011 19:30:15 +0400 Pavel Shilovsky…
move it to the beginning of the loop.
Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/cifsfs.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)fs/cifs/cifsfs.c +6
-3@@ -559,6 +559,12 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)struct inode *dir = dentry->d_inode;struct dentry *child; +if (!dir) { +dput (dentry); + dentry =ERR_PTR (-ENOENT ); +break ; + } +/* skip separators */ while (*s == sep) s++;@@ -574,10 +580,6 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)mutex_unlock (&dir->i_mutex);dput (dentry); dentry = child; -if (!dentry->d_inode) { -dput (dentry); - dentry =ERR_PTR (-ENOENT );
Quoted 9 lines
fs/cifs/cifsfs.c cifs_get_root(struct smb_vol *vol, struct super_block *sb) · line 585
Quoted 4 lines
fs/cifs/cifsfs.c +0
-1- } }while (!IS_ERR (dentry));_FreeXid (xid);kfree (full_path);What exactly does this fix? The only possible thing I could see it is if
sb->s_rootwas a negative dentry, and I'm not sure that would ever happen. Would it?
Ahh, nevermind. I see the issue...
If IS_ERR(dentry) is true then we definitely don't want to try and dereference the inode. This needs to go into 3.1 and stable as well.