From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11807C433E2 for ; Thu, 25 Mar 2021 15:20:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D429661A38 for ; Thu, 25 Mar 2021 15:20:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231464AbhCYPUV (ORCPT ); Thu, 25 Mar 2021 11:20:21 -0400 Received: from zeniv-ca.linux.org.uk ([142.44.231.140]:58720 "EHLO zeniv-ca.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230095AbhCYPUD (ORCPT ); Thu, 25 Mar 2021 11:20:03 -0400 Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1lPRjt-009CM7-Rc; Thu, 25 Mar 2021 15:17:38 +0000 Date: Thu, 25 Mar 2021 15:17:37 +0000 From: Al Viro To: Miklos Szeredi Cc: Eric Biggers , Miklos Szeredi , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Dilger , Andreas Gruenbacher , Christoph Hellwig , "Darrick J . Wong" , Dave Kleikamp , David Sterba , Jaegeuk Kim , Jan Kara , Joel Becker , Matthew Garrett , Mike Marshall , Richard Weinberger , Ryusuke Konishi , Theodore Ts'o , Tyler Hicks Subject: Re: [PATCH 01/18] vfs: add miscattr ops Message-ID: References: <20210203124112.1182614-1-mszeredi@redhat.com> <20210203124112.1182614-2-mszeredi@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 25, 2021 at 03:52:28PM +0100, Miklos Szeredi wrote: > On Tue, Mar 23, 2021 at 1:24 AM Eric Biggers wrote: > > > > +int vfs_miscattr_set(struct dentry *dentry, struct miscattr *ma) > > > +{ > > > + struct inode *inode = d_inode(dentry); > > > + struct miscattr old_ma = {}; > > > + int err; > > > + > > > + if (d_is_special(dentry)) > > > + return -ENOTTY; > > > + > > > + if (!inode->i_op->miscattr_set) > > > + return -ENOIOCTLCMD; > > > + > > > + if (!inode_owner_or_capable(inode)) > > > + return -EPERM; > > > > Shouldn't this be EACCES, not EPERM? > > $ git diff master.. | grep -C1 inode_owner_or_capable | grep > "^-.*\(EPERM\|EACCES\)" | cut -d- -f3 | sort | uniq -c > 12 EACCES; > 4 EPERM; > > So EACCES would win if this was a democracy. However: > > "[EACCES] > Permission denied. An attempt was made to access a file in a way > forbidden by its file access permissions." > > "[EPERM] > Operation not permitted. An attempt was made to perform an operation > limited to processes with appropriate privileges or to the owner of a > file or other resource." > > The EPERM description matches the semantics of > inode_owner_or_capable() exactly. It's a pretty clear choice. Except that existing implementation (e.g. for ext2) gives -EACCES here... OTOH, EPERM matches the behaviour of chown(2), as well as that of *BSD chflags(2), which is the best match to functionality (setting and clearing immutable/append-only/etc.) So I'd probably go with EPERM, and watched for userland breakage; if something *does* rely upon the historical EACCES here, we might have to restore that.