Skip to contentSkip to conversation

cifs: When "refer file directly", make new inode cache if file type is different

PATCH In review Nakajima Akira 2 participants 2 messages Dec 24, 2014 – Jan 4, 2015 1 message not in the archive

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

PATCH 1/1 cifs: When "refer file directly", make new inode cache if file type is different

This problem is similar as
"Dec/19/2014 [PATCH] cifs: make new inode cache when file type is different"
but we need different patch.

Problem :
When "refer file directly" (e.g. ls <filename>),
in spite of different file type,
if file is same name, old inode cache is used.
This causes that you can not cd directory, can not cat SymbolicLink. So this patch is that if file type is different, return error.

Reproducible sample :
1. create file 'a' at cifs client.
2. rm 'a' and mkdir 'a' at server.
3. ls 'a' at client, then returned error (ls: cannot open directory). And you can not cd directory.

SymbolicLink has same problem.

Bug link:
https://bugzilla.kernel.org/show_bug.cgi?id=90031

# cifs_get_inode_info_unix() is for UNIX server.
# cifs_get_inode_info() is for Win server.

fs/cifs/inode.c +18 -0
diff -uprN -X linux-3.18-vanilla/Documentation/dontdiff linux-3.18-vanilla/fs/cifs/inode.c linux-3.18/fs/cifs/inode.c
@@ -402,9 +402,18 @@ int cifs_get_inode_info_unix(struct inod
 			rc = -ENOMEM;
 	} else {
 		/* we already have inode, update it */
+
+		/* if filetype is different, return error */
+		if (unlikely(((*pinode)->i_mode & S_IFMT) !=
+		    (fattr.cf_mode & S_IFMT))) {
+			rc = -ENOENT;
+			goto cgiiu_exit;
+		}
+
 		cifs_fattr_to_inode(*pinode, &fattr);
 	}
 
+cgiiu_exit:
 	return rc;
 }
 
@@ -837,6 +846,15 @@ cifs_get_inode_info(struct inode **inode
 		if (!*inode)
 			rc = -ENOMEM;
 	} else {
+		/* we already have inode, update it */
+
+		/* if filetype is different, return error */
+		if (unlikely(((*inode)->i_mode & S_IFMT) !=
+		    (fattr.cf_mode & S_IFMT))) {
+			rc = -ENOENT;
+			goto cgii_exit;
+		}
+
 		cifs_fattr_to_inode(*inode, &fattr);
 	}
Reviewed-by
#2 lore raw
In reply to a message not in the archive

Looks correct.

Quoted 72 lines · Nakajima Akira

This problem is similar as
"Dec/19/2014 [PATCH] cifs: make new inode cache when file type is different"
but we need different patch.

Problem :
When "refer file directly" (e.g. ls <filename>),
in spite of different file type,
if file is same name, old inode cache is used.
This causes that you can not cd directory, can not cat SymbolicLink. So this patch is that if file type is different, return error.

Reproducible sample :
1. create file 'a' at cifs client.
2. rm 'a' and mkdir 'a' at server.
3. ls 'a' at client, then returned error (ls: cannot open directory). And you can not cd directory.

SymbolicLink has same problem.

Bug link:
https://bugzilla.kernel.org/show_bug.cgi?id=90031

# cifs_get_inode_info_unix() is for UNIX server.
# cifs_get_inode_info() is for Win server.

diff -uprN -X linux-3.18-vanilla/Documentation/dontdiff linux-3.18-vanilla/fs/cifs/inode.c linux-3.18/fs/cifs/inode.c

fs/cifs/inode.c 2014-12-18 14:20:35.096468862 +0900 renamed from fs/cifs/inode.c 2014-12-08 07:21:05.000000000 +0900 +18 -1
@@ -402,9 +402,18 @@ int cifs_get_inode_info_unix(struct inod
                        rc = -ENOMEM;
        } else {
                /* we already have inode, update it */
+
+               /* if filetype is different, return error */
+               if (unlikely(((*pinode)->i_mode & S_IFMT) !=
+                   (fattr.cf_mode & S_IFMT))) {
+                       rc = -ENOENT;
+                       goto cgiiu_exit;
+               }
+
                cifs_fattr_to_inode(*pinode, &fattr);
        }
 
+cgiiu_exit:
        return rc;
 }
 
@@ -837,6 +846,15 @@ cifs_get_inode_info(struct inode **inode
                if (!*inode)
                        rc = -ENOMEM;
        } else {
+               /* we already have inode, update it */
+
+               /* if filetype is different, return error */
+               if (unlikely(((*inode)->i_mode & S_IFMT) !=
+                   (fattr.cf_mode & S_IFMT))) {
+                       rc = -ENOENT;
+                       goto cgii_exit;
+               }
+
                cifs_fattr_to_inode(*inode, &fattr);
        }
--

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