Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1212254pxk; Thu, 10 Sep 2020 09:39:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxN5K55ZgraM7djim4t050BoPMIS4dsOwL4b2/oR7CxEtLtBJhK4G3+SsKbfwDaPHMysqBu X-Received: by 2002:a05:6402:1d29:: with SMTP id dh9mr10637561edb.124.1599755970117; Thu, 10 Sep 2020 09:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599755970; cv=none; d=google.com; s=arc-20160816; b=XeyjpjS2ZvYdNXFLWRVKBg7aZKbt435MOIudc4qT7n88uQXdm81IRaQbGoBXT5cPey ErHDrNZdL5namdLW+H5rhTO8nRTG8a7BfCgaz9cIot2GISH9uWAEDcdff7goEYmA1Hfm oTzzvTLWPiEqx2z5c299W2Cvm5oZMbpSTuU+ZAtq67oYEFCLHYqPnhSl6aRILVgRYIzv NF2rcoW2abeTS2kHTSLplcFLN9w6CfZr+uquUGiieQgVv9bImeYW1q4oDFRL2Q2paxx8 Exu/c3jNWOaP0000YTnIoETAwmZ6Q1rgH86aHlSL2JC+G/Z+LnODwgVQxmOebVs03zPs dsSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=W8YeWR3pj7zWIXtRN//sgjuiHeme27wEpLYCU6/hm9M=; b=IdJQ6gzGAhAZWXEhfUfV2r6ue8+pwu+Mx7QFHBA3ViWeurld1/vTY9AFD/1pqJ2XYZ x0J8GC6KYJa7knEH/N2GKEEXjlk5nN+0/71J8TJiHqCQ7XSiyEd9qH8xf8WZya8rmSOh XnllnhCpTp3ALcmvJyZyyHMiBaphWloOT9VJY4OqCP0g9PmuuzjXzLFh3knj5XQ2vWT4 DD0hfsOlS3rRBrt/JhdrHCxP1RZ6W+oI+ZSABlO4eOiYSowZYzFaiTsDdPszPvC/Q251 LcTFiRmTKR5yvBxTmYb0ApbmcdOZC034TUsjIjTleXgVFkQOXt2Kk9/ZPQbKugF6+riU CD8A== 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 d6si3996288ejm.636.2020.09.10.09.39.06; Thu, 10 Sep 2020 09:39:30 -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 S1726109AbgIJQhz (ORCPT + 99 others); Thu, 10 Sep 2020 12:37:55 -0400 Received: from brightrain.aerifal.cx ([216.12.86.13]:52458 "EHLO brightrain.aerifal.cx" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726853AbgIJQfw (ORCPT ); Thu, 10 Sep 2020 12:35:52 -0400 Date: Thu, 10 Sep 2020 12:35:24 -0400 From: Rich Felker To: Greg KH Cc: linux-api@vger.kernel.org, Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vfs: add fchmodat2 syscall Message-ID: <20200910163524.GI3265@brightrain.aerifal.cx> References: <20200910142335.GG3265@brightrain.aerifal.cx> <20200910161615.GA1180022@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200910161615.GA1180022@kroah.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 10, 2020 at 06:16:15PM +0200, Greg KH wrote: > On Thu, Sep 10, 2020 at 10:23:37AM -0400, Rich Felker wrote: > > POSIX defines fchmodat as having a 4th argument, flags, that can be > > AT_SYMLINK_NOFOLLOW. Support for changing the access mode of symbolic > > links is optional (EOPNOTSUPP allowed if not supported), but this flag > > is important even on systems where symlinks do not have access modes, > > since it's the only way to safely change the mode of a file which > > might be asynchronously replaced with a symbolic link, without a race > > condition whereby the link target is changed. > > > > It's possible to emulate AT_SYMLINK_NOFOLLOW in userspace, and both > > musl libc and glibc do this, by opening an O_PATH file descriptor and > > performing chmod on the corresponding magic symlink in /proc/self/fd. > > However, this requires procfs to be mounted and accessible. > > > > It was determined (see glibc issue #14578 and commit a492b1e5ef) that, > > on some filesystems, performing chmod on the link itself produces a > > change in the inode's access mode, but returns an EOPNOTSUPP error. > > This is non-conforming and wrong. Rather than try to fix all the > > broken filesystem backends, block attempts to change the symlink > > access mode via fchmodat2 at the frontend layer. This matches the > > userspace emulation done in libc implementations. No change is made to > > the underlying chmod_common(), so it's still possible to attempt > > changes via procfs, if desired. If at some point all filesystems have > > been fixed, this could be relaxed to allow filesystems to make their > > own decision whether changing access mode of links is supported. > > A new syscall just because we have broken filesystems seems really odd, > why not just fix the filesystems instead? The part about broken filesystems is just the justification for doing the EOPNOTSUPP check at this layer rather than relying on the filesystem to do it, not the purposse for the syscall. The purpose of the syscall is fixing the deficiency in the original one, which lacked the flags argument, making it so you have to do a complicated emulation dance involving O_PATH and procfs magic symlinks to implement the standard functionality. Rich