Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp131333pxk; Tue, 15 Sep 2020 23:27:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOL+GmkYEilXs4zpsfeIrlb7l4O1nh2jv12pTqYT4fuuyiYTDgsbfT46p1Vu47klIuNczB X-Received: by 2002:aa7:d747:: with SMTP id a7mr25204968eds.304.1600237630729; Tue, 15 Sep 2020 23:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600237630; cv=none; d=google.com; s=arc-20160816; b=JnNGyg0eKg/Z43KApoUSQe8mC7bLm97qE3gG8Pq9mXXyCstebQZLFcUU+8DNkPVKmv i/yrfd+lZbf5z/vMYTsUkKjYmCkgWANRT37aCX06d6myFL/GXGPZ1zZhh40EmkKz+4Zw ZMOY17BBbF6G2o37VxuggPd9nBrVlrZs9DcKodxmoa4VQyrlis4wi4Xwz3ASAk3EcQRW VtNPNX4jYzAo13R2yslU2HjyicmRtwqtJIgbmG1MEVQ58z0ZzO0n9rq1Q1PqTmw4c8X+ +eQIivFdKki9fxjzcFdQ+hEkOIFooAbVxzq5g394CnV7t/QjIifbQkrTp4A3jlAj8MnV ci7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=5DkGrdwtKboVv6oJ+L5ofbnVJYprbMvRcR1X/5Ks8Fk=; b=q36FmF8JyEVTLqaROqnXi2adSmqMzeYiHE7G6DD/wdO7Ccv9E99LX9QQZwRQ8z6kui PC4S4rLRjplq9WWZnvUVyxTOd/zM4RuLfzP1MRxyVssMn6fhOiEZW3nefHlQGl8kwMuo Ai6qSld0dNCBCpVRLpM65yjAicL9nAcF3iZIIwyp/AshbI7ldiKki+E6haOKGsQTlUt4 6d0p12IKquVd9Zzs3hmIFtlVYrYzgAkPDxkT6qD+0/x2O8P1sjrJR6FSZrFllWMXC4E8 rf2Fe9lCxddyM5bRT009dmm+gw8HpnFBdssNoTwoPRUYvefz2NXIIXau71Vn3vMy+Agm ItXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=NwUKULRa; 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 x13si3097932ejj.368.2020.09.15.23.26.48; Tue, 15 Sep 2020 23:27:10 -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; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=NwUKULRa; 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 S1726335AbgIPG0C (ORCPT + 99 others); Wed, 16 Sep 2020 02:26:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726136AbgIPGZ4 (ORCPT ); Wed, 16 Sep 2020 02:25:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 164ABC06174A; Tue, 15 Sep 2020 23:25:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=5DkGrdwtKboVv6oJ+L5ofbnVJYprbMvRcR1X/5Ks8Fk=; b=NwUKULRasoHoDh5Re+0oSBPoOy cVoFabxviFAt51K/mnHZ97XXOZDkQYezTtUKQ0Ug21qeRpaVtxtxlqn+eIJOMnGZoOeLK4h1mmPe1 Yk4ICgexAbxXc56SRoycT/PX2Gm6yHY7lBVC6Sh9BEdV5Rv760gEXf7Kkkwn8Qioq0xRniiS/DEbc jSn+Ax4XAc07B3QMykBleghV6+CZPmccpDA1gI8N6d1WKCCTIZY37pK1boZ/RYKw/qD1xJX+xLGyC jEjasxT5xSri6kUplc0O7LATOQY7MvfSqKgERkQd1Re11IPDbem7jREFTAgnH5WTBSUIgqUO4x98u p114gKbQ==; Received: from hch by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIQt7-0007XL-BE; Wed, 16 Sep 2020 06:25:53 +0000 Date: Wed, 16 Sep 2020 07:25:53 +0100 From: Christoph Hellwig To: Rich Felker Cc: linux-api@vger.kernel.org, Alexander Viro , Christoph Hellwig , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] vfs: block chmod of symlinks Message-ID: <20200916062553.GB27867@infradead.org> References: <20200916002157.GO3265@brightrain.aerifal.cx> <20200916002253.GP3265@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200916002253.GP3265@brightrain.aerifal.cx> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.