Skip to content

Commit

Permalink
FROMLIST: selftests, arm64: add a selftest for passing tagged pointer…
Browse files Browse the repository at this point in the history
…s to kernel

(from https://lore.kernel.org/patchwork/patch/994348)

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.

Bug: 112461694
Change-Id: Id23d66680a6bb55a098ef69bfa8af90c096fe53b
Signed-off-by: Andrey Konovalov <[email protected]>
Signed-off-by: Chenyang Zhong <[email protected]>
  • Loading branch information
xairy authored and YumeMichi committed Aug 9, 2021
1 parent 6599630 commit be1de5b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/arm64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tags_test
11 changes: 11 additions & 0 deletions tools/testing/selftests/arm64/Makefile
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions tools/testing/selftests/arm64/run_tags_test.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions tools/testing/selftests/arm64/tags_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* SPDX-License-Identifier: GPL-2.0 */

#include <stdio.h>
#include <unistd.h>
#include <stdint.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)
{
struct utsname utsname;
void *ptr = &utsname;
void *tagged_ptr = (void *)SET_TAG(ptr, 0x42);
int err = uname(tagged_ptr);
return err;
}

0 comments on commit be1de5b

Please sign in to comment.