From patchwork Fri Dec 1 12:56:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 172476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1095141vqy; Fri, 1 Dec 2023 04:57:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+kHsdl0RpPyOcQwBZ7gyvyrTXcXQ22vu1G65yESEmU9bi+4/1ZMXZ+Dd0YCmm3OQkY4gO X-Received: by 2002:a17:90b:1e45:b0:285:ade1:cbfa with SMTP id pi5-20020a17090b1e4500b00285ade1cbfamr24004313pjb.16.1701435423527; Fri, 01 Dec 2023 04:57:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701435423; cv=none; d=google.com; s=arc-20160816; b=gcIOux62+BYaSMVpD/MXWPUA8w5AR60atKz58Qjd3PoqFKqFoY+If6kRvXgG5pmPbQ C1vIVfBiiqSWaG0Nr34tcZQkgsNScGRSivaRSaC5gqL7l3J2ug7afbrS3GK32biDHhwr B0Sb8MHRkXZcJiDjc2oXYZwbjZxS5udHSpecBO0gRv9O4aa36RQdcO6nhrgLSph/BuWv 0v+7JyGV3yjDzUwBM1K0nxorHnXijVyKX4vDewNjt6eSgy+oaw+OfE+cSKUOfVelVyt7 AKIE8JFhJbFQAhXpSZfzcrwLqKY/eJ7wAuyRD5zmSHiZvozZ8cb28tPv/pXFpKaztFAs IfHQ== 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=m/7cKv0n7i+Sfh7Y0nPTpy9YYoZvft9zpO431GTslYc=; fh=VN24NhpMN+IMUAjl9ufkstPt7WLUAUA7pL8s3WKHHb4=; b=ooDWEJX2+kBhqgsIxVTVWqG0C8AuOD7RX9sc6rml07MOcxcMshqwS+RoZu87McvyQ2 9kNBZJ9YIDITjeiArqwHB895fQmuiamjHqIwaWnQ9NitfzwpFGDn6Glx43VKgkUVabOa YUfrXHbv7Jonq2Ko3Jb1OJHzOPkP0FTLXcQktWXN4KYE7lkc2xTlhn1ziEkkWNhKVAoL ZjP3/d65u2qLShJbydjeWb4iJ1r6P038aJSFzvSw7X7kragRirJqLvlfr5SRLAxorJvS ZlAlhWrvALcrxeajkChHT9759yoIZFhDwANZRa9/bSB+R3veptpdqUmukB/MRd5qMyFs J9bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=Sqp22FzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id sk13-20020a17090b2dcd00b002861c962e15si3606080pjb.15.2023.12.01.04.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 04:57:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=Sqp22FzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 9D6BC807500F; Fri, 1 Dec 2023 04:56:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378903AbjLAM4j (ORCPT + 99 others); Fri, 1 Dec 2023 07:56:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378839AbjLAM4i (ORCPT ); Fri, 1 Dec 2023 07:56:38 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD2FD10F3 for ; Fri, 1 Dec 2023 04:56:42 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-54c6896a689so359444a12.2 for ; Fri, 01 Dec 2023 04:56:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1701435401; x=1702040201; 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=m/7cKv0n7i+Sfh7Y0nPTpy9YYoZvft9zpO431GTslYc=; b=Sqp22FzJfmhNI6Q2Zfl0v1ry9N0axJeymXMA3hPbkA5vzLnZjTsLu0F7yCVplD78Q7 4iv9Hfj4J9lkSDLAr8NMRDsautipaBxQVGe+OQ/twCxKFXwrOMNOEXHDWeBxjEYlMoRH 99sdHSHC2lf2qY11J+ilWpIc4lokjq6IKaNRxqFcoj7hdsHZaflY+Zd6rJCiUzvojzLH Os2R55bG0/Y14M3lblcGohQ9ggSjoD70D9V2AkvZl/66jt/94lH+LlgF1U8+CfsxIzYQ ju5CSG9g7y3IuOln85EGl+L2fzCBQ/rPzFRN3o4+PduRo3NBf0Ky2CRRPCObLa+DGmUN PPsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701435401; x=1702040201; 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=m/7cKv0n7i+Sfh7Y0nPTpy9YYoZvft9zpO431GTslYc=; b=GOrxDHkMmZAt5t/dKcx0FVqOaZIsCEI1RXpvlz5lsI9+RrjS6Vg/WWINxMKd+OUSvR vdVBVaQvlyDZSLvfBUlpm14M9ARjON5qQPhRTG5wvvdCi96mSPyQVvMtyToCwd/bRVL1 AXx0Q0JgWT/waqzgh7pnrZCojJBdiR0dlEZzyqvzvl37cCig+OyMxpdy/JXlqBA534/J 1zThFT4amA3tTgjWR2wZGBDDGAKyrAFIYR5ATTDxVxg2PG9bd8HgXP+49Tt9Hg4t4P4x HM8grfaJim1210sCyjBkf1SCiy5+UMqxCeQF0uRaMwPvW82vuoGQEjhiak3POgwrcBEu 4K2g== X-Gm-Message-State: AOJu0Yx84BGKRQRR4B33MWL41WnkrAEnTl1Kxda/5KXyEbrtNPdAqwAL QNne9jKtng4UzOdjdbjW7qqbgA== X-Received: by 2002:a17:906:6955:b0:a00:893f:58cf with SMTP id c21-20020a170906695500b00a00893f58cfmr798081ejs.54.1701435401138; Fri, 01 Dec 2023 04:56:41 -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 p10-20020a170906a00a00b00a0be4fec1b4sm1870231ejy.138.2023.12.01.04.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 04:56:40 -0800 (PST) From: Max Kellermann To: Tejun Heo , Zefan Li , Johannes Weiner Cc: Max Kellermann , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] kernel/cgroup: use kernfs_create_dir_ns() Date: Fri, 1 Dec 2023 13:56:37 +0100 Message-Id: <20231201125638.1699026-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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Fri, 01 Dec 2023 04:56:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784084350567675545 X-GMAIL-MSGID: 1784084350567675545 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 49957f8e2a ("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 --- 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 1 12:56:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 172477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1095176vqy; Fri, 1 Dec 2023 04:57:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdm3m97NjBA6UQetvZrelswbA0dlDfgVox5c1woxNa8IWdsiHCn9UHXo5YNdGdWhVqN97I X-Received: by 2002:a05:6a20:a10a:b0:18a:e176:87e9 with SMTP id q10-20020a056a20a10a00b0018ae17687e9mr24034568pzk.15.1701435428423; Fri, 01 Dec 2023 04:57:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701435428; cv=none; d=google.com; s=arc-20160816; b=AiRNiEbbwoOB06YVVRDFxaoNt7VQIjRHas3VCKQdbEHaIFqmg3nPMZYb+riUsZi3tE A6j1kLATUKgC+UtLDQoA1iDyn5OLfp5PseDvXv+WzQSZLCtEAfvb9bhRETgjxjFcly6L Gp2IhC1YTZ/HwFo7hJ9OWIfPwhYPmmVZx+YBa6pj8BNZ1HweqW9WuBCxK8wMMiEVJyJj Hc8HyLl0IXuWGFRINmZWn5hDDTayo0xHz3+XPo9kR8/qCzA0PMKho21AZeWc/jfgfuDb gpQgKnyKKi2vj9NirsXH/kBbCY4dGaNrLRp/VBkHK8gjZnta98ECoB97Lf9lhh2WuFv7 Iyrw== 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=gM3txpR7KJT3aJLknAwcYyGwwkt0hTNGCSJEHZF76+c=; fh=y2iI/SoDz6OL9QAK2Ube1UCD9XBanxUt9VMdAar7Ei4=; b=WlrO/FQz6Z+Cp6rnIdh9yQnSlKNshXj+kMR5W7QPtesJEW17CBUmVfF/ShqqxO6xk1 n5smlsBsuai7hSjGjhVq+keaYvDNnbLR8f02/rJrMQNCYwrwEZuuXoQMwkCcRrjndhIh vdrkSwhYVxqyelPXmnhuD+nTLBBiBzzXmofCtAevPJOq9nPpDEgdPAAr1ayJXcs0JVAN WnbiofkqJsAEdn79uzvx9IZfaHg73Dc28IAJglMdnBfruXRrDIEn8x82isVb/klFj65r iNsf6PtWZMeU1kttC+uJuaqfwC508WLAQyWxEGNDa2ILpe0aVKNOTkqd0l/wU3g2Dia8 eBdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=dwm77DbY; 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 h9-20020a170902f54900b001c9c967e77esi3314641plf.207.2023.12.01.04.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 04:57:08 -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=dwm77DbY; 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 BD404836CE77; Fri, 1 Dec 2023 04:57:05 -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 S1378913AbjLAM4m (ORCPT + 99 others); Fri, 1 Dec 2023 07:56:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378858AbjLAM4i (ORCPT ); Fri, 1 Dec 2023 07:56:38 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44C0B10F9 for ; Fri, 1 Dec 2023 04:56:44 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a00a9c6f283so295647266b.0 for ; Fri, 01 Dec 2023 04:56:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1701435403; x=1702040203; 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=gM3txpR7KJT3aJLknAwcYyGwwkt0hTNGCSJEHZF76+c=; b=dwm77DbY05vUESPpsO+GLsOcz3tWtZGm+Z6tydNvmu7KkBI5Qnq24MnUa0iBnVty5H HQv2jbbICt28S4AkGc8n5Yo+NN9qNs0nN1lBGr/G4YeSwJwQbespYfuGDmSrRzedVHI7 45uNlbJpvXRdrWyoDw0xyYyLxlRB+pdqhHBVixZ9rzsNoiIX1Dq/tNme98BlEkb0acda Zk1U71zj2UUhCEqa9mpvg94E0zGlrqb+Ao8Q/ip0bRf6CuvIlBJnygPJ+Xq7U8cP8IN5 VKYmAZQIOtPC6mNWaXHRgY13E38DGbRN3VkZbkLqE2A+YVlmGulnjwse5Ec9y6fcQKsm UYyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701435403; x=1702040203; 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=gM3txpR7KJT3aJLknAwcYyGwwkt0hTNGCSJEHZF76+c=; b=W9AUc34yBhFKpwoQYkoG/guxy6NNPL1bEawqhSJNX2OPG9/sWeN7taFiFKvvjDeylh SbiWxThvISEfRxbwF6qm6HHDNWpsRodlI52X49N5hi0N/R6B++u0/Jucuy0yEyhC2Siz 2ISmRLu6MWW5/3n+b6N1DlDe5lQXcnTJsUo1KwOPzNSgG6an81RgAY89AFgUYxVaCv6k JlMogfvf02zJFbYY8C2M+jrZPBZiivit5yiGg443veStVfcbTVtx4/EiibPiqV+Y4wIA evXft7lQ9xUK27XJZ9DQt93+SEJwW6mdefdwznkBNnYZpeasTqjoBh28x/ulLhNKtUo8 lUmA== X-Gm-Message-State: AOJu0Ywp37Aya7cbdBQprRBJX1vFD8OBsK/D49EsRirm1TDFgaoGR0CF rOezqcjkkpKJiyVFNvs6F0lzNg== X-Received: by 2002:a17:906:718b:b0:9fe:81a:c258 with SMTP id h11-20020a170906718b00b009fe081ac258mr1704769ejk.26.1701435402759; Fri, 01 Dec 2023 04:56:42 -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 p10-20020a170906a00a00b00a0be4fec1b4sm1870231ejy.138.2023.12.01.04.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 04:56:42 -0800 (PST) From: Max Kellermann To: Greg Kroah-Hartman , Tejun Heo Cc: Max Kellermann , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] fs/kernfs/dir: obey S_ISGID Date: Fri, 1 Dec 2023 13:56:38 +0100 Message-Id: <20231201125638.1699026-2-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231201125638.1699026-1-max.kellermann@ionos.com> References: <20231201125638.1699026-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, 01 Dec 2023 04:57:05 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784084356136213567 X-GMAIL-MSGID: 1784084356136213567 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 --- fs/kernfs/dir.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 8b2bd65d70e7..7580cc340d28 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -676,6 +676,17 @@ 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) {