1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <stdint.h>
7 #include <sys/prctl.h>
8 #include <sys/utsname.h>
9 #include "../../kselftest.h"
10 
11 #define SHIFT_TAG(tag)		((uint64_t)(tag) << 56)
12 #define SET_TAG(ptr, tag)	(((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \
13 					SHIFT_TAG(tag))
14 
main(void)15 int main(void)
16 {
17 	static int tbi_enabled = 0;
18 	unsigned long tag = 0;
19 	struct utsname *ptr;
20 
21 	ksft_print_header();
22 	ksft_set_plan(1);
23 
24 	if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0)
25 		tbi_enabled = 1;
26 	ptr = (struct utsname *)malloc(sizeof(*ptr));
27 	if (!ptr)
28 		ksft_exit_fail_perror("Failed to allocate utsname buffer");
29 
30 	if (tbi_enabled)
31 		tag = 0x42;
32 	ptr = (struct utsname *)SET_TAG(ptr, tag);
33 	ksft_test_result(!uname(ptr), "Syscall successful with tagged address\n");
34 	free(ptr);
35 
36 	ksft_finished();
37 }
38