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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECCA1C4332F for ; Mon, 18 Apr 2022 03:09:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235957AbiDRDLi (ORCPT ); Sun, 17 Apr 2022 23:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233152AbiDRDLh (ORCPT ); Sun, 17 Apr 2022 23:11:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36775186F9; Sun, 17 Apr 2022 20:08:59 -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=Cr0CVOdS5okWrJVBplWYDXiXksMwwPiOAV0K2em79Qw=; b=Lq6N9I9OQl8ZiOp+wKe9GGd1X3 cMMaJLRrsuevLRaK4khhCJYxxCBoKL/mXsZlAJ72jCyG94owuVXAXJVmAgTGJ10ND/3fvdOywPfXk 51dhD82AtEdlNPJYa9a1Rj7Sc2jEtYvI7SMg9DYpnvIOeMS138kaFdXx92+C2Po53BTcEBKb6M/7+ f5jdSvmGXz3sa08efWBnfJ9Ievcp8P6+4Q059t4y+DJ90NfI6pZfQ30ToP2gIvWILVVgnwf+6aDNS LvUK1uZNvz+JKNdhwMvbD9xgPp8zRCxELk6TLmkQ8hUG/6c8Bh7L5butrNV5IKOPjHxy/3IpTMa9x iO3QAJTA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngHkx-001l2F-RE; Mon, 18 Apr 2022 03:08:51 +0000 Date: Mon, 18 Apr 2022 04:08:51 +0100 From: Matthew Wilcox To: Christian Brauner Cc: Yang Xu , david@fromorbit.com, djwong@kernel.org, linux-fsdevel@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, viro@zeniv.linux.org.uk, jlayton@kernel.org Subject: Re: [PATCH v3 1/7] fs/inode: move sgid strip operation from inode_init_owner into inode_sgid_strip Message-ID: References: <1650020543-24908-1-git-send-email-xuyang2018.jy@fujitsu.com> <20220415140924.oirar6dklelujnxs@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220415140924.oirar6dklelujnxs@wittgenstein> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Fri, Apr 15, 2022 at 04:09:24PM +0200, Christian Brauner wrote: > > + inode_sgid_strip(mnt_userns, dir, &mode); > > } else > > inode_fsgid_set(inode, mnt_userns); > > inode->i_mode = mode; > > @@ -2405,3 +2403,21 @@ struct timespec64 current_time(struct inode *inode) > > return timestamp_truncate(now, inode); > > } > > EXPORT_SYMBOL(current_time); > > + > > +void inode_sgid_strip(struct user_namespace *mnt_userns, > > + const struct inode *dir, umode_t *mode) > > +{ > > + if (!dir || !(dir->i_mode & S_ISGID)) > > + return; > > + if ((*mode & (S_ISGID | S_IXGRP)) != (S_ISGID | S_IXGRP)) > > + return; > > + if (S_ISDIR(*mode)) > > + return; > > I'd place that check first as this whole function is really only > relevant for non-directories. > > Otherwise I can live with *mode being a pointer although I still find > this unpleasant API wise but the bikeshed does it's job without having > my color. :) No, I think your instincts are correct. This should be umode_t inode_sgid_strip(struct user_namespace *mnt_userns, const struct inode *dir, umode_t mode) { if (S_ISDIR(mode) || !dir || !(dir->i_mode & S_ISGID)) return mode; if (mode & (S_ISGID | S_IXGRP) != (S_ISGID | S_IXGRP)) return mode; ... and the same for prepare_mode(). And really, I think this should be called inode_strip_sgid(). Right?