Received: by 2002:aa6:c3ca:0:b029:c8:4414:5686 with SMTP id b10csp1829158lkq; Fri, 19 Mar 2021 12:58:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/dX9Tgekq3bf8MXOjBbJ31hAShuWCF7BgjIBSfQgSm6H28zsMG7RGdKVD05I1rHm61Fqs X-Received: by 2002:aa7:c98f:: with SMTP id c15mr11829031edt.231.1616183894131; Fri, 19 Mar 2021 12:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616183894; cv=none; d=google.com; s=arc-20160816; b=mRoirbxaZrcvxe5OoFtzCro9agSlR6qAwhAdPnyf67P1orjDYxxMPgN00SjhlCxaBK zWat9DoPXHu/xPlDZ9onM/hBc5wGQDUF5JE/Abkomg3izpAfSovSytrq/Xu5j9oHajgN v0uTSiKAoXScYVNseFUSsKCw5/imG2K3z9i63JoqL9AyswGhl1OA579j2Q+9OznLsXOE +c2Cyaal88aiAJQLzBNPpZGqMcqCV57Wzd4SaDHT51IGtUB428LSu1fVEDHNaPUlduQ9 oWHooLlTbQEd80cb91J8/VxSUz2ibLABpfb41DKIyq8lHYdIhtnZsIuvkexPlaJ2rRi2 9jtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l8vf0ntv6vZtHIIlnMnshk7MthH0lMBrpY+YvS+Cm2U=; b=X1+zJlOvp7w8FPK/wS5AxUN2TRgQkT2yRMS38dvfQ6DE8ifugYd3RnOBPCJZMtti3O 2S7OlFMkZ2tvfv/lMC7/oVrFeZPVppF/CLn/fUvogBkVQ3m58DBHbbtghlHlChRt4gpg rZjZqFFHOiaRl1b0qsYoXfL0+U04LUgZgjriTvN+TVkT08/YXXzbKuvgzw8hKVEKqGty +eQfScyxr8zk7aJVPmL2TpKhbQDPMoJIqvE5rlU2bkKrzyGi2CAL08jh6B4omLpscxBZ cdlwqUxoc6rxp1JGHuV4AKUTZb/Ynr2Sy42FCtTnjKbIiwQU5AxuYUNwedDh8oqQfp59 JjpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="JZ/7Cuu5"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz16si4874174ejb.586.2021.03.19.12.57.51; Fri, 19 Mar 2021 12:58:14 -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=pass header.i=@redhat.com header.s=mimecast20190719 header.b="JZ/7Cuu5"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbhCST4p (ORCPT + 99 others); Fri, 19 Mar 2021 15:56:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28778 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbhCST4M (ORCPT ); Fri, 19 Mar 2021 15:56:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616183771; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l8vf0ntv6vZtHIIlnMnshk7MthH0lMBrpY+YvS+Cm2U=; b=JZ/7Cuu5ydap0IChg8AvLMnYvmnM/NI459SBz9oKeAgh7tjFZ4ForuJV+0BEWV1uMdwMl9 kAMybfNokCtryrjEfjOGX60VkBntSARCG1Fv0LDKRVFnjs86QGoJpDP0qYs/X9XYDHcpLu dXD79mj+JrqtDTqFnUvNBrQh/UsIJmo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-453-aeLBLauOORuScnfHdMkD6w-1; Fri, 19 Mar 2021 15:56:08 -0400 X-MC-Unique: aeLBLauOORuScnfHdMkD6w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8270D839A44; Fri, 19 Mar 2021 19:56:06 +0000 (UTC) Received: from horse.redhat.com (ovpn-114-114.rdu2.redhat.com [10.10.114.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id C25D516E3A; Fri, 19 Mar 2021 19:56:02 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 3C5D9223D98; Fri, 19 Mar 2021 15:56:02 -0400 (EDT) From: Vivek Goyal To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, virtio-fs@redhat.com, miklos@szeredi.hu Cc: vgoyal@redhat.com, lhenriques@suse.de, dgilbert@redhat.com, seth.forshee@canonical.com, Jan Kara , Andreas Gruenbacher , Alexander Viro Subject: [PATCH 1/3] posic_acl: Add a helper determine if SGID should be cleared Date: Fri, 19 Mar 2021 15:55:45 -0400 Message-Id: <20210319195547.427371-2-vgoyal@redhat.com> In-Reply-To: <20210319195547.427371-1-vgoyal@redhat.com> References: <20210319195547.427371-1-vgoyal@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; +} + /* posix_acl.c */ extern void posix_acl_init(struct posix_acl *, int); -- 2.25.4