Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1554102rdb; Mon, 8 Jan 2024 03:05:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKR3pauvfBp9/L3JIfhqmKxgSI8xHWqdj99+/iIw/gPdGPO6pThbiGv3QIkRmOatWazq4E X-Received: by 2002:a17:902:e54f:b0:1d4:cc36:e47 with SMTP id n15-20020a170902e54f00b001d4cc360e47mr1104760plf.52.1704711939542; Mon, 08 Jan 2024 03:05:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704711939; cv=none; d=google.com; s=arc-20160816; b=nXUYKcrM7IFOCP4rp1kFNyhGl39Zy0Dr1+f3KxNA5QzQju6d/zmthL65uoaU4R20zj /C6vtzRjBPDq1EsBZlDAtmnucLUjO4ji9Lq7KwVo9Wrf+FicVwzGnou1ve8KY3ZVNJq9 oteNcVKbi+e8SfiQkZEiQFYbplv+ThyL09RP0JpGmRLJOo5nGXtDdM8B0r/aDENHLa3W m80YozbmZJFPyIGqDqxnXzSvoCY0u51LTiDcNa2XjeKN+T7Yp5fOvQCKY2J2Gf+J0I57 gzU2PhmReHsMGCJIfVnEnkXaJO7X37KfpeoLJzBbCeqNvixrh3RjZ6fID1jBrPAVmNgO 3aJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yF+yOkPMCw62XjQbo+5QzYT+u8cCRu/eiT3gAM+f41A=; fh=tX5EGv6jK/Dl/05Aa90IVl+6fxuZIkQ4Z7yDCdFv4iw=; b=W9WMah4hbu4ayet+yLsxYwx1gMhYv/EuJQDraD+DRvJ8lMBC9Dz4K6eBHdnBA5mpl7 Q7PMsIiOkNUhoN+xEoIgAcl7xLR59UU/9h2sLrdbexShiAeK+JMww0bAxuV0t1qGE709 SktFRAIrMb328gbKoW9YG3qdsMxbPfS8XiWPs9FyjEWCTAq886+racH3kfwRNBoseV2Z hzRnAA91WKpZMws7YToCuy7MY9DDRnnwmvqxn1RmOQxb9z25vGRernRCzu5y4eaaobLM Sf9qJ6zG57RpF6FCRs3VFv71+lBw0fwLxgFEO+2Re8yOv0Oz3tRa1xW/lWFIrmgO/3eA zv+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FEs1ZNsN; spf=pass (google.com: domain of linux-kernel+bounces-19374-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19374-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c3-20020a170902d90300b001d4cbf7d66fsi5867685plz.560.2024.01.08.03.05.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 03:05:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19374-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FEs1ZNsN; spf=pass (google.com: domain of linux-kernel+bounces-19374-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19374-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 387AD2812CA for ; Mon, 8 Jan 2024 11:05:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03D1C14AB0; Mon, 8 Jan 2024 11:05:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FEs1ZNsN" X-Original-To: linux-kernel@vger.kernel.org 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 2CA8A1A271; Mon, 8 Jan 2024 11:04:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10868C433CC; Mon, 8 Jan 2024 11:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704711899; bh=ADZSz3svcvy4AE0ELj/OHAdWql4h0/MMJv4njtLcOQ0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FEs1ZNsNkv1hZ7rvZ5yDtjX9ooa2ixnqvb4Lt3NzsFMPe0NI1ulO6GFDsaAnVY46A tUCu9aWmz9Fq0LAW8jlic1dnzOOPAV3fEKKRvN2EgNUaEgRyNLDS2TYmqtnZ2vRqtJ 8G8TIAYNsGbIfyPZ/c0bEhfIGJK4Uxs7bH8wKvi3eEoGOcORi6jtC9hBK0eCx7j247 wGbg/dFaHlhpty+peUeOXy1NcOg8TksLY63xbLWs1pLAeY5Bwr3wG+ae6RtT4E1hXk Jveorm9MUjFCsDmsCn1oRxafbYkUodH0uRxLnu0cd+6mARBJsU/NK42nqqC9SumzMM H7u/PxmBtP4NQ== Date: Mon, 8 Jan 2024 12:04:54 +0100 From: Christian Brauner To: Steven Rostedt Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mathieu Desnoyers , Linus Torvalds , Al Viro , linux-fsdevel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH] tracefs/eventfs: Use root and instance inodes as default ownership Message-ID: <20240108-ortsrand-ziehen-4e9a9a58e708@brauner> References: <20240103203246.115732ec@gandalf.local.home> <20240105-wegstecken-sachkenntnis-6289842d6d01@brauner> <20240105095954.67de63c2@gandalf.local.home> <20240107-getrickst-angeeignet-049cea8cad13@brauner> <20240107132912.71b109d8@rorschach.local.home> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240107132912.71b109d8@rorschach.local.home> > > * Tracefs supports the creation of instances from userspace via mkdir. > > For example, > > > > mkdir /sys/kernel/tracing/instances/foo > > > > And here the idmapping is relevant so we need to make the helpers > > aware of the idmapping. > > > > I just went and plumbed this through to most helpers. > > > > There's some subtlety in eventfs. Afaict, the directories and files for > > the individual events are created on-demand during lookup or readdir. > > > > The ownership of these events is again inherited from the parent inode > > or recovered from stored state. In both cases the actual idmapping is > > irrelevant. > > > > The callchain here is: > > > > eventfs_root_lookup("xfs", "events") > > -> create_{dir,file}_dentry("xfs", "events") > > -> create_{dir,file}("xfs", "events") > > -> eventfs_start_creating("xfs", "events") > > -> lookup_one_len("xfs", "events") > > > > And the subtlety is that lookup_one_len() does permission checking on > > the parent inode (IOW, if you want a dentry for "blech" under "events" > > it'll do a permission check on events->d_inode) for exec permissions > > and then goes on to give you a new dentry. > > > > Usually this call would have to be changed to lookup_one() and the > > idmapping be handed down to it. But I think that's irrelevant here. > > > > Lookup generally doesn't need to be aware of idmappings at all. The > > permission checking is done purely in the vfs via may_lookup() and the > > idmapping is irrelevant because we always initialize inodes with the > > filesystem level ownership (see the idmappings.rst) documentation if > > you're interested in excessive details (otherwise you get inode aliases > > which you really don't want). > > > > For tracefs it would not matter for lookup per se but only because > > tracefs seemingly creates inodes/dentries during lookup (and readdir()). > > tracefs creates the inodes/dentries at boot up, it's eventfs that does > it on demand during lookup. > > For inodes/dentries: > > /sys/kernel/tracing/* is all created at boot up, except for "events". Yes. > /sys/kernel/tracing/events/* is created on demand. Yes. > > > > > But imho the permission checking done in current eventfs_root_lookup() > > via lookup_one_len() is meaningless in any way; possibly even > > (conceptually) wrong. > > > > Because, the actual permission checking for the creation of the eventfs > > entries isn't really done during lookup or readdir, it's done when mkdir > > is called: > > > > mkdir /sys/kernel/tracing/instances/foo > > No. that creates a entire new tracefs instance, which happens to > include another eventfs directory. Yes, I'm aware of all that. > No. Only the meta data is created for the eventfs directory with a > mkdir instances/foo. The inodes and dentries are not there. I know, that is what I'm saying. > > > > > When one goes and looksup stuff under foo/events/ or readdir the entries > > in that directory: > > > > fd = open("foo/events") > > readdir(fd, ...) > > > > then they are licensed to list an entry in that directory. So all that > > needs to be done is to actually list those files in that directory. And > > since they already exist (they were created during mkdir) we just need > > to splice in inodes and dentries for them. But for that we shouldn't > > check permissions on the directory again. Because we've done that > > already correctly when the VFS called may_lookup(). > > No they do not exist. I am aware. > > > > > IOW, the inode_permission() in lookup_one_len() that eventfs does is > > redundant and just wrong. > > I don't think so. I'm very well aware that the dentries and inode aren't created during mkdir but the completely directory layout is determined. You're just splicing in dentries and inodes during lookup and readdir. If mkdir /sys/kernel/tracing/instances/foo has succeeded and you later do a lookup/readdir on ls -al /sys/kernel/tracing/instances/foo/events Why should the creation of the dentries and inodes ever fail due to a permission failure? The vfs did already verify that you had the required permissions to list entries in that directory. Why should filling up /sys/kernel/tracing/instances/foo/events ever fail then? It shouldn't That tracefs instance would be half-functional. And again, right now that inode_permission() check cannot even fail.