Skip to contentSkip to conversation

CIFS: Fix ERR_PTR dereference in cifs_get_root

PATCH In review Pavel Shilovsky 3 participants 3 messages Aug 21, 2011 – Aug 24, 2011 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 0435bb9..8b79122 100644
@@ -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
#2 lore raw
In reply to a message not in the archive
Quoted 25 lines · On Sun, 21 Aug 2011 19:30:15 +0400 Pavel Shilovsky…

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 -0
index 0435bb9..8b79122 100644
@@ -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]>
Reviewed-by
#4 lore raw
In reply to a message not in the archive
Quoted 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.

---
 fs/cifs/cifsfs.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +6 -3
index 0435bb9..8b79122 100644
@@ -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_root was 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.