Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp778508rdb; Sun, 28 Jan 2024 08:31:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIRG89TVaVF5uB1GqUQ0we30KA92E980rNvEgHpf1bJL1yOCbL90FGdrPpsnPghLEaDKuw X-Received: by 2002:a17:906:eb44:b0:a33:1d7d:912f with SMTP id mc4-20020a170906eb4400b00a331d7d912fmr3094139ejb.8.1706459492093; Sun, 28 Jan 2024 08:31:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706459492; cv=pass; d=google.com; s=arc-20160816; b=cHlUCHlpB+BXVoeVlR8+dX0a6knpcHgHYkNyyxOb+Kifd3EXzI4x87+W+IuJMUGlB5 DFA7jRjj1h6MfDBGugkfE7e29rc6krCawvh9Pjo/c2UgcRFEGyce3jwtcNIQ9ScoTaEF 6zXZG++PmitVmrUgmlKygTeA/800wqgyC3du9Qv3nkB41LZIXuro7FUG1eNvuSMRd1Za Ih20UFaI0fJ4A99L0dCLKf2AW6cBCO2GkkJ5Nm8DpX29bdxMJP6c0OMq6rIgyvvxWJ8N nm4CzQcjqSQUdqYFoN7uvNyoAlUkAnX/5VFYXm8dnmQLkpcVuaxjw3MCXi9ewq4yEdUU z43w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BzgqPznljrdHkAot8LmfBlPvbG2agIRDMD6adJuooW4=; fh=6ugEFvPW3ynj+0vd/MwDXlTxmUWEyjggFuNt1zE5E7Y=; b=sYJPkca/4ut5fG8zahHlhqSys1yoI/Xm+kpbN7SH/f82f/GcHvOdQn7svwe6crmVFh arYWN6Trrg/l22em96fzs/O6UuwodgOJtvxsq4sklRb2pTUzLhZNeyLHAZJ7oj1I5U1M 7vabjpq4iMSlCHjulDGpY6eNgtOoujXxZQmbjL2T5UY3h97gjSVQPqFmWe0M1CPDIlaZ H1cTUQtjD/j7d5ZUiOQKFvAqaTlXU0uF7B958HCBJGAqCo2GpKa605yJSSHm3Un38khg wZO3PVPRsmGLpzLZkvVlGIS+H7tC08ISx8c+b0QBoVqiqNnCK/HNReb+iIXUDttzdZKm XHTA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LaGLwdWW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41693-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41693-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a13-20020a1709066d4d00b00a35a659ca48si322435ejt.473.2024.01.28.08.31.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 08:31:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41693-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LaGLwdWW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41693-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41693-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8FC691F22A81 for ; Sun, 28 Jan 2024 16:14:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C80645BF9; Sun, 28 Jan 2024 16:11:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LaGLwdWW" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C84D345979; Sun, 28 Jan 2024 16:11:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706458311; cv=none; b=dNuGQN+EaKC8MoK06FSN2gmNKMXH1mXxbejgIpsIGtpYfO+L/QknIKRGiLhmtoReYi5K4fUyqMMFzQuQdvr5u0ltsyHLIwYBvJP4WPTalgJ4LICmVxPzub9OJ28UV647A1BjSQByt7oSr8NxcubnlEVUqxNKCi2YcgZU7yNQr0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706458311; c=relaxed/simple; bh=uMnD0aUO2l3M2khXx2m/8Vx9nla+p5h2CdRabr2cOEM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k2t0N4dlCT3VCul1VWPc+zIg3+V3DcJFNoV4ZKTZk3cupg+HBgbupLh50jJs/2YUapdAtkWLZCK1DZZX7HP5ff7IJVkW4JQ9G+DHulsQLHcKah1njZz5O3zX1EwPYgEDacrKGbK6G/CTkvi/MLwiua6zuZN35GIPh3lCXK/dmJ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LaGLwdWW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC2DAC433F1; Sun, 28 Jan 2024 16:11:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706458311; bh=uMnD0aUO2l3M2khXx2m/8Vx9nla+p5h2CdRabr2cOEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LaGLwdWWi9AL7Y3QMPGSS8GQ1hOKKUTXpo311vhBalW/LC0tsIUfU4AIymZ4w1S/6 Pe0j2kFwQoiPPeWFGwSkOPoApcft+h05zoDHawbZiCe3TnH1DuPj8c9IvNV2yGJ47g BqiSHM+4sLXaC2Ps9FAkIsaOE1CYjZtr1yes0SzvOKlsKe6rkiTamrrKzy9/uAVGC9 ju8uwEn6JhZLZNt3x5eqh/GLaeFaV8Kv7Y7LwEjkLDlhx28dhWRO08YT3hekgeIIWB NR9qp73j3fOC8L6IlDMSIozTDKWgoCpNnnHPhxdk3xk9SE5LyspnO3frtGcmTWddh4 zQ6+oojchV+Wg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Max Kellermann , Tejun Heo , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 6.7 11/39] fs/kernfs/dir: obey S_ISGID Date: Sun, 28 Jan 2024 11:10:31 -0500 Message-ID: <20240128161130.200783-11-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240128161130.200783-1-sashal@kernel.org> References: <20240128161130.200783-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.7.2 Content-Transfer-Encoding: 8bit From: Max Kellermann [ Upstream commit 5133bee62f0ea5d4c316d503cc0040cac5637601 ] Handling of S_ISGID is usually done by inode_init_owner() in all other filesystems, but kernfs doesn't use that function. In kernfs, struct kernfs_node is the primary data structure, and struct inode is only created from it on demand. Therefore, inode_init_owner() can't be used and we need to imitate its behavior. S_ISGID support is useful for the cgroup filesystem; it allows subtrees managed by an unprivileged process to retain a certain owner gid, which then enables sharing access to the subtree with another unprivileged process. -- v1 -> v2: minor coding style fix (comment) Signed-off-by: Max Kellermann Acked-by: Tejun Heo Link: https://lore.kernel.org/r/20231208093310.297233-2-max.kellermann@ionos.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- fs/kernfs/dir.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 8b2bd65d70e7..62d39ecf0a46 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -676,6 +676,18 @@ struct kernfs_node *kernfs_new_node(struct kernfs_node *parent, { struct kernfs_node *kn; + if (parent->mode & S_ISGID) { + /* this code block imitates inode_init_owner() for + * kernfs + */ + + if (parent->iattr) + gid = parent->iattr->ia_gid; + + if (flags & KERNFS_DIR) + mode |= S_ISGID; + } + kn = __kernfs_new_node(kernfs_root(parent), parent, name, mode, uid, gid, flags); if (kn) { -- 2.43.0