From patchwork Fri Dec 8 09:33:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 175696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5341893vqy; Fri, 8 Dec 2023 01:33:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnzgkMHxX6IDpQlZsGaTK5/zSG9VfMk2C7xt2yJynqmL6bMmLAAJCQeBP+pSJg+iYlnTvw X-Received: by 2002:a17:90a:df89:b0:28a:3b47:8081 with SMTP id p9-20020a17090adf8900b0028a3b478081mr335666pjv.18.1702028003289; Fri, 08 Dec 2023 01:33:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702028003; cv=none; d=google.com; s=arc-20160816; b=CoYvkDSpJVnXf+NTu+cqAExUxzk1tuw1kRtNXCVxAZMgKghFJhNd3N7g+sNyBrD2ud WFDRdJgDS+ug6a3FdmDJ+qshJnb2Uw3eXV8T2HEFN3FJls1yd0m0xePbi3tYojZGerPh woOgW8rJ3+AoaTZCjHQhHRzKpjWR1kl6ax/hCqpMbMXw2hjkziq3doNnty5ZDqNalgIg OwvrFAoDmnFymoRTsyYLDecI3+WYj/IEOmNLjztbYKRYkiHnj8zSNBnD6TGJFuC8mWMm 9jdVKxsr0OSTtI7pbdC2vAYs6nVrhOpk0XnHqqZovZ/GtWnVFOBo4hVrO++jjAcU86SP BttA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=L4rZ/GzRY7+TnTS+jdlOOGqRdC+4LjtAOi+pvi/VqV0=; fh=uUgNkyrv3JReNoTSO9y0jmTkBGsqHJqQkaGAGfDhVmw=; b=CRvb+KO/Sig+tZpbUOQF7fTqbwkFUgquQfl/s+wAH3dzbRCgcreil6CKpxX55OUb0u 256o0Gz33Ktst9u8CElyO7J0bI+5y5KPlzCkWNg+078w/yJZX7+xgPn8YAaCjhfWzI8/ Nr7FG6LvT8U0Rl2KoI/3b/VT2ap086IRxA7wRG+9mo6g4QIlpNRgGAZ1WvPyuKWfdVT6 UuAp9OjPKKV1MaZHBpDfnBjd06mynex00LmjxuQ1xAQM1Z23NBAd2WfIonB4if8qxciK IF3vjwu41C8asUx4b5Q4C286tGdtF0DGG2fpwI2pZLzOTekDLBmmtrDyU8DYGPVplznI 6HJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="JtuRaQ5/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id lb11-20020a17090b4a4b00b00286ae823308si1361248pjb.73.2023.12.08.01.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 01:33:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="JtuRaQ5/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 84313809B9C6; Fri, 8 Dec 2023 01:33:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233259AbjLHJdK (ORCPT + 99 others); Fri, 8 Dec 2023 04:33:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231863AbjLHJdJ (ORCPT ); Fri, 8 Dec 2023 04:33:09 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7521590 for ; Fri, 8 Dec 2023 01:33:14 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-54cb4fa667bso2641905a12.3 for ; Fri, 08 Dec 2023 01:33:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1702027993; x=1702632793; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=L4rZ/GzRY7+TnTS+jdlOOGqRdC+4LjtAOi+pvi/VqV0=; b=JtuRaQ5/qOG7u7fsHo5vA6j7INkvoMJWlC1UGGAfMSrIB7FIC1QukHG4FajC596zsl E1zj8nAleHRCoRTpXiDjrILm+XBC173B2tVZ/hXyw4X0pKJaAHNOTJPaEpTy59Xy4i0B 407bVZdzIkVKxG6nY8A/IktYMm9NrRWgwKyZpWkys9KDaJfM3ghOCgrvg+rsgp9THm2b BXA4lQGqmnt0CAaa063gwnxdn6t7vwb4GiASNoMfarZTk6f/hgKum1oJggoXgy5WTHtE wdbN0a3eyOep+cfChbuTdIhzES1l9V+AegXlBk8vKh+E8/6VkJ+bTZ0JH2BTDSxqMuW6 /7Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702027993; x=1702632793; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=L4rZ/GzRY7+TnTS+jdlOOGqRdC+4LjtAOi+pvi/VqV0=; b=qB/0ojJnClwL7CUMvPDnTTL47bmek+GWwKQnBtoe/ZkmvU3XOufCaRr84NNWg5MujT BZ3K3Ihzx+N45HVfXi84cYajBEIdtsMmiuWRcKVxc35JWpqwvRMrE0Fsblgg/0HxVf8f W3BTtTq6sg7DoHZcVnuvxQ9ple6py4uWdKPpMLUaYGbQE+SkL9+w7is4I4sAuh7/dQ35 BIVIIdpTmGDaYm7kt4MRw11ElYWyHtX+Inqh1sAaAC2quZw/n+t0LsvRrPQ3kyMRJqej W+ethr2r9CyDXN26sbbzYvFcyRntSDY57C+THy+K/pM4XFgYEoPKmHu+93R2NgSWEX0r 7zkA== X-Gm-Message-State: AOJu0YzVZB9Dx2lsMdZo0qhKI8ov/vzSvwr0S2ee7qjH+hg1DMqx19MS AW1DKGu2CTgXBBvpkuszpZ8yxA== X-Received: by 2002:a17:906:10ce:b0:a1e:1da1:73c0 with SMTP id v14-20020a17090610ce00b00a1e1da173c0mr1885941ejv.10.1702027992742; Fri, 08 Dec 2023 01:33:12 -0800 (PST) Received: from heron.intern.cm-ag (p200300dc6f0b6500529a4cfffe3dd983.dip0.t-ipconnect.de. [2003:dc:6f0b:6500:529a:4cff:fe3d:d983]) by smtp.gmail.com with ESMTPSA id vk5-20020a170907cbc500b00a1ce56f7b16sm774812ejc.71.2023.12.08.01.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 01:33:12 -0800 (PST) From: Max Kellermann To: Greg Kroah-Hartman , Tejun Heo , Zefan Li , Johannes Weiner , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Cc: Max Kellermann Subject: [PATCH v2 1/2] kernel/cgroup: use kernfs_create_dir_ns() Date: Fri, 8 Dec 2023 10:33:09 +0100 Message-Id: <20231208093310.297233-1-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 08 Dec 2023 01:33:19 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784705715124218416 X-GMAIL-MSGID: 1784705715124218416 By passing the fsugid to kernfs_create_dir_ns(), we don't need cgroup_kn_set_ugid() any longer. That function was added for exactly this purpose by commit 49957f8e2a43 ("cgroup: newly created dirs and files should be owned by the creator"). Eliminating this piece of duplicate code means we benefit from future improvements to kernfs_create_dir_ns(); for example, both are lacking S_ISGID support currently, which my next patch will add to kernfs_create_dir_ns(). It cannot (easily) be added to cgroup_kn_set_ugid() because we can't dereference struct kernfs_iattrs from there. Signed-off-by: Max Kellermann Acked-by: Tejun Heo Reviewed-by: Michal Koutný Tested-by: Bagas Sanjaya --- v1 -> v2: 12-digit commit id --- kernel/cgroup/cgroup.c | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 4b9ff41ca603..a844b421fd83 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -4169,20 +4169,6 @@ static struct kernfs_ops cgroup_kf_ops = { .seq_show = cgroup_seqfile_show, }; -/* set uid and gid of cgroup dirs and files to that of the creator */ -static int cgroup_kn_set_ugid(struct kernfs_node *kn) -{ - struct iattr iattr = { .ia_valid = ATTR_UID | ATTR_GID, - .ia_uid = current_fsuid(), - .ia_gid = current_fsgid(), }; - - if (uid_eq(iattr.ia_uid, GLOBAL_ROOT_UID) && - gid_eq(iattr.ia_gid, GLOBAL_ROOT_GID)) - return 0; - - return kernfs_setattr(kn, &iattr); -} - static void cgroup_file_notify_timer(struct timer_list *timer) { cgroup_file_notify(container_of(timer, struct cgroup_file, @@ -4195,25 +4181,18 @@ static int cgroup_add_file(struct cgroup_subsys_state *css, struct cgroup *cgrp, char name[CGROUP_FILE_NAME_MAX]; struct kernfs_node *kn; struct lock_class_key *key = NULL; - int ret; #ifdef CONFIG_DEBUG_LOCK_ALLOC key = &cft->lockdep_key; #endif kn = __kernfs_create_file(cgrp->kn, cgroup_file_name(cgrp, cft, name), cgroup_file_mode(cft), - GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, + current_fsuid(), current_fsgid(), 0, cft->kf_ops, cft, NULL, key); if (IS_ERR(kn)) return PTR_ERR(kn); - ret = cgroup_kn_set_ugid(kn); - if (ret) { - kernfs_remove(kn); - return ret; - } - if (cft->file_offset) { struct cgroup_file *cfile = (void *)css + cft->file_offset; @@ -5616,7 +5595,9 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name, goto out_cancel_ref; /* create the directory */ - kn = kernfs_create_dir(parent->kn, name, mode, cgrp); + kn = kernfs_create_dir_ns(parent->kn, name, mode, + current_fsuid(), current_fsgid(), + cgrp, NULL); if (IS_ERR(kn)) { ret = PTR_ERR(kn); goto out_stat_exit; @@ -5761,10 +5742,6 @@ int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, umode_t mode) */ kernfs_get(cgrp->kn); - ret = cgroup_kn_set_ugid(cgrp->kn); - if (ret) - goto out_destroy; - ret = css_populate_dir(&cgrp->self); if (ret) goto out_destroy; From patchwork Fri Dec 8 09:33:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 175697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5342006vqy; Fri, 8 Dec 2023 01:33:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKRP0N3FMTCr4jLwy/A4aMuaV0fnKn06Vf0kQdQirDfmXuRtEYBFu0JtrP6mQXnZ/FvvaB X-Received: by 2002:a9d:4d16:0:b0:6d9:e37f:5c45 with SMTP id n22-20020a9d4d16000000b006d9e37f5c45mr1525195otf.2.1702028018493; Fri, 08 Dec 2023 01:33:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702028018; cv=none; d=google.com; s=arc-20160816; b=Za56mauJImWCUOO1sakbB8FpsK9ivwf9r8e5BrhCcLNsQwPtUrZwcQ32a1zfPNoXnA jCEcEzZCBZ57XcQMv6Vj/YKHuxc2ieQRvWL4fxLwe+gC/qPfd1v69nRkBw9vEJpITvI9 tRuT4+N4mPKeBWqcNJJKMtnk92YCUJfDNaaVpgwVJvYmwMWiQWwFxHNWzjjfRNsPAaXs SiUDwkDanzGhn+sBRCGwPYUsT2DUZQ+rI5VAaH+C7lWZv8bh82ot8jdmlxpBVBSIsFhc VF915HdG9q2rvYjZOhYqf4ymNzL34bdDHOgA/JhWNFEaklz5rA3jPq2oMAPhVtl1OD8F Ydyg== 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=ml3aYbEq09uGjduR2N6EJX5pAeyS3QJMe6FIXxf84y8=; fh=uUgNkyrv3JReNoTSO9y0jmTkBGsqHJqQkaGAGfDhVmw=; b=E0Tg1GWYl1WxzqZ9cIzpgM+JY6kYblVW7faZzWKzgspYwa6NA4QHG1cqOLYOsmSoks 0cZ1FL8uuOtau4doU/4/tlvNbbJr7gGMv6PgJWXzNric2SwwphZsmT3FPTDWj23qwxMh 6kB9sXxXUFig0DvnPNhn6LoV1xPQEHN0/4EHJEpZcJNZAaKLJlfmutdY+YiwykcBJeYr 28x3Vy+YWgi4SOaRZFkWV4Ibf3z2jaN8oOtO8UnIIfn/riBhS+IvPNP88lJxDLKKaiFx tm2EFYOuvzDvzpxZT8ss6hh1lJC+DvU4K8FzUJC73Hoptnn3mnwv4ov2IdjhqrTqikOL ei0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="QE1yCNi/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id bx2-20020a056a02050200b005bdf59618e3si1374614pgb.497.2023.12.08.01.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 01:33:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="QE1yCNi/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 0A0A383741D4; Fri, 8 Dec 2023 01:33:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573441AbjLHJdM (ORCPT + 99 others); Fri, 8 Dec 2023 04:33:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232968AbjLHJdJ (ORCPT ); Fri, 8 Dec 2023 04:33:09 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E834210CA for ; Fri, 8 Dec 2023 01:33:15 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a1f47f91fc0so168438666b.0 for ; Fri, 08 Dec 2023 01:33:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1702027994; x=1702632794; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ml3aYbEq09uGjduR2N6EJX5pAeyS3QJMe6FIXxf84y8=; b=QE1yCNi/RKufBR/+9V8qBw+gNmJ7H8TD55foVj7sizAM1YtpZkH4NvnxOF5vNd0a7/ zP9liIPL+7PKC9TUv36IcDL0LHhXXTZjAHZfYCgqI07ENhRBLh9NvWOAVgRlMgTa97BO 7/iJWvHZYS7zsVFOCAoAEgH3PimGntYufZ7+LdMFB+TIcUxcyYlOqeQStJvTpIhFCWlN lKsnrcZcSQ+j33SecPZ98Fg/GEoaEX5XA2/nMsmZwXTWGhwSEmdbTO37wCGD0hdn2LVi 8R0Jkgiu39W+7o8D4QgNs5BBzLVAYF2b7LGk3nKuU0SUSXUe0Pwnus+RI1YwhEEaxqfn Rsnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702027994; x=1702632794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ml3aYbEq09uGjduR2N6EJX5pAeyS3QJMe6FIXxf84y8=; b=EZxMqX7gYh18MvlAVolEFeCOkHf69dwPP9kVBLgMnn+NrT6int02Usaj5k3IEFNJ1X HLCmVlFtK2ui0UnDbQddAu/E/oJJu0WKlxubktySowGmd+dBBJbl/JVLyoDfjZbMg5vM ceL00gsqJgjp9E+iEXiWSwX9JTHPD7MhOnVTKwgWSslBcDLZ1EOJMhyKIagQ4gQq3qdp Qv0vKO07nmtV++PYItm6oF0z1ldL/6l5ogqPwwB9Wq+zn/WyggJOz9RqAU1zhcze7Rc5 OYFoSlV1FEJMJntGCvvOMtgrn/aVpS7tXHnpKaY70YcjyKa98aBHzs2TW6pZpQ0IXL6Z U0Xw== X-Gm-Message-State: AOJu0YxkvwOKTR3nWR2dfGHGhc09unNKN0mV+qOUQK8juiU0IWP52lxr wF9PY3de/DpCJdja5lF3c1wRkg== X-Received: by 2002:a17:906:eb57:b0:a19:a19b:55c3 with SMTP id mc23-20020a170906eb5700b00a19a19b55c3mr1992038ejb.83.1702027994303; Fri, 08 Dec 2023 01:33:14 -0800 (PST) Received: from heron.intern.cm-ag (p200300dc6f0b6500529a4cfffe3dd983.dip0.t-ipconnect.de. [2003:dc:6f0b:6500:529a:4cff:fe3d:d983]) by smtp.gmail.com with ESMTPSA id vk5-20020a170907cbc500b00a1ce56f7b16sm774812ejc.71.2023.12.08.01.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 01:33:14 -0800 (PST) From: Max Kellermann To: Greg Kroah-Hartman , Tejun Heo , Zefan Li , Johannes Weiner , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Cc: Max Kellermann Subject: [PATCH v2 2/2] fs/kernfs/dir: obey S_ISGID Date: Fri, 8 Dec 2023 10:33:10 +0100 Message-Id: <20231208093310.297233-2-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231208093310.297233-1-max.kellermann@ionos.com> References: <20231208093310.297233-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 08 Dec 2023 01:33:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784705731443429288 X-GMAIL-MSGID: 1784705731443429288 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. Signed-off-by: Max Kellermann Acked-by: Tejun Heo Tested-by: Bagas Sanjaya --- v1 -> v2: minor coding style fix (comment) --- 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) {