Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp646306pxk; Thu, 17 Sep 2020 12:12:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR4sJeqlh2ixsmayTouSNbyP7LUgavJ+G2i3nP+FDA1h8mc31jI34WBx5bBcNEiN0jf4td X-Received: by 2002:a17:906:1157:: with SMTP id i23mr25510500eja.440.1600369960587; Thu, 17 Sep 2020 12:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600369960; cv=none; d=google.com; s=arc-20160816; b=YOUZZHAZYGu9jRf62CFIFpBpTtejqanfduLQfLvHADL/DX9Zk6G8dNwtgkPPoYIEhm rLrQT8RnraNE6HF1IfzbLBRLJcU64Uh2Ihe/mvFXjmCCOHT0UZrclW37eFA2CEcBKz3G b1iZRM7YFQYG91u6MMW72VSqNAHZ0nZn5fuC9Hp3yLkqQhsD36cykYcj/8KA1O0JBZ+n 4k2inNOvyGxEZhMFM+DA4CzqaxQ50Qdlu0DAQ1rp5c7CQSUr8KAZydbPnFE4MmbFQmYY lTgpBetOcsM+Vo2rtIKrU5rE1LzhgrKuNmR1BSq+tP33zgbagZD9ERbHvC2U25FSCuHV guhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=bsQKqxvUF8b8k2ufxVPiw7oLJ3aDPfVcDaM8FIvuAx4=; b=X11Ghtt2kPYZMG5qI8+mNc0PgRVEfzxJd1FWkv4lidVfFhOA6iuuptczSpXjywleFl 3r8BglggYNXhNclRqGov5G6MPkZkvUVuAarcqrHiDhAP6SY2kIZgi+ofoOGcPmSrm1qE 6zYkiaX3E7qhPw9zjA/+fPuA/wvE7/DiVMbqtbi7q/SBE0aV5VwvD+4DM7tz2sVbA7LK TEupnuvuXnkmXRpEHjh9ar8HzIb95zRL/joicvE7LPEBy7s9nh/fkS5lnOcK8Jlo/E0a 64CXU4tSOGUkV3XG3ZMixIzeF7rcQT0xzrq3Z71Wn4lQ7qo6Nq19K7OuV3jJfoymMHEr byBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w7si538367ejf.3.2020.09.17.12.12.17; Thu, 17 Sep 2020 12:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726383AbgIQTIQ (ORCPT + 99 others); Thu, 17 Sep 2020 15:08:16 -0400 Received: from brightrain.aerifal.cx ([216.12.86.13]:54468 "EHLO brightrain.aerifal.cx" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726633AbgIQS6E (ORCPT ); Thu, 17 Sep 2020 14:58:04 -0400 X-Greylist: delayed 914 seconds by postgrey-1.27 at vger.kernel.org; Thu, 17 Sep 2020 14:58:03 EDT Date: Thu, 17 Sep 2020 14:42:46 -0400 From: Rich Felker To: Al Viro Cc: Christoph Hellwig , 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 Message-ID: <20200917184245.GW3265@brightrain.aerifal.cx> References: <20200916002157.GO3265@brightrain.aerifal.cx> <20200916002253.GP3265@brightrain.aerifal.cx> <20200916062553.GB27867@infradead.org> <20200917040715.GS3421308@ZenIV.linux.org.uk> <20200917041503.GT3421308@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200917041503.GT3421308@ZenIV.linux.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 17, 2020 at 05:15:03AM +0100, Al Viro wrote: > 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 > > > > --- > > > > 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; Does this make chmod of links behave consistently (either succeeding with return value 0, or returning -EOPNOTSUPP without doing anything) for all filesystems? I'm fine with (and would probably prefer) this fix if it's a complete one. If this goes in I think my patch 1/2 can just be dropped and patch 2/2 behaves as intended; does that sound correct to you? Rich