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) {