Commit ab27740f authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'linux_kselftest-next-6.8-rc1' of...

Merge tag 'linux_kselftest-next-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest update from Shuah Khan:
 "Enhancements to reporting test results, fixes to root and user run
  behavior and fixing ksft_print_msg() calls"

* tag 'linux_kselftest-next-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  tracing/selftests: Add ownership modification tests for eventfs
  selftests: sched: Remove initialization to 0 for a static variable
  selftests: capabilities: namespace create varies for root and normal user
  selftests: prctl: Add prctl test for PR_GET_NAME
  kselftest/vDSO: Use ksft_print_msg() rather than printf in vdso_test_abi
  kselftest/vDSO: Fix message formatting for clock_id logging
  kselftest/vDSO: Make test name reporting for vdso_abi_test tooling friendly
  selftests:x86: Fix Format String Warnings in lam.c
  selftests/breakpoints: Fix format specifier in ksft_print_msg in step_after_suspend_test.c
  selftests:breakpoints: Fix Format String Warning in breakpoint_test
parents 41daf06e ee9793be
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -284,9 +284,9 @@ static void check_success(const char *msg)
	nr_tests++;

	if (ret)
		ksft_test_result_pass(msg);
		ksft_test_result_pass("%s", msg);
	else
		ksft_test_result_fail(msg);
		ksft_test_result_fail("%s", msg);
}

static void launch_instruction_breakpoints(char *buf, int local, int global)
+1 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ int run_test(int cpu)

	wpid = waitpid(pid, &status, __WALL);
	if (wpid != pid) {
		ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
		ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
		return KSFT_FAIL;
	}
	if (WIFEXITED(status)) {
+1 −5
Original line number Diff line number Diff line
@@ -88,11 +88,7 @@ static bool create_and_enter_ns(uid_t inner_uid)
	outer_uid = getuid();
	outer_gid = getgid();

	/*
	 * TODO: If we're already root, we could skip creating the userns.
	 */

	if (unshare(CLONE_NEWNS) == 0) {
	if (outer_uid == 0 && unshare(CLONE_NEWNS) == 0) {
		ksft_print_msg("[NOTE]\tUsing global UIDs for tests\n");
		if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0)
			ksft_exit_fail_msg("PR_SET_KEEPCAPS - %s\n",
+114 −0
Original line number Diff line number Diff line
#!/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
+32 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#define CHANGE_NAME "changename"
#define EMPTY_NAME ""
#define TASK_COMM_LEN 16
#define MAX_PATH_LEN 50

int set_name(char *name)
{
@@ -47,6 +48,35 @@ int check_null_pointer(char *check_name)
	return res;
}

int check_name(void)
{

	int pid;

	pid = getpid();
	FILE *fptr = NULL;
	char path[MAX_PATH_LEN] = {};
	char name[TASK_COMM_LEN] = {};
	char output[TASK_COMM_LEN] = {};
	int j;

	j = snprintf(path, MAX_PATH_LEN, "/proc/self/task/%d/comm", pid);
	fptr = fopen(path, "r");
	if (!fptr)
		return -EIO;

	fscanf(fptr, "%s", output);
	if (ferror(fptr))
		return -EIO;

	int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);

	if (res < 0)
		return -errno;

	return !strcmp(output, name);
}

TEST(rename_process) {

	EXPECT_GE(set_name(CHANGE_NAME), 0);
@@ -57,6 +87,8 @@ TEST(rename_process) {

	EXPECT_GE(set_name(CHANGE_NAME), 0);
	EXPECT_LT(check_null_pointer(CHANGE_NAME), 0);

	EXPECT_TRUE(check_name());
}

TEST_HARNESS_MAIN
Loading