aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/arm64/mte
diff options
context:
space:
mode:
authorJoey Gouly <joey.gouly@arm.com>2022-02-09 15:22:37 +0000
committerWill Deacon <will@kernel.org>2022-02-15 16:57:50 +0000
commit682b064bae871deb213ed2e97fe4a5d4a5132e37 (patch)
treedebdbf9d2d8d386008272fa519992f8bf3043a61 /tools/testing/selftests/arm64/mte
parentkselftest/arm64: mte: user_mem: rework error handling (diff)
downloadwireguard-linux-682b064bae871deb213ed2e97fe4a5d4a5132e37.tar.xz
wireguard-linux-682b064bae871deb213ed2e97fe4a5d4a5132e37.zip
kselftest/arm64: mte: user_mem: check different offsets and sizes
To check there are no assumptions in the kernel about buffer sizes or alignments of user space pointers, expand the test to cover different sizes and offsets. Signed-off-by: Joey Gouly <joey.gouly@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will@kernel.org> Cc: Mark Brown <broonie@kernel.org> Cc: Shuah Khan <shuah@kernel.org> Reviewed-by: Mark Brown <broonie@kernel.org> Tested-by: Mark Brown <broonie@kernel.org> Reviewed-by: Shuah Khan <skhan@linuxfoundation.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Link: https://lore.kernel.org/r/20220209152240.52788-4-joey.gouly@arm.com Signed-off-by: Will Deacon <will@kernel.org>
Diffstat (limited to 'tools/testing/selftests/arm64/mte')
-rw-r--r--tools/testing/selftests/arm64/mte/check_user_mem.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c
index 2afcc9fb9ae8..89c861ee68fa 100644
--- a/tools/testing/selftests/arm64/mte/check_user_mem.c
+++ b/tools/testing/selftests/arm64/mte/check_user_mem.c
@@ -26,6 +26,8 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping,
char val = 'A';
size_t len, read_len;
void *ptr, *ptr_next;
+ int fileoff, ptroff, size;
+ int sizes[] = {1, 2, 3, 8, 16, 32, 4096, page_sz};
err = KSFT_PASS;
len = 2 * page_sz;
@@ -62,24 +64,31 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping,
ptr_next = mte_insert_new_tag(ptr_next);
mte_set_tag_address_range(ptr_next, tag_len);
- lseek(fd, 0, 0);
- /* Copy from file into buffer with invalid tag */
- read_len = read(fd, ptr, len);
- mte_wait_after_trig();
- /*
- * Accessing user memory in kernel with invalid tag should fail in sync
- * mode without fault but may not fail in async mode as per the
- * implemented MTE userspace support in Arm64 kernel.
- */
- if (cur_mte_cxt.fault_valid)
- goto usermem_acc_err;
-
- if (mode == MTE_SYNC_ERR && read_len < len) {
- /* test passed */
- } else if (mode == MTE_ASYNC_ERR && read_len == len) {
- /* test passed */
- } else {
- goto usermem_acc_err;
+ for (fileoff = 0; fileoff < 16; fileoff++) {
+ for (ptroff = 0; ptroff < 16; ptroff++) {
+ for (i = 0; i < ARRAY_SIZE(sizes); i++) {
+ size = sizes[i];
+ lseek(fd, 0, 0);
+ /* Copy from file into buffer with invalid tag */
+ read_len = read(fd, ptr + ptroff, size);
+ mte_wait_after_trig();
+ /*
+ * Accessing user memory in kernel with invalid tag should fail in sync
+ * mode without fault but may not fail in async mode as per the
+ * implemented MTE userspace support in Arm64 kernel.
+ */
+ if (cur_mte_cxt.fault_valid) {
+ goto usermem_acc_err;
+ }
+ if (mode == MTE_SYNC_ERR && read_len < len) {
+ /* test passed */
+ } else if (mode == MTE_ASYNC_ERR && read_len == size) {
+ /* test passed */
+ } else {
+ goto usermem_acc_err;
+ }
+ }
+ }
}
goto exit;