Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp833634rwb; Mon, 26 Sep 2022 06:29:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5yP64lN4vjMHBhw+Bshl2SsdoLIxTftqeALglINc6aob0tbahaDvskGhcfBXCcFwzljeyq X-Received: by 2002:a17:907:3e0f:b0:782:dc11:da99 with SMTP id hp15-20020a1709073e0f00b00782dc11da99mr10678718ejc.499.1664198980089; Mon, 26 Sep 2022 06:29:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198980; cv=none; d=google.com; s=arc-20160816; b=VqfV/5Z6db/kop8iQLFECr8ZziGiHgo1zb7gWxMM0bbxR4n9lNHnS3O2MHmVrZ6dpE aDwKSvP1+lJxII8vwONU7mGLs+YFBU525Y51y8hs3M2hEEavUytmBVrINPHxstg8feXE aiVITo2xcOKSZK52vp8ST7RaNVOGC8c+vNTSZMtlTslBNngMGdQo1sXVU+5/F1spsngI I7CPPFj6D0E861pSykr/Q++9Xa6vYj8E8oUoZmZhP8//EwtlcN0XBardh9S8+mplc9J9 eeKTFWmMdyYGM0MQFm/f3lStxRChTwIQnVIqmFP1mRpfjXkiB9R4RSLPPTZ15R1kAtLc xnXg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wD61wOTvx3zZza06Nqffz1o9nPZHD7eEEUfbTQ9Fd+s=; b=PcLPtkatxcIBonzkgT8zfFAbAKRkLCbzADRXNdoIDfLjJh8AEApg2juXeN5vLm2Cyc xLoKjc5+Q6Zg6lK6uysi0LYjuWKY7R0dcML6HYBC2v7kuhdLqeTZ5ItIXBJ/wkg41xE6 vA5CtXCFo1AfIxvGuTSGZy/NpW0DBshfz9db6NF9MirRjw3yCfgePENjJvNLvKDot1vX qfPBfT/yknGq8SCGXDhCdUcQ3umF5jqglTrANm7qG5TygHid/+7BLXQjbUPk8NSPnNEX u7aSqkp0qxs8aaRxz07d2XLJQwFEr8GEDacLk8n7uN9+qPxtUsdFtK5pgjUwZARa2qqO eioA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yM6/OrFa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w18-20020a056402269200b004546d8c2a18si18388733edd.187.2022.09.26.06.29.14; Mon, 26 Sep 2022 06:29:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yM6/OrFa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239465AbiIZM0c (ORCPT + 99 others); Mon, 26 Sep 2022 08:26:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239437AbiIZMZn (ORCPT ); Mon, 26 Sep 2022 08:25:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F218FAB4EE; Mon, 26 Sep 2022 04:06:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 74AF2B8092B; Mon, 26 Sep 2022 10:30:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBA0DC433D7; Mon, 26 Sep 2022 10:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188254; bh=NryZB3Ybd6APvn/0eYP21OrMJqs15ALEa9AN7nDLQww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yM6/OrFaaV9oztEUP1cRBHs3pAvpmyDOY5WLkJF6puf0ys3R35ETcnfPpMDeffgZR oJBE9RbHj1DFIf4BUi9UTl+eoNxbItKeD+3CamF/W+RZGxULey64aD24PzRCJydI1V /ybZOlcOGduVcyxhcbzBo5eZNtNe7Cdzy2GN4kAc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Brauner , Christoph Hellwig , "Darrick J. Wong" , Amir Goldstein Subject: [PATCH 5.10 060/141] xfs: fix up non-directory creation in SGID directories Date: Mon, 26 Sep 2022 12:11:26 +0200 Message-Id: <20220926100756.624113733@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100754.639112000@linuxfoundation.org> References: <20220926100754.639112000@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig commit 01ea173e103edd5ec41acec65b9261b87e123fc2 upstream. XFS always inherits the SGID bit if it is set on the parent inode, while the generic inode_init_owner does not do this in a few cases where it can create a possible security problem, see commit 0fa3ecd87848 ("Fix up non-directory creation in SGID directories") for details. Switch XFS to use the generic helper for the normal path to fix this, just keeping the simple field inheritance open coded for the case of the non-sgid case with the bsdgrpid mount option. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Christian Brauner Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Amir Goldstein Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_inode.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -802,6 +802,7 @@ xfs_ialloc( xfs_buf_t **ialloc_context, xfs_inode_t **ipp) { + struct inode *dir = pip ? VFS_I(pip) : NULL; struct xfs_mount *mp = tp->t_mountp; xfs_ino_t ino; xfs_inode_t *ip; @@ -847,18 +848,17 @@ xfs_ialloc( return error; ASSERT(ip != NULL); inode = VFS_I(ip); - inode->i_mode = mode; set_nlink(inode, nlink); - inode->i_uid = current_fsuid(); inode->i_rdev = rdev; ip->i_d.di_projid = prid; - if (pip && XFS_INHERIT_GID(pip)) { - inode->i_gid = VFS_I(pip)->i_gid; - if ((VFS_I(pip)->i_mode & S_ISGID) && S_ISDIR(mode)) - inode->i_mode |= S_ISGID; + if (dir && !(dir->i_mode & S_ISGID) && + (mp->m_flags & XFS_MOUNT_GRPID)) { + inode->i_uid = current_fsuid(); + inode->i_gid = dir->i_gid; + inode->i_mode = mode; } else { - inode->i_gid = current_fsgid(); + inode_init_owner(inode, dir, mode); } /*