From: Joey Gouly <joey.gouly@arm.com>
To: <linux-arm-kernel@lists.infradead.org>
Cc: <linux-kselftest@vger.kernel.org>, <nd@arm.com>,
<broonie@kernel.org>, <catalin.marinas@arm.com>,
<joey.gouly@arm.com>, <shuah@kernel.org>,
<skhan@linuxfoundation.org>, <will@kernel.org>
Subject: [PATCH v3 1/6] kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len
Date: Wed, 9 Feb 2022 15:22:35 +0000 [thread overview]
Message-ID: <20220209152240.52788-2-joey.gouly@arm.com> (raw)
In-Reply-To: <20220209152240.52788-1-joey.gouly@arm.com>
These can be used to place an MTE tag at an address that is not at a
page size boundary.
The kernel prior to 295cf156231c ("arm64: Avoid premature usercopy failure"),
would infinite loop if an MTE tag was placed not at a PAGE_SIZE boundary.
This is because the kernel checked if the pages were readable by checking the
first byte of each page, but would then fault in the middle of the page due
to the MTE tag.
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>
---
.../selftests/arm64/mte/check_user_mem.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c
index 1de7a0abd0ae..5a5a7e1f5789 100644
--- a/tools/testing/selftests/arm64/mte/check_user_mem.c
+++ b/tools/testing/selftests/arm64/mte/check_user_mem.c
@@ -19,7 +19,8 @@
static size_t page_sz;
-static int check_usermem_access_fault(int mem_type, int mode, int mapping)
+static int check_usermem_access_fault(int mem_type, int mode, int mapping,
+ int tag_offset, int tag_len)
{
int fd, i, err;
char val = 'A';
@@ -54,10 +55,12 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping)
if (i < len)
goto usermem_acc_err;
- /* Tag the next half of memory with different value */
- ptr_next = (void *)((unsigned long)ptr + page_sz);
+ if (!tag_len)
+ tag_len = len - tag_offset;
+ /* Tag a part of memory with different value */
+ ptr_next = (void *)((unsigned long)ptr + tag_offset);
ptr_next = mte_insert_new_tag(ptr_next);
- mte_set_tag_address_range(ptr_next, page_sz);
+ mte_set_tag_address_range(ptr_next, tag_len);
lseek(fd, 0, 0);
/* Copy from file into buffer with invalid tag */
@@ -100,14 +103,14 @@ int main(int argc, char *argv[])
/* Set test plan */
ksft_set_plan(4);
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE),
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, page_sz, 0),
"Check memory access from kernel in sync mode, private mapping and mmap memory\n");
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_SHARED),
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_SHARED, page_sz, 0),
"Check memory access from kernel in sync mode, shared mapping and mmap memory\n");
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE),
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE, page_sz, 0),
"Check memory access from kernel in async mode, private mapping and mmap memory\n");
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_SHARED),
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_SHARED, page_sz, 0),
"Check memory access from kernel in async mode, shared mapping and mmap memory\n");
mte_restore_setup();
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-02-09 15:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 15:22 [PATCH v3 0/6] add more test coverage to MTE kselftests Joey Gouly
2022-02-09 15:22 ` Joey Gouly [this message]
2022-02-09 18:36 ` [PATCH v3 1/6] kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len Catalin Marinas
2022-02-09 15:22 ` [PATCH v3 2/6] kselftest/arm64: mte: user_mem: rework error handling Joey Gouly
2022-02-09 18:40 ` Catalin Marinas
2022-02-09 15:22 ` [PATCH v3 3/6] kselftest/arm64: mte: user_mem: check different offsets and sizes Joey Gouly
2022-02-09 18:41 ` Catalin Marinas
2022-02-09 15:22 ` [PATCH v3 4/6] kselftest/arm64: mte: user_mem: add test type enum Joey Gouly
2022-02-09 18:43 ` Catalin Marinas
2022-02-09 15:22 ` [PATCH v3 5/6] kselftest/arm64: mte: user_mem: add more test types Joey Gouly
2022-02-09 18:43 ` Catalin Marinas
2022-02-09 15:22 ` [PATCH v3 6/6] kselftest/arm64: mte: user_mem: test a wider range of values Joey Gouly
2022-02-09 18:44 ` Catalin Marinas
2022-02-15 23:18 ` [PATCH v3 0/6] add more test coverage to MTE kselftests Will Deacon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220209152240.52788-2-joey.gouly@arm.com \
--to=joey.gouly@arm.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=nd@arm.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).