From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kara Subject: Re: [Bugme-new] [Bug 15909] New: open("a/", O_NOFOLLOW) fails with ELOOP if "a" is a symbolic link to a directory. Date: Tue, 11 May 2010 18:28:19 +0200 Message-ID: <20100511162819.GE2832@quack.suse.cz> References: <20100506143002.0381501b.akpm@linux-foundation.org> <20100511154850.GC2832@quack.suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Al Viro , Christoph Hellwig , bugzilla-daemon@bugzilla.kernel.org, bugme-daemon@bugzilla.kernel.org, tolzmann@molgen.mpg.de, linux-fsdevel@vger.kernel.org To: Andrew Morton Return-path: Received: from cantor2.suse.de ([195.135.220.15]:40806 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751643Ab0EKQ2X (ORCPT ); Tue, 11 May 2010 12:28:23 -0400 Content-Disposition: inline In-Reply-To: <20100511154850.GC2832@quack.suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Tue 11-05-10 17:48:51, Jan Kara wrote: > From d53d3cc6488d9135bb69c3ff7e034b3b624866ed Mon Sep 17 00:00:00 2001 > From: Jan Kara > Date: Tue, 11 May 2010 16:34:25 +0200 > Subject: [PATCH] vfs: Fix O_NOFOLLOW behavior for paths with trailing slashes > > According to specification > mkdir d; ln -s d a; open("a/", O_NOFOLLOW | O_RDONLY) > should return success but currently it did return ELOOP. Fix the code to ignore > O_NOFOLLOW in case the provided path has trailing slashes. This is a regression > caused by path lookup cleanup patch series. > > CC: stable@kernel.org > Signed-off-by: Jan Kara > --- > fs/namei.c | 8 +++++--- > 1 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/fs/namei.c b/fs/namei.c > index a7dce91..4cc7fbc 100644 > --- a/fs/namei.c > +++ b/fs/namei.c ... > @@ -1722,7 +1722,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path, > > if (__follow_mount(path)) { > error = -ELOOP; > - if (open_flag & O_NOFOLLOW) > + if (!(nd->flags & LOOKUP_FOLLOW)) > goto exit_dput; > } Sorry for replying to myself... This change is actually unrelated and as I've checked the same behavior is in older kernels. So although the check currently does not quite make sense to me the fix should probably leave it alone. So below is a patch without the above hunk. --- >>From 2d4a9e9cca7c4f147aa29256ee25de593bb41540 Mon Sep 17 00:00:00 2001 From: Jan Kara Date: Tue, 11 May 2010 16:34:25 +0200 Subject: [PATCH] vfs: Fix O_NOFOLLOW behavior for paths with trailing slashes According to specification mkdir d; ln -s d a; open("a/", O_NOFOLLOW | O_RDONLY) should return success but currently it did return ELOOP. Fix the code to ignore O_NOFOLLOW in case the provided path has trailing slashes. This is a regression caused by path lookup cleanup patch series. CC: stable@kernel.org Signed-off-by: Jan Kara --- fs/namei.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index a7dce91..16df727 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1641,7 +1641,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path, if (nd->last.name[nd->last.len]) { if (open_flag & O_CREAT) goto exit; - nd->flags |= LOOKUP_DIRECTORY; + nd->flags |= LOOKUP_DIRECTORY | LOOKUP_FOLLOW; } /* just plain open? */ @@ -1830,6 +1830,8 @@ reval: } if (open_flag & O_DIRECTORY) nd.flags |= LOOKUP_DIRECTORY; + if (!(open_flag & O_NOFOLLOW)) + nd.flags |= LOOKUP_FOLLOW; filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname); while (unlikely(!filp)) { /* trailing symlink */ struct path holder; @@ -1837,7 +1839,7 @@ reval: void *cookie; error = -ELOOP; /* S_ISDIR part is a temporary automount kludge */ - if ((open_flag & O_NOFOLLOW) && !S_ISDIR(inode->i_mode)) + if (!(nd.flags & LOOKUP_FOLLOW) && !S_ISDIR(inode->i_mode)) goto exit_dput; if (count++ == 32) goto exit_dput; -- 1.6.4.2