tools/testing/selftests/arm64/pauth/pac.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/arm64/pauth/pac.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/arm64/pauth/pac.c
Extension
.c
Size
9003 bytes
Lines
374
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (ret == -1) {
			perror("dup2 returned error");
			exit(1);
		}

		dup2(new_stdout[1], STDOUT_FILENO);
		if (ret == -1) {
			perror("dup2 returned error");
			exit(1);
		}

		close(new_stdin[0]);
		close(new_stdin[1]);
		close(new_stdout[0]);
		close(new_stdout[1]);

		ret = execl("exec_target", "exec_target", (char *)NULL);
		if (ret == -1) {
			perror("exec returned error");
			exit(1);
		}
	}

	close(new_stdin[0]);
	close(new_stdout[1]);

	ret = write(new_stdin[1], &val, sizeof(size_t));
	if (ret == -1) {
		perror("write returned error");
		return -1;
	}

	/*
	 * wait for the worker to finish, so that read() reads all data
	 * will also context switch with worker so that this function can be used
	 * for context switch tests
	 */
	waitpid(pid, &status, 0);
	if (WIFEXITED(status) == 0) {
		fprintf(stderr, "worker exited unexpectedly\n");
		return -1;
	}
	if (WEXITSTATUS(status) != 0) {
		fprintf(stderr, "worker exited with error\n");
		return -1;
	}

	ret = read(new_stdout[0], signed_vals, sizeof(struct signatures));
	if (ret == -1) {
		perror("read returned error");
		return -1;
	}

	close(new_stdin[1]);
	close(new_stdout[0]);

	return 0;
}

sigjmp_buf jmpbuf;
void pac_signal_handler(int signum, siginfo_t *si, void *uc)
{
	if (signum == SIGSEGV || signum == SIGILL)
		siglongjmp(jmpbuf, 1);
}

/* check that a corrupted PAC results in SIGSEGV or SIGILL */
TEST(corrupt_pac)
{
	struct sigaction sa;

	ASSERT_PAUTH_ENABLED();
	if (sigsetjmp(jmpbuf, 1) == 0) {
		sa.sa_sigaction = pac_signal_handler;
		sa.sa_flags = SA_SIGINFO | SA_RESETHAND;
		sigemptyset(&sa.sa_mask);

		sigaction(SIGSEGV, &sa, NULL);
		sigaction(SIGILL, &sa, NULL);

		pac_corruptor();
		ASSERT_TRUE(0) TH_LOG("SIGSEGV/SIGILL signal did not occur");
	}
}

/*
 * There are no separate pac* and aut* controls so checking only the pac*
 * instructions is sufficient
 */
TEST(pac_instructions_not_nop)

Annotation

Implementation Notes