Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp544139rdb; Thu, 21 Dec 2023 18:36:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGh6lteijkgRT97c+e9lb80C3AX22ln+vE9vUtjdoIDWVfvBaSCHxMSeVPQOx5jyU7rlDdF X-Received: by 2002:a05:6870:b620:b0:204:91c:d45d with SMTP id cm32-20020a056870b62000b00204091cd45dmr855522oab.114.1703212578689; Thu, 21 Dec 2023 18:36:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703212578; cv=none; d=google.com; s=arc-20160816; b=bW1fXQfBhTCov23SZ+aQFq+egnQ/n37fGqzK408B1FBb7dh7COF/i2xGDJOwtOUZvH m01Dd7YbPR3aehSpsfCYYnEADokqfl3CPiFQkxJLfIlZolempRsQdWJqP+8kHSDX8S3t xh7Th8Qt2vI+NcUaLAQ02RuE4B0OMrBim8t3C1fA9td+b5S8/iXPuGhgAmzpj/Ag/za9 Yw5qOLg0XesJVnxiGAr3ldUp7z5FtTMFw9LZ3ZbURr2N8PIUZ2GSxujxq/q7qDvDxHYz akgCSTvEIMwOISDPKp0oOtjFIfWaxfWjGyEsWlEpxWuuKgdgHriMWCPqpZZDUNixUDhF gOhA== ARC-Message-Signature: i=1; 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 :subject:cc:to:from:date:dkim-signature; bh=D+94Rjtu9zaFy5UISWTvZJMRMiuRDcZqZM9/+u9YkJw=; fh=TkTKDGPZ7HAdKsrr4ynV9GvRfkI/C8PkKUnzi3kBXyk=; b=vYGAsBICjp/ohdg/ui1oWiwr04Eq/6B54W457Z0Q0aBMn4W3ILfFVScF+4+P+QXQIC 3PXjIPTJ5qyMVvGGC3N+1F4gkOZwctgQM6XML5X7e2D1o9xm59pri1HXOY34EwqQJMNA kLH/awdKz5nra+KUdPTtnby8ZsE+SAGLcdU5fY+oL+Fdm1VoU8+75WzyoIya2JcyqDaC eyWSG96rkEiXnkkSFeZLdW4+7BRo7iGms+GDUqK+exgH57Diy2LhIc0cWfX9bkrEhhwU QT1GpWJ76RbbVYdhz9fhStp5FvDuuCRiXxuIK78uUg7vQNTmysOPBxHrZrKCDPIMiG9t Ng2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uvKT6nVf; spf=pass (google.com: domain of linux-kernel+bounces-9266-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9266-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 e24-20020a656498000000b005cdf98f236esi13034pgv.795.2023.12.21.18.36.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 18:36:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9266-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=uvKT6nVf; spf=pass (google.com: domain of linux-kernel+bounces-9266-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9266-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 54CC4284C49 for ; Fri, 22 Dec 2023 02:36:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02FF915A4; Fri, 22 Dec 2023 02:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uvKT6nVf" 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 1AE64EB8; Fri, 22 Dec 2023 02:36:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3634C433C7; Fri, 22 Dec 2023 02:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703212568; bh=4YxpCLDfd1k1s8/rpC3WKr38gI6Epu4ObWxhbNChjn8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=uvKT6nVfVjS7D9F0wnDoUDniJlkzacWvpcRUGtXLhiWuMjC9/uCV4C/l1rCstUz+T kE23aMje+vrNqo7ZYIDFPoYZAECtn30St10BPcw7VQ33poe/aRmKRxH+we+PJhOCP5 gmVQYlsiTicKzylthmDA1MIm1MaThTBp5GgH3zb1frc3uGKxlGZoUOWCJLWSCqQ2HS xrlbLm/7FgDxZ5b+VW3eFWHhC2Js/6egmUDjkpdQ/ZL3icb6nCJQwjaBW/SjAG+D6r gjM3hF8EpLmJPzVaLGiWxG0Gj71gViXSqGczDEh1lqcaUlx1x0i17YUloC7nTz0OtN HJN+yUWLt0M9A== Date: Fri, 22 Dec 2023 11:36:03 +0900 From: Masami Hiramatsu (Google) To: Steven Rostedt Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Linus Torvalds , Shuah Khan , Linux selftests Subject: Re: [PATCH v3] tracing/selftests: Add ownership modification tests for eventfs Message-Id: <20231222113603.96bf082a416abf8a56a26ddc@kernel.org> In-Reply-To: <20231221211229.13398ef3@gandalf.local.home> References: <20231221211229.13398ef3@gandalf.local.home> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 21 Dec 2023 21:12:29 -0500 Steven Rostedt wrote: > From: "Steven Rostedt (Google)" > > As there were bugs found with the ownership of eventfs dynamic file > creation. Add a test to test it. > > It will remount tracefs with a different gid and check the ownership of > the eventfs directory, as well as the system and event directories. It > will also check the event file directories. > > It then does a chgrp on each of these as well to see if they all get > updated as expected. > > Then it remounts the tracefs file system back to the original group and > makes sure that all the updated files and directories were reset back to > the original ownership. > > It does the same for instances that change the ownership of he instance > directory. > > Note, because the uid is not reset by a remount, it is tested for every > file by switching it to a new owner and then back again. > Thanks for update! Acked-by: Masami Hiramatsu (Google) Tested-by: Masami Hiramatsu (Google) > Signed-off-by: Steven Rostedt (Google) > --- > Changes since v2: https://lore.kernel.org/linux-trace-kernel/20231221194516.53e1ee43@gandalf.local.home > > - Changed the instance test name from "foo-$(mktemp -u XXXXX)" to > "$(mktemp -u test-XXXXXX)" as Masami reported that busybox mktemp only > works with 6 Xs and not 5. Also changed "foo" to "test" and placed it > into the mktemp format. > > .../ftrace/test.d/00basic/test_ownership.tc | 113 ++++++++++++++++++ > 1 file changed, 113 insertions(+) > create mode 100755 tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc > > diff --git a/tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc b/tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc > new file mode 100755 > index 000000000000..4c20be3a714a > --- /dev/null > +++ b/tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc > @@ -0,0 +1,113 @@ > +#!/bin/sh > +# description: Test file and directory owership changes for eventfs > + > +original_group=`stat -c "%g" .` > +original_owner=`stat -c "%u" .` > + > +mount_point=`stat -c '%m' .` > +mount_options=`mount | grep "$mount_point" | sed -e 's/.*(\(.*\)).*/\1/'` > + > +# find another owner and group that is not the original > +other_group=`tac /etc/group | grep -v ":$original_group:" | head -1 | cut -d: -f3` > +other_owner=`tac /etc/passwd | grep -v ":$original_owner:" | head -1 | cut -d: -f3` > + > +# Remove any group ownership already > +new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"` > + > +if [ "$new_options" = "$mount_options" ]; then > + new_options="$mount_options,gid=$other_group" > + mount_options="$mount_options,gid=$original_group" > +fi > + > +canary="events/timer events/timer/timer_cancel events/timer/timer_cancel/format" > + > +test() { > + file=$1 > + test_group=$2 > + > + owner=`stat -c "%u" $file` > + group=`stat -c "%g" $file` > + > + echo "testing $file $owner=$original_owner and $group=$test_group" > + if [ $owner -ne $original_owner ]; then > + exit_fail > + fi > + if [ $group -ne $test_group ]; then > + exit_fail > + fi > + > + # Note, the remount does not update ownership so test going to and from owner > + echo "test owner $file to $other_owner" > + chown $other_owner $file > + owner=`stat -c "%u" $file` > + if [ $owner -ne $other_owner ]; then > + exit_fail > + fi > + > + chown $original_owner $file > + owner=`stat -c "%u" $file` > + if [ $owner -ne $original_owner ]; then > + exit_fail > + fi > + > +} > + > +run_tests() { > + for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do > + test "$d" $other_group > + done > + > + chgrp $original_group events > + test "events" $original_group > + for d in "." "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do > + test "$d" $other_group > + done > + > + chgrp $original_group events/sched > + test "events/sched" $original_group > + for d in "." "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do > + test "$d" $other_group > + done > + > + chgrp $original_group events/sched/sched_switch > + test "events/sched/sched_switch" $original_group > + for d in "." "events/sched/sched_switch/enable" $canary; do > + test "$d" $other_group > + done > + > + chgrp $original_group events/sched/sched_switch/enable > + test "events/sched/sched_switch/enable" $original_group > + for d in "." $canary; do > + test "$d" $other_group > + done > +} > + > +mount -o remount,"$new_options" . > + > +run_tests > + > +mount -o remount,"$mount_options" . > + > +for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do > + test "$d" $original_group > +done > + > +# check instances as well > + > +chgrp $other_group instances > + > +instance="$(mktemp -u test-XXXXXX)" > + > +mkdir instances/$instance > + > +cd instances/$instance > + > +run_tests > + > +cd ../.. > + > +rmdir instances/$instance > + > +chgrp $original_group instances > + > +exit 0 > -- > 2.42.0 > > -- Masami Hiramatsu (Google)