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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 746BCC433E5 for ; Sat, 20 Mar 2021 10:51:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 344BB619E3 for ; Sat, 20 Mar 2021 10:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229756AbhCTKv1 (ORCPT ); Sat, 20 Mar 2021 06:51:27 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:46712 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbhCTKvV (ORCPT ); Sat, 20 Mar 2021 06:51:21 -0400 Received: from mail-ed1-f72.google.com ([209.85.208.72]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lNYS5-0004S0-K1 for linux-fsdevel@vger.kernel.org; Sat, 20 Mar 2021 10:03:25 +0000 Received: by mail-ed1-f72.google.com with SMTP id o15so24334431edv.7 for ; Sat, 20 Mar 2021 03:03:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=6xT9jeCPBXNdoVrmRy60VcYXZbqaQTYKy1zemjeU5tQ=; b=LD5o6GlvhjvnbkviERDCQqT9QeEtqwlfRjK8EyLN1+vP34BShBoIzfrWV112Ta7Klt no7/nHE86RQCddTLUl8vCOKCIeIXhtvNd+KX6bg53uUuClRwRNyp7H/MTFclMJTW1RAE alV3gFGJNsxRZtL3ZQlgnD7B3ibSGcWj9p10A0P+x8fHFJDBqy0Fx4h6yWU2rLpJEUys wWUS4HEhwvJvgP9aC/MQDMtjDvjCMIt8dyvy7Nfsj3rugL9C67lW4x3B0CrsIGJs1qYR 7fXprforiDRp3qzjSeHW/kF4dGi3yhhoQAIPgn/5qYPMTIibfmFH6iFlPp7VtYZWaGHq Bhtg== X-Gm-Message-State: AOAM533c0OLQh9owBYoMBDh49sKIckTlpcxpqbMqId9IU1XyfQdbOZP1 F523Ifq8d0x1XtbgKi3fndZMNU/CnBQ9RZPGlTy6jz5c8ZS8AF8oKkFO8f5Wde9HzzFGFDCUOEQ 15gr91APYf5hpWdKz2JG5u9SRC4Qf7TVB8PgGel5HSL8= X-Received: by 2002:a17:906:9bc5:: with SMTP id de5mr9107548ejc.284.1616234605198; Sat, 20 Mar 2021 03:03:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMnEtYNqzI5L7gpZLlQlj1az6CLbmQYLoAqJ72bRRK64C3vgPnc7jNhufbCQEfX8lOBrCj7A== X-Received: by 2002:a17:906:9bc5:: with SMTP id de5mr9107519ejc.284.1616234604964; Sat, 20 Mar 2021 03:03:24 -0700 (PDT) Received: from gmail.com (ip5f5af0a0.dynamic.kabel-deutschland.de. [95.90.240.160]) by smtp.gmail.com with ESMTPSA id p3sm5027921ejd.7.2021.03.20.03.03.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 03:03:24 -0700 (PDT) Date: Sat, 20 Mar 2021 11:03:22 +0100 From: Christian Brauner To: Andreas =?utf-8?Q?Gr=C3=BCnbacher?= Cc: Vivek Goyal , Linux FS-devel Mailing List , Linux Kernel Mailing List , virtio-fs@redhat.com, Miklos Szeredi , lhenriques@suse.de, dgilbert@redhat.com, Seth Forshee , Jan Kara , Andreas Gruenbacher , Alexander Viro Subject: Re: [PATCH 1/3] posic_acl: Add a helper determine if SGID should be cleared Message-ID: <20210320100322.ox5gzgauo7iqf2fv@gmail.com> References: <20210319195547.427371-1-vgoyal@redhat.com> <20210319195547.427371-2-vgoyal@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Fri, Mar 19, 2021 at 11:42:48PM +0100, Andreas Grünbacher wrote: > Hi, > > Am Fr., 19. März 2021 um 20:58 Uhr schrieb Vivek Goyal : > > posix_acl_update_mode() determines what's the equivalent mode and if SGID > > needs to be cleared or not. I need to make use of this code in fuse > > as well. Fuse will send this information to virtiofs file server and > > file server will take care of clearing SGID if it needs to be done. > > > > Hence move this code in a separate helper so that more than one place > > can call into it. > > > > Cc: Jan Kara > > Cc: Andreas Gruenbacher > > Cc: Alexander Viro > > Signed-off-by: Vivek Goyal > > --- > > fs/posix_acl.c | 3 +-- > > include/linux/posix_acl.h | 11 +++++++++++ > > 2 files changed, 12 insertions(+), 2 deletions(-) > > > > diff --git a/fs/posix_acl.c b/fs/posix_acl.c > > index f3309a7edb49..2d62494c4a5b 100644 > > --- a/fs/posix_acl.c > > +++ b/fs/posix_acl.c > > @@ -684,8 +684,7 @@ int posix_acl_update_mode(struct user_namespace *mnt_userns, > > return error; > > if (error == 0) > > *acl = NULL; > > - if (!in_group_p(i_gid_into_mnt(mnt_userns, inode)) && > > - !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID)) > > + if (posix_acl_mode_clear_sgid(mnt_userns, inode)) > > mode &= ~S_ISGID; > > *mode_p = mode; > > return 0; > > diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h > > index 307094ebb88c..073c5e546de3 100644 > > --- a/include/linux/posix_acl.h > > +++ b/include/linux/posix_acl.h > > @@ -59,6 +59,17 @@ posix_acl_release(struct posix_acl *acl) > > } > > > > > > +static inline bool > > +posix_acl_mode_clear_sgid(struct user_namespace *mnt_userns, > > + struct inode *inode) > > +{ > > + if (!in_group_p(i_gid_into_mnt(mnt_userns, inode)) && > > + !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID)) > > + return true; > > + > > + return false; > > That's just > > return !in_group_p(i_gid_into_mnt(mnt_userns, inode)) && > !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID); > > The same pattern we have in posix_acl_update_mode also exists in > setattr_copy and inode_init_owner, and almost the same pattern exists > in setattr_prepare, so can this be cleaned up as well? The function > also isn't POSIX ACL specific, so the function name is misleading. Good idea but that should probably be spun into a separate patchset that only touches the vfs parts. Christian