Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp914089rdb; Fri, 22 Dec 2023 08:34:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHpWVrcWrDYCxj7HMf7G6HMy48fLTqGsv25gDzW9mZuB9E+3OYQkF8RC9IR7XY2C0aBCfee X-Received: by 2002:ac2:5a5b:0:b0:50e:3c20:4a35 with SMTP id r27-20020ac25a5b000000b0050e3c204a35mr871753lfn.59.1703262879796; Fri, 22 Dec 2023 08:34:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703262879; cv=none; d=google.com; s=arc-20160816; b=LppfJbCec1D1Td8IjQCFRWtCUdyLg/I2QdzmAU8qjXmQllp8KWjufLZQw8boB03wYI rI1/RKrXFMcFJcgX6k8tIbbTzBGzO5cLB9xtLmIhlyogPmr8jJe/RdFk4JQlK1cBsI5P aeDmyR8kD4CcybV6PgZNDL/2HNjLDwz797ljncq1QRmpc+BRYr/pG7RYAgeWLLBgA94O lsNQM+RSdyk09NDTRC8y6OojvPe9PX8oR9wcRyBTAIju7uKahE7z5baaRNJaOOvvz7ny EjkzWxvB3oxq4HFOqZ6pGqI/Aq3byrE2jc4Fm4dfR84vGv7I9Bemiel64p5Sm9Y14dtD F55w== 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:message-id:subject:cc:to:from :date; bh=MfVZf9orWaJBhj2onBJtr0R13AYAEQD9ma5zJvxKBKo=; fh=vJ6MEK635tD6MRVsCzr90ayissWCVHJGOtPL2mbj8IQ=; b=oRrJ7JAFvzS0isZHhsK00LDEh27HAk8LC7+gObb8ovXGTFudyvfBKkkS+1MHhqZMZB 5copeL2gY8/SvIHhBPoKgnNDjWFJ7+habicPRG/ru74JKcpJxVb0AkjhszhoglaU+f/U XRck76oN620wpZTheFegay/Zjo1lqEqB6gO5AA1N/sX2xeyrEPr0ymD5+SfnTfgXfnqc c5rOBx3RPPdBzDpWrgQ7OebHaSqiQDc4Cq8QyGD1greTgXO5tvNSOCK0HOTkEA2qvGx6 H3huoidLjiJFSItwZ1ePqVYnlFFNX+h59pjOI7WOdaqxbuVjfzjrKbCG6IgTNlGaDryv iuIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-9911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9911-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v5-20020a170906488500b00a2375c07456si1840481ejq.656.2023.12.22.08.34.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 08:34:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-9911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9911-linux.lists.archive=gmail.com@vger.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8508F1F2364A for ; Fri, 22 Dec 2023 16:34:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3676F28DAE; Fri, 22 Dec 2023 16:33:56 +0000 (UTC) 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 B7BD024B4D; Fri, 22 Dec 2023 16:33:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32E88C433C9; Fri, 22 Dec 2023 16:33:54 +0000 (UTC) Date: Fri, 22 Dec 2023 11:34:59 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mathieu Desnoyers , Linus Torvalds , Shuah Khan , Linux selftests Subject: [PATCH v4] tracing/selftests: Add ownership modification tests for eventfs Message-ID: <20231222113459.4d645bfc@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (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 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. Acked-by: Masami Hiramatsu (Google) Tested-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- Changes since v3: https://lore.kernel.org/linux-trace-kernel/20231221211229.13398ef3@gandalf.local.home - Added missing SPDX and removed exec permission from file (Shuah Khan) .../ftrace/test.d/00basic/test_ownership.tc | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 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 100644 index 000000000000..add7d5bf585d --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc @@ -0,0 +1,114 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# 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