public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Christoph Hellwig <hch@infradead.org>
Cc: Rich Felker <dalias@libc.org>,
	linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] vfs: block chmod of symlinks
Date: Thu, 17 Sep 2020 05:15:03 +0100	[thread overview]
Message-ID: <20200917041503.GT3421308@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20200917040715.GS3421308@ZenIV.linux.org.uk>

On Thu, Sep 17, 2020 at 05:07:15AM +0100, Al Viro wrote:
> On Wed, Sep 16, 2020 at 07:25:53AM +0100, Christoph Hellwig wrote:
> > On Tue, Sep 15, 2020 at 08:22:54PM -0400, Rich Felker wrote:
> > > It was discovered while implementing userspace emulation of fchmodat
> > > AT_SYMLINK_NOFOLLOW (using O_PATH and procfs magic symlinks; otherwise
> > > it's not possible to target symlinks with chmod operations) that some
> > > filesystems erroneously allow access mode of symlinks to be changed,
> > > but return failure with EOPNOTSUPP (see glibc issue #14578 and commit
> > > a492b1e5ef). This inconsistency is non-conforming and wrong, and the
> > > consensus seems to be that it was unintentional to allow link modes to
> > > be changed in the first place.
> > > 
> > > Signed-off-by: Rich Felker <dalias@libc.org>
> > > ---
> > >  fs/open.c | 6 ++++++
> > >  1 file changed, 6 insertions(+)
> > > 
> > > diff --git a/fs/open.c b/fs/open.c
> > > index 9af548fb841b..cdb7964aaa6e 100644
> > > --- a/fs/open.c
> > > +++ b/fs/open.c
> > > @@ -570,6 +570,12 @@ int chmod_common(const struct path *path, umode_t mode)
> > >  	struct iattr newattrs;
> > >  	int error;
> > >  
> > > +	/* Block chmod from getting to fs layer. Ideally the fs would either
> > > +	 * allow it or fail with EOPNOTSUPP, but some are buggy and return
> > > +	 * an error but change the mode, which is non-conforming and wrong. */
> > > +	if (S_ISLNK(inode->i_mode))
> > > +		return -EOPNOTSUPP;
> > 
> > Our usualy place for this would be setattr_prepare.  Also the comment
> > style is off, and I don't think we should talk about buggy file systems
> > here, but a policy to not allow the chmod.  I also suspect the right
> > error value is EINVAL - EOPNOTSUPP isn't really used in normal posix
> > file system interfaces.
> 
> Er...   Wasn't that an ACL-related crap?  XFS calling posix_acl_chmod()
> after it has committed to i_mode change, propagating the error to
> caller of ->notify_change(), IIRC...
> 
> Put it another way, why do we want
>         if (!inode->i_op->set_acl)
>                 return -EOPNOTSUPP;
> in posix_acl_chmod(), when we have
>         if (!IS_POSIXACL(inode))
>                 return 0;
> right next to it?  If nothing else, make that
> 	if (!IS_POSIXACL(inode) || !inode->i_op->get_acl)
> 		return 0;	// piss off - nothing to adjust here

Arrgh...  That'd break shmem and similar filesystems...  Still, it
feels like we should _not_ bother in cases when there's no ACL
for that sucker; after all, if get_acl() returns NULL, we quietly
return 0 and that's it.

How about something like this instead?

diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 95882b3f5f62..2339160fabab 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -559,8 +559,6 @@ posix_acl_chmod(struct inode *inode, umode_t mode)
 
 	if (!IS_POSIXACL(inode))
 		return 0;
-	if (!inode->i_op->set_acl)
-		return -EOPNOTSUPP;
 
 	acl = get_acl(inode, ACL_TYPE_ACCESS);
 	if (IS_ERR_OR_NULL(acl)) {
@@ -569,6 +567,10 @@ posix_acl_chmod(struct inode *inode, umode_t mode)
 		return PTR_ERR(acl);
 	}
 
+	if (!inode->i_op->set_acl) {
+		posix_acl_release(acl);
+		return -EOPNOTSUPP;
+	}
 	ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
 	if (ret)
 		return ret;

  reply	other threads:[~2020-09-17  4:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16  0:22 [PATCH v2 0/2] changes for addding fchmodat2 syscall Rich Felker
2020-09-16  0:22 ` [PATCH v2 1/2] vfs: block chmod of symlinks Rich Felker
2020-09-16  6:18   ` Greg KH
2020-09-16  6:23     ` Christoph Hellwig
2020-09-16 15:36     ` Rich Felker
2020-09-16  6:25   ` Christoph Hellwig
2020-09-16 15:41     ` Rich Felker
2020-09-17  4:07     ` Al Viro
2020-09-17  4:15       ` Al Viro [this message]
2020-09-17 18:42         ` Rich Felker
2020-09-29 17:49         ` Christoph Hellwig
2020-09-16  0:23 ` [PATCH v2 2/2] vfs: add fchmodat2 syscall Rich Felker
2020-09-16  6:01   ` Aleksa Sarai
2020-09-16  6:19   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200917041503.GT3421308@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=dalias@libc.org \
    --cc=hch@infradead.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox