Skip to contentSkip to conversation

cifs - check S_AUTOMOUNT in revalidate

PATCH Applied Ian Kent 7 participants 12 messages Apr 27, 2012 – May 3, 2012 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Ian Kent

author
#0 lore raw

PATCH 1/1 cifs - check S_AUTOMOUNT in revalidate

When revalidating a dentry, if the inode wasn't known to be a dfs entry when the dentry was instantiated, such as when created via ->readdir(), the DCACHE_NEED_AUTOMOUNT flag needs to be set on the dentry in ->d_revalidate().

The false return from cifs_d_revalidate(), due to the inode now being marked with the S_AUTOMOUNT flag, might not invalidate the dentry if there is a concurrent unlazy path walk. This is because the dentry reference count will be at least 2 in this case causing d_invalidate() to return EBUSY. So the asumption that the dentry will be discarded then correctly instantiated via ->lookup() might not hold.

---

 fs/cifs/dir.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
fs/cifs/dir.c +12 -5
index d172c8e..ec4e9a2 100644
@@ -668,12 +668,19 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
 			return 0;
 		else {
 			/*
-			 * Forcibly invalidate automounting directory inodes
-			 * (remote DFS directories) so to have them
-			 * instantiated again for automount
+			 * If the inode wasn't known to be a dfs entry when
+			 * the dentry was instantiated, such as when created
+			 * via ->readdir(), it needs to be set now since the
+			 * attributes will have been updated by
+			 * cifs_revalidate_dentry().
 			 */
-			if (IS_AUTOMOUNT(direntry->d_inode))
-				return 0;
+			if (IS_AUTOMOUNT(direntry->d_inode) &&
+			   !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
+				spin_lock(&direntry->d_lock);
+				direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
+				spin_unlock(&direntry->d_lock);
+			}
+
 			return 1;
 		}
 	}
#1 lore raw

Steve? I have a CIFS pull request from you now, and it doesn't contain this one. I don't know the code well enough to say one way or the other, so I haven't applied this. Pls Ack/Nak.

Linus

Quoted 52 lines · Ian Kent

When revalidating a dentry, if the inode wasn't known to be a dfs entry when the dentry was instantiated, such as when created via ->readdir(), the DCACHE_NEED_AUTOMOUNT flag needs to be set on the dentry in ->d_revalidate().

The false return from cifs_d_revalidate(), due to the inode now being marked with the S_AUTOMOUNT flag, might not invalidate the dentry if there is a concurrent unlazy path walk. This is because the dentry reference count will be at least 2 in this case causing d_invalidate() to return EBUSY. So the asumption that the dentry will be discarded then correctly instantiated via ->lookup() might not hold.

---

 fs/cifs/dir.c |   17 ++++++++++++-----

 1 files changed, 12 insertions(+), 5 deletions(-)
fs/cifs/dir.c +12 -5
index d172c8e..ec4e9a2 100644
@@ -668,12 +668,19 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
                        return 0;
                else {
                        /*
-                        * Forcibly invalidate automounting directory inodes
-                        * (remote DFS directories) so to have them
-                        * instantiated again for automount
+                        * If the inode wasn't known to be a dfs entry when
+                        * the dentry was instantiated, such as when created
+                        * via ->readdir(), it needs to be set now since the
+                        * attributes will have been updated by
+                        * cifs_revalidate_dentry().
                         */
-                       if (IS_AUTOMOUNT(direntry->d_inode))
-                               return 0;
+                       if (IS_AUTOMOUNT(direntry->d_inode) &&
+                          !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
+                               spin_lock(&direntry->d_lock);
+                               direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
+                               spin_unlock(&direntry->d_lock);
+                       }
+
                        return 1;
                }
        }
#2 lore raw

The fix makes sense, but it is fairly recent and I haven't had a chance to try it,
so unless a new release is imminent, I would prefer to put in the next merge request (I have at least one more fix likely as well) next week.

Quoted 59 lines · Linus Torvalds

Steve? I have a CIFS pull request from you now, and it doesn't contain this one. I don't know the code well enough to say one way or the other, so I haven't applied this. Pls Ack/Nak.

                  Linus

Quoted 52 lines · Ian Kent

When revalidating a dentry, if the inode wasn't known to be a dfs entry when the dentry was instantiated, such as when created via ->readdir(), the DCACHE_NEED_AUTOMOUNT flag needs to be set on the dentry in ->d_revalidate().

The false return from cifs_d_revalidate(), due to the inode now being marked with the S_AUTOMOUNT flag, might not invalidate the dentry if there is a concurrent unlazy path walk. This is because the dentry reference count will be at least 2 in this case causing d_invalidate() to return EBUSY. So the asumption that the dentry will be discarded then correctly instantiated via ->lookup() might not hold.

---

 fs/cifs/dir.c |   17 ++++++++++++-----

 1 files changed, 12 insertions(+), 5 deletions(-)
fs/cifs/dir.c +12 -5
index d172c8e..ec4e9a2 100644
@@ -668,12 +668,19 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
                        return 0;
                else {
                        /*
-                        * Forcibly invalidate automounting directory inodes
-                        * (remote DFS directories) so to have them
-                        * instantiated again for automount
+                        * If the inode wasn't known to be a dfs entry when
+                        * the dentry was instantiated, such as when created
+                        * via ->readdir(), it needs to be set now since the
+                        * attributes will have been updated by
+                        * cifs_revalidate_dentry().
                         */
-                       if (IS_AUTOMOUNT(direntry->d_inode))
-                               return 0;
+                       if (IS_AUTOMOUNT(direntry->d_inode) &&
+                          !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
+                               spin_lock(&direntry->d_lock);
+                               direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
+                               spin_unlock(&direntry->d_lock);
+                       }
+
                        return 1;
                }
        }
Signature · 3 lines
Thanks,

Steve
#3 lore raw
Quoted 4 lines · Steve French

The fix makes sense, but it is fairly recent and I haven't had a chance to try it,
so unless a new release is imminent, I would prefer to put in the next merge request (I have at least one more fix likely as well) next week.

Ok, no problem. Just wanted to check.

Linus

#4 lore raw
In reply to Steve French
Quoted 4 lines · Steve French

The fix makes sense, but it is fairly recent and I haven't had a chance to try it,
so unless a new release is imminent, I would prefer to put in the next merge request (I have at least one more fix likely as well) next week.

We need this fix for -stable as well, right? Please include

Suresh

A message that is not in the archive (sent off-list or not yet received): 4FA11E59.9050004-IBi9RG/[email protected]

Applied
#6 lore raw

Merged into cifs-2.6.git

Quoted 14 lines · Suresh Jayaraman
Quoted 4 lines · Steve French

The fix makes sense, but it is fairly recent and I haven't had a chance to try it,
so unless a new release is imminent, I would prefer to put in the next merge request (I have at least one more fix likely as well) next week.

We need this fix for -stable as well, right? Please include

Suresh

Signature · 3 lines
Thanks,

Steve
#7 lore raw
In reply to Suresh Jayaraman
Quoted 11 lines · On Wed, 02 May 2012 17:15:29 +0530 Suresh Jayaraman…
Quoted 4 lines · Steve French

The fix makes sense, but it is fairly recent and I haven't had a chance to try it,
so unless a new release is imminent, I would prefer to put in the next merge request (I have at least one more fix likely as well) next week.

We need this fix for -stable as well, right? Please include

   Cc: [email protected]
Quoted 7 lines

Suresh

--
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

The stable-kernel-rules.txt file says this:

- It must fix a real bug that bothers people (not a, "This could be a problem..." type thing).

...and...

- No "theoretical race condition" issues, unless an explanation of how the race can be exploited is also provided.

...and this seems to clearly violate both of those rules. I'd say we just go with putting it in 3.4 for now, and keep it in mind if someone comes back later and says that it's needed.

Signature · 1 line
Jeff Layton <[email protected]>
author
#8 lore raw
Quoted 27 lines · Jeff Layton
Quoted 11 lines · On Wed, 02 May 2012 17:15:29 +0530 Suresh Jayaraman…
Quoted 4 lines · Steve French

The fix makes sense, but it is fairly recent and I haven't had a chance to try it,
so unless a new release is imminent, I would prefer to put in the next merge request (I have at least one more fix likely as well) next week.

We need this fix for -stable as well, right? Please include

   Cc: [email protected]
Quoted 7 lines

Suresh

--
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

The stable-kernel-rules.txt file says this:

- It must fix a real bug that bothers people (not a, "This could be a problem..." type thing).

Quoted 9 lines

...and...

- No "theoretical race condition" issues, unless an explanation of how the race can be exploited is also provided.

...and this seems to clearly violate both of those rules. I'd say we just go with putting it in 3.4 for now, and keep it in mind if someone comes back later and says that it's needed.

I have to agree with Jeff.

I just happened to notice it when trying to work out why DFS automounts weren't happening.

I eventually found that the kernel in use didn't have the d_invalidate() patch, then realized the potential problem. It would require fairly heavy demand to trigger so it isn't urgent, especially since no-one has actually reported it.

Another reason I should have sent this to Steve, not Linus, sorry for the noise Linus.

Ian

#9 lore raw
In reply to Jeff Layton
Quoted 9 lines · Jeff Layton
Quoted 6 lines · On Wed, 02 May 2012 17:15:29 +0530 Suresh Jayaraman…
Quoted 4 lines · Steve French

The fix makes sense, but it is fairly recent and I haven't had a chance to try it,
so unless a new release is imminent, I would prefer to put in the next merge request (I have at least one more fix likely as well) next week.

Quoted 9 lines
Quoted 3 lines

We need this fix for -stable as well, right? Please include

   Cc: [email protected]

The stable-kernel-rules.txt file says this:

- It must fix a real bug that bothers people (not a, "This could be a problem..." type thing).

Doh, looks like I had assumed (wrongly) that this fixes the problem reported here

http://marc.info/?l=linux-cifs&m=133460168320472&w=2

(mapping to a dfsroot and cd to a reflink returning "Object is remote" or "Not a directory" error). I didn't have a setup to verify it too.

I notice that Steve has already merged this patch adding Cc to stable and the Cc has to be removed before sending the pull request.

Suresh

A message that is not in the archive (sent off-list or not yet received): 4FA21C66.1030009-IBi9RG/[email protected]

#11 lore raw

Check the cifs-2.6.git tree - it should be fine.

Let me know if anything missing potentially for 3.4

Quoted 33 lines · Suresh Jayaraman
Quoted 9 lines · Jeff Layton
Quoted 6 lines · On Wed, 02 May 2012 17:15:29 +0530 Suresh Jayaraman…
Quoted 4 lines · Steve French

The fix makes sense, but it is fairly recent and I haven't had a chance to try it,
so unless a new release is imminent, I would prefer to put in the next merge request (I have at least one more fix likely as well) next week.

Quoted 9 lines
Quoted 3 lines

We need this fix for -stable as well, right? Please include

The stable-kernel-rules.txt file says this:

 - It must fix a real bug that bothers people (not a, "This could be a problem..." type thing).

Doh, looks like I had assumed (wrongly) that this fixes the problem reported here

  http://marc.info/?l=linux-cifs&m=133460168320472&w=2

(mapping to a dfsroot and cd to a reflink returning "Object is remote" or "Not a directory" error). I didn't have a setup to verify it too.

I notice that Steve has already merged this patch adding Cc to stable and the Cc has to be removed before sending the pull request.

Suresh

Signature · 3 lines
Thanks,

Steve

A message that is not in the archive (sent off-list or not yet received): 20120427081815.4478.26011.stgit-jgopVnDzZD88qxobedHYj6xOck334EZe@public.gmane.org

#13 lore raw

You may have corrupted the patch by cut&paste. Would you resend it? Checkpatch fails repeatedly with errors like:

ERROR: trailing whitespace
#84: FILE: fs/cifs/dir.c:671:
+^I^I^I * If the inode wasn't known to be a dfs entry when^M$

Quoted 52 lines · Ian Kent

When revalidating a dentry, if the inode wasn't known to be a dfs entry when the dentry was instantiated, such as when created via ->readdir(), the DCACHE_NEED_AUTOMOUNT flag needs to be set on the dentry in ->d_revalidate().

The false return from cifs_d_revalidate(), due to the inode now being marked with the S_AUTOMOUNT flag, might not invalidate the dentry if there is a concurrent unlazy path walk. This is because the dentry reference count will be at least 2 in this case causing d_invalidate() to return EBUSY. So the asumption that the dentry will be discarded then correctly instantiated via ->lookup() might not hold.

---

 fs/cifs/dir.c |   17 ++++++++++++-----

 1 files changed, 12 insertions(+), 5 deletions(-)
fs/cifs/dir.c +12 -5
index d172c8e..ec4e9a2 100644
@@ -668,12 +668,19 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
                        return 0;
                else {
                        /*
-                        * Forcibly invalidate automounting directory inodes
-                        * (remote DFS directories) so to have them
-                        * instantiated again for automount
+                        * If the inode wasn't known to be a dfs entry when
+                        * the dentry was instantiated, such as when created
+                        * via ->readdir(), it needs to be set now since the
+                        * attributes will have been updated by
+                        * cifs_revalidate_dentry().
                         */
-                       if (IS_AUTOMOUNT(direntry->d_inode))
-                               return 0;
+                       if (IS_AUTOMOUNT(direntry->d_inode) &&
+                          !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
+                               spin_lock(&direntry->d_lock);
+                               direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
+                               spin_unlock(&direntry->d_lock);
+                       }
+
                        return 1;
                }
        }
Signature · 3 lines
Thanks,

Steve

A message that is not in the archive (sent off-list or not yet received): CAH2r5ms7Xa5UXg-iw9QWG7u32nmDEneh0bHBM5d1kv4i-Oi_vA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#15 lore raw
Quoted 7 lines · On Tue, 1 May 2012 22:23:37 -0500 Steve French…

You may have corrupted the patch by cut&paste. Would you resend it? Checkpatch fails repeatedly with errors like:

ERROR: trailing whitespace
#84: FILE: fs/cifs/dir.c:671:
+^I^I^I * If the inode wasn't known to be a dfs entry when^M$

Hmmm...the only checkpatch warnings I saw were these trivial ones, which it looks to be getting out of the header of the email.

-------------------[snip]------------------

$ ./scripts/checkpatch.pl \[PATCH\]\ cifs\ -\ check\ S_AUTOMOUNT\ in\ revalidate 
WARNING: Use a single space after To:
#47: 
To:	Linus Torvalds <torvalds-de/[email protected]>

WARNING: Use a single space after Cc:
#48:
Cc: Jeff Layton <[email protected]>,

total: 0 errors, 2 warnings, 24 lines checked

[PATCH] cifs - check S_AUTOMOUNT in revalidate has style problems, please review.

If any of these errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. -------------------[snip]------------------

I don't see any trailing whitespace.

In any case, I went ahead and pushed it to my cifs-3.4 branch if you want to just cherry-pick it from there...

Quoted 57 lines · Ian Kent
Quoted 52 lines

When revalidating a dentry, if the inode wasn't known to be a dfs entry when the dentry was instantiated, such as when created via ->readdir(), the DCACHE_NEED_AUTOMOUNT flag needs to be set on the dentry in ->d_revalidate().

The false return from cifs_d_revalidate(), due to the inode now being marked with the S_AUTOMOUNT flag, might not invalidate the dentry if there is a concurrent unlazy path walk. This is because the dentry reference count will be at least 2 in this case causing d_invalidate() to return EBUSY. So the asumption that the dentry will be discarded then correctly instantiated via ->lookup() might not hold.

---

 fs/cifs/dir.c |   17 ++++++++++++-----

 1 files changed, 12 insertions(+), 5 deletions(-)
fs/cifs/dir.c +12 -5
index d172c8e..ec4e9a2 100644
@@ -668,12 +668,19 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
                        return 0;
                else {
                        /*
-                        * Forcibly invalidate automounting directory inodes
-                        * (remote DFS directories) so to have them
-                        * instantiated again for automount
+                        * If the inode wasn't known to be a dfs entry when
+                        * the dentry was instantiated, such as when created
+                        * via ->readdir(), it needs to be set now since the
+                        * attributes will have been updated by
+                        * cifs_revalidate_dentry().
                         */
-                       if (IS_AUTOMOUNT(direntry->d_inode))
-                               return 0;
+                       if (IS_AUTOMOUNT(direntry->d_inode) &&
+                          !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
+                               spin_lock(&direntry->d_lock);
+                               direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
+                               spin_unlock(&direntry->d_lock);
+                       }
+
                        return 1;
                }
        }
Signature · 1 line
Jeff Layton <[email protected]>