linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cifs - check S_AUTOMOUNT in revalidate
@ 2012-04-27  8:18 Ian Kent
  2012-04-28  2:46 ` Linus Torvalds
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Kent @ 2012-04-27  8:18 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Jeff Layton, Steve French, linux-cifs, Kernel Mailing List

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.

Signed-off-by: Ian Kent <raven@themaw.net>
Reviewed-by: Jeff Layton <jlayton@redhat.com>
Cc: Steve French <smfrench@gmail.com>
Cc: linux-cifs@vger.kernel.org
---

 fs/cifs/dir.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index d172c8e..ec4e9a2 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -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;
 		}
 	}


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] cifs - check S_AUTOMOUNT in revalidate
  2012-04-27  8:18 [PATCH] cifs - check S_AUTOMOUNT in revalidate Ian Kent
@ 2012-04-28  2:46 ` Linus Torvalds
  2012-04-28  3:33   ` Steve French
  0 siblings, 1 reply; 8+ messages in thread
From: Linus Torvalds @ 2012-04-28  2:46 UTC (permalink / raw)
  To: Steve French; +Cc: Ian Kent, Jeff Layton, linux-cifs, Kernel Mailing List

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

On Fri, Apr 27, 2012 at 1:18 AM, Ian Kent <raven@themaw.net> wrote:
> 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.
>
> Signed-off-by: Ian Kent <raven@themaw.net>
> Reviewed-by: Jeff Layton <jlayton@redhat.com>
> Cc: Steve French <smfrench@gmail.com>
> Cc: linux-cifs@vger.kernel.org
> ---
>
>  fs/cifs/dir.c |   17 ++++++++++++-----
>  1 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
> index d172c8e..ec4e9a2 100644
> --- a/fs/cifs/dir.c
> +++ b/fs/cifs/dir.c
> @@ -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;
>                }
>        }
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] cifs - check S_AUTOMOUNT in revalidate
  2012-04-28  2:46 ` Linus Torvalds
@ 2012-04-28  3:33   ` Steve French
  2012-04-28  3:55     ` Linus Torvalds
  2012-05-02 11:45     ` Suresh Jayaraman
  0 siblings, 2 replies; 8+ messages in thread
From: Steve French @ 2012-04-28  3:33 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Ian Kent, Jeff Layton, linux-cifs, Kernel Mailing List

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.

On Fri, Apr 27, 2012 at 9:46 PM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> 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
>
> On Fri, Apr 27, 2012 at 1:18 AM, Ian Kent <raven@themaw.net> wrote:
>> 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.
>>
>> Signed-off-by: Ian Kent <raven@themaw.net>
>> Reviewed-by: Jeff Layton <jlayton@redhat.com>
>> Cc: Steve French <smfrench@gmail.com>
>> Cc: linux-cifs@vger.kernel.org
>> ---
>>
>>  fs/cifs/dir.c |   17 ++++++++++++-----
>>  1 files changed, 12 insertions(+), 5 deletions(-)
>>
>> diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
>> index d172c8e..ec4e9a2 100644
>> --- a/fs/cifs/dir.c
>> +++ b/fs/cifs/dir.c
>> @@ -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;
>>                }
>>        }
>>



-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] cifs - check S_AUTOMOUNT in revalidate
  2012-04-28  3:33   ` Steve French
@ 2012-04-28  3:55     ` Linus Torvalds
  2012-05-02 11:45     ` Suresh Jayaraman
  1 sibling, 0 replies; 8+ messages in thread
From: Linus Torvalds @ 2012-04-28  3:55 UTC (permalink / raw)
  To: Steve French; +Cc: Ian Kent, Jeff Layton, linux-cifs, Kernel Mailing List

On Fri, Apr 27, 2012 at 8:33 PM, Steve French <smfrench@gmail.com> wrote:
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] cifs - check S_AUTOMOUNT in revalidate
  2012-04-28  3:33   ` Steve French
  2012-04-28  3:55     ` Linus Torvalds
@ 2012-05-02 11:45     ` Suresh Jayaraman
  2012-05-02 17:50       ` Jeff Layton
  1 sibling, 1 reply; 8+ messages in thread
From: Suresh Jayaraman @ 2012-05-02 11:45 UTC (permalink / raw)
  To: Steve French
  Cc: Linus Torvalds, Ian Kent, Jeff Layton, linux-cifs, Kernel Mailing List

On 04/28/2012 09:03 AM, Steve French wrote:
> 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: stable@vger.kernel.org


Suresh



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] cifs - check S_AUTOMOUNT in revalidate
  2012-05-02 11:45     ` Suresh Jayaraman
@ 2012-05-02 17:50       ` Jeff Layton
  2012-05-03  0:56         ` Ian Kent
  2012-05-03  5:49         ` Suresh Jayaraman
  0 siblings, 2 replies; 8+ messages in thread
From: Jeff Layton @ 2012-05-02 17:50 UTC (permalink / raw)
  To: Suresh Jayaraman
  Cc: Steve French, Linus Torvalds, Ian Kent, linux-cifs, Kernel Mailing List

On Wed, 02 May 2012 17:15:29 +0530
Suresh Jayaraman <sjayaraman@suse.com> wrote:

> On 04/28/2012 09:03 AM, Steve French wrote:
> > 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: stable@vger.kernel.org
> 
> 
> Suresh
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
> the body of a message to majordomo@vger.kernel.org
> 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.

-- 
Jeff Layton <jlayton@redhat.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] cifs - check S_AUTOMOUNT in revalidate
  2012-05-02 17:50       ` Jeff Layton
@ 2012-05-03  0:56         ` Ian Kent
  2012-05-03  5:49         ` Suresh Jayaraman
  1 sibling, 0 replies; 8+ messages in thread
From: Ian Kent @ 2012-05-03  0:56 UTC (permalink / raw)
  To: Suresh Jayaraman
  Cc: Jeff Layton, Steve French, Linus Torvalds, linux-cifs,
	Kernel Mailing List

On Wed, 2012-05-02 at 13:50 -0400, Jeff Layton wrote:
> On Wed, 02 May 2012 17:15:29 +0530
> Suresh Jayaraman <sjayaraman@suse.com> wrote:
> 
> > On 04/28/2012 09:03 AM, Steve French wrote:
> > > 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: stable@vger.kernel.org
> > 
> > 
> > Suresh
> > 
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
> > the body of a message to majordomo@vger.kernel.org
> > 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.
> 

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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] cifs - check S_AUTOMOUNT in revalidate
  2012-05-02 17:50       ` Jeff Layton
  2012-05-03  0:56         ` Ian Kent
@ 2012-05-03  5:49         ` Suresh Jayaraman
  1 sibling, 0 replies; 8+ messages in thread
From: Suresh Jayaraman @ 2012-05-03  5:49 UTC (permalink / raw)
  To: Jeff Layton
  Cc: Steve French, Linus Torvalds, Ian Kent, linux-cifs, Kernel Mailing List

On 05/02/2012 11:20 PM, Jeff Layton wrote:
> On Wed, 02 May 2012 17:15:29 +0530
> Suresh Jayaraman <sjayaraman@suse.com> wrote:
> 
>> On 04/28/2012 09:03 AM, Steve French wrote:
>>> 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: stable@vger.kernel.org
> 
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-05-03  5:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-27  8:18 [PATCH] cifs - check S_AUTOMOUNT in revalidate Ian Kent
2012-04-28  2:46 ` Linus Torvalds
2012-04-28  3:33   ` Steve French
2012-04-28  3:55     ` Linus Torvalds
2012-05-02 11:45     ` Suresh Jayaraman
2012-05-02 17:50       ` Jeff Layton
2012-05-03  0:56         ` Ian Kent
2012-05-03  5:49         ` Suresh Jayaraman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).