selftests, arm64: add a selftest for passing tagged pointers to kernel
This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. This patch adds a simple test, that calls the uname syscall with a tagged user pointer as an argument. Without the kernel accepting tagged user pointers the test fails with EFAULT. Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Will Deacon <will@kernel.org>
This commit is contained in:
parent
63f0c60379
commit
9ce1263033
1
tools/testing/selftests/arm64/.gitignore
vendored
Normal file
1
tools/testing/selftests/arm64/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
tags_test
|
11
tools/testing/selftests/arm64/Makefile
Normal file
11
tools/testing/selftests/arm64/Makefile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
|
||||||
|
# ARCH can be overridden by the user for cross compiling
|
||||||
|
ARCH ?= $(shell uname -m 2>/dev/null || echo not)
|
||||||
|
|
||||||
|
ifneq (,$(filter $(ARCH),aarch64 arm64))
|
||||||
|
TEST_GEN_PROGS := tags_test
|
||||||
|
TEST_PROGS := run_tags_test.sh
|
||||||
|
endif
|
||||||
|
|
||||||
|
include ../lib.mk
|
12
tools/testing/selftests/arm64/run_tags_test.sh
Executable file
12
tools/testing/selftests/arm64/run_tags_test.sh
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
|
||||||
|
echo "--------------------"
|
||||||
|
echo "running tags test"
|
||||||
|
echo "--------------------"
|
||||||
|
./tags_test
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "[FAIL]"
|
||||||
|
else
|
||||||
|
echo "[PASS]"
|
||||||
|
fi
|
29
tools/testing/selftests/arm64/tags_test.c
Normal file
29
tools/testing/selftests/arm64/tags_test.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#define SHIFT_TAG(tag) ((uint64_t)(tag) << 56)
|
||||||
|
#define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \
|
||||||
|
SHIFT_TAG(tag))
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
static int tbi_enabled = 0;
|
||||||
|
struct utsname *ptr, *tagged_ptr;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0)
|
||||||
|
tbi_enabled = 1;
|
||||||
|
ptr = (struct utsname *)malloc(sizeof(*ptr));
|
||||||
|
if (tbi_enabled)
|
||||||
|
tagged_ptr = (struct utsname *)SET_TAG(ptr, 0x42);
|
||||||
|
err = uname(tagged_ptr);
|
||||||
|
free(ptr);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user