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 
15 int main(void)
16 {
17 	static int tbi_enabled = 0;
18 	unsigned long tag = 0;
19 	struct utsname *ptr;
20 	int err;
21 
22 	if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0)
23 		tbi_enabled = 1;
24 	ptr = (struct utsname *)malloc(sizeof(*ptr));
25 	if (!ptr)
26 		ksft_exit_fail_msg("Failed to allocate utsname buffer\n");
27 
28 	if (tbi_enabled)
29 		tag = 0x42;
30 	ptr = (struct utsname *)SET_TAG(ptr, tag);
31 	err = uname(ptr);
32 	free(ptr);
33 
34 	return err;
35 }
36