Hi,
This series fixes various issues in LTP that prevent tests from passing when reservations / PCuABI address space management are implemented.
Patch 1-3 are generic, and arguably general improvements. The remainder of the patches are PCuABI-specific, with appropriate #ifdef'ing where necessary. The changes are meant to be backwards-compatible (e.g. ERESERVATION is not assumed to be returned in PCuABI).
Review branch:
https://git.morello-project.org/kbrodsky-arm/morello-linux-ltp/-/commits/mor...
Thanks, Kevin
Kevin Brodsky (10): syscalls/munlock: Pass an appropriate length to munlock() syscalls/m{,un}lock: Use mmap() to obtain an owning pointer syscalls/m{,un}map: Pass a raw address when reusing an address range syscalls: Use PROT_MAX() where needed syscalls/mmap: Allow MREMAP_MAYMOVE in PCuABI syscalls/mlock{,2}: Expect ERESERVATION on unmapped area syscalls/mmap: Expect EINVAL on MAP_FIXED_NOREPLACE syscalls/mprotect: Expect EINVAL on null pointer syscalls/mremap: Expect EINVAL on narrow pointer syscalls/mmap: Skip MAP_GROWSDOWN tests in PCuABI
.../syscalls/memfd_create/memfd_create_common.c | 3 ++- testcases/kernel/syscalls/mlock/mlock01.c | 13 +++---------- testcases/kernel/syscalls/mlock/mlock02.c | 12 +++++++++++- testcases/kernel/syscalls/mlock2/mlock202.c | 5 +++-- testcases/kernel/syscalls/mmap/mmap16.c | 11 +++++++++-- testcases/kernel/syscalls/mmap/mmap17.c | 4 ++++ testcases/kernel/syscalls/mmap/mmap18.c | 7 +++++++ testcases/kernel/syscalls/mmap/mmap19.c | 4 ++-- testcases/kernel/syscalls/mprotect/mprotect01.c | 11 +++++++++-- testcases/kernel/syscalls/mprotect/mprotect02.c | 3 ++- testcases/kernel/syscalls/mprotect/mprotect04.c | 5 +++-- testcases/kernel/syscalls/mprotect/mprotect05.c | 4 +++- testcases/kernel/syscalls/mremap/mremap03.c | 5 +++++ testcases/kernel/syscalls/mremap/mremap05.c | 4 +++- testcases/kernel/syscalls/munlock/munlock01.c | 13 +++---------- testcases/kernel/syscalls/munlock/munlock02.c | 1 + 16 files changed, 70 insertions(+), 35 deletions(-)
munlock() currently gets passed a range that is wider than the targeted mapping. This fails in PCuABI, as the bounds check against the passed capability will fail. Reduce len accordingly.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/munlock/munlock02.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/testcases/kernel/syscalls/munlock/munlock02.c b/testcases/kernel/syscalls/munlock/munlock02.c index f51c3d21f24a..ea095b59ce63 100644 --- a/testcases/kernel/syscalls/munlock/munlock02.c +++ b/testcases/kernel/syscalls/munlock/munlock02.c @@ -38,6 +38,7 @@ static void setup(void) * unmap part of the area, to create the condition for ENOMEM */ addr += 2 * pg_size; + len -= 2 * pg_size; SAFE_MUNMAP(addr, 4 * pg_size); }
In PCuABI, library functions such as malloc() are not expected to return a pointer that allows manipulating the underlying mapping. For that purpose, mmap() should be used.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mlock/mlock01.c | 13 +++---------- testcases/kernel/syscalls/munlock/munlock01.c | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-)
diff --git a/testcases/kernel/syscalls/mlock/mlock01.c b/testcases/kernel/syscalls/mlock/mlock01.c index 0b079f8be83a..8cefc96b87dc 100644 --- a/testcases/kernel/syscalls/mlock/mlock01.c +++ b/testcases/kernel/syscalls/mlock/mlock01.c @@ -32,21 +32,14 @@ static void do_mlock(unsigned int i) struct tcase *tc = &tcases[i];
tst_res(TINFO, "%s", tc->msg); - addr = SAFE_MALLOC(tc->len); + addr = SAFE_MMAP(NULL, tc->len, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); TST_EXP_PASS(mlock(addr, tc->len), "mlock(%p, %d)", addr, tc->len); - free(addr); - addr = NULL; -} - -static void cleanup(void) -{ - if (addr) - free(addr); + SAFE_MUNMAP(addr, tc->len); }
static struct tst_test test = { .needs_root = 1, .test = do_mlock, .tcnt = ARRAY_SIZE(tcases), - .cleanup = cleanup, }; diff --git a/testcases/kernel/syscalls/munlock/munlock01.c b/testcases/kernel/syscalls/munlock/munlock01.c index 31d749e66697..ff55056ae908 100644 --- a/testcases/kernel/syscalls/munlock/munlock01.c +++ b/testcases/kernel/syscalls/munlock/munlock01.c @@ -30,22 +30,15 @@ static void verify_munlock(unsigned int i) struct tcase *tc = &tcases[i];
tst_res(TINFO, "%s", tc->msg); - addr = SAFE_MALLOC(tc->len); + addr = SAFE_MMAP(NULL, tc->len, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); SAFE_MLOCK(addr, tc->len); TST_EXP_PASS(munlock(addr, tc->len), "munlock(%p, %d)", addr, tc->len); - free(addr); - addr = NULL; -} - -static void cleanup(void) -{ - if (addr) - free(addr); + SAFE_MUNMAP(addr, tc->len); }
static struct tst_test test = { .needs_root = 1, .test = verify_munlock, .tcnt = ARRAY_SIZE(tcases), - .cleanup = cleanup, };
The pointer returned by mmap() and mremap() has extra properties in PCuABI, indicating ownership of the mapping. Certain mmap and mremap tests rely on an mmap() + munmap() sequence to make sure that an address range is not mapped. In this case, a subsequent call to mmap/mremap should simply pass the address of that range, not a capability owning it, because at that point the underlying reservation will have disappeared.
Note: this pattern is acceptable in the current implementation of reservations where they are destroyed synchronously with the last mapping within them. This should not be assumed in general, but given the difficulty to remove that assumption it is kept for now.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mmap/mmap16.c | 3 ++- testcases/kernel/syscalls/mmap/mmap19.c | 4 ++-- testcases/kernel/syscalls/mremap/mremap05.c | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/testcases/kernel/syscalls/mmap/mmap16.c b/testcases/kernel/syscalls/mmap/mmap16.c index 4e0d8a3f4249..64fb02fa4034 100644 --- a/testcases/kernel/syscalls/mmap/mmap16.c +++ b/testcases/kernel/syscalls/mmap/mmap16.c @@ -67,7 +67,8 @@ static void do_child(void) MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); SAFE_MUNMAP(addr, page_size * 2);
- addr = SAFE_MMAP(addr, FS_BLOCKSIZE, PROT_WRITE | PROT_READ, MAP_SHARED, childfd, 0); + addr = SAFE_MMAP((void *)(ptraddr_t)addr, FS_BLOCKSIZE, + PROT_WRITE | PROT_READ, MAP_SHARED, childfd, 0);
addr[0] = 'a';
diff --git a/testcases/kernel/syscalls/mmap/mmap19.c b/testcases/kernel/syscalls/mmap/mmap19.c index 90b3f45b1f63..e6e04dcc1bde 100644 --- a/testcases/kernel/syscalls/mmap/mmap19.c +++ b/testcases/kernel/syscalls/mmap/mmap19.c @@ -52,8 +52,8 @@ static void run(void) SAFE_MUNMAP(mm1, LEN); SAFE_MUNMAP(mm2, LEN);
- mm1 = SAFE_MMAP(save_mm2, LEN, PROT_READ, MAP_PRIVATE, f1, 0); - mm2 = SAFE_MMAP(save_mm1, LEN, PROT_READ, MAP_PRIVATE, f2, 0); + mm1 = SAFE_MMAP((void *)(ptraddr_t)save_mm2, LEN, PROT_READ, MAP_PRIVATE, f1, 0); + mm2 = SAFE_MMAP((void *)(ptraddr_t)save_mm1, LEN, PROT_READ, MAP_PRIVATE, f2, 0);
if (mm1 != save_mm2 || mm2 != save_mm1) tst_res(TINFO, "mmap not using same address"); diff --git a/testcases/kernel/syscalls/mremap/mremap05.c b/testcases/kernel/syscalls/mremap/mremap05.c index d85ebb068dc4..1e9f6c162ce3 100644 --- a/testcases/kernel/syscalls/mremap/mremap05.c +++ b/testcases/kernel/syscalls/mremap/mremap05.c @@ -128,8 +128,10 @@ static void *get_test_area(int size, int free_area) MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (p == MAP_FAILED) tst_brkm(TBROK | TERRNO, cleanup, "get_test_area mmap"); - if (free_area) + if (free_area) { free_test_area(p, size); + p = (void *)(ptraddr_t)p; + } return p; }
In PCuABI, the permissions of a mapping cannot be expanded by default (using mprotect()). To allow this, PROT_MAX() with the full set of allowed permissions must be passed.
This is a no-op on other ABIs.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/memfd_create/memfd_create_common.c | 3 ++- testcases/kernel/syscalls/mprotect/mprotect01.c | 4 +++- testcases/kernel/syscalls/mprotect/mprotect02.c | 3 ++- testcases/kernel/syscalls/mprotect/mprotect04.c | 5 +++-- testcases/kernel/syscalls/mprotect/mprotect05.c | 4 +++- 5 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c index a52b02a567f5..619ecb157384 100644 --- a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c +++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c @@ -346,7 +346,8 @@ void check_mfd_writeable(const char *filename, const int lineno, int fd) * mprotect(PROT_WRITE) allows writing */ p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE, - PROT_READ, MAP_SHARED, fd, 0); + PROT_READ | PROT_MAX(PROT_READ | PROT_WRITE), + MAP_SHARED, fd, 0);
check_mprotect(filename, lineno, p, MFD_DEF_SIZE, PROT_READ | PROT_WRITE); diff --git a/testcases/kernel/syscalls/mprotect/mprotect01.c b/testcases/kernel/syscalls/mprotect/mprotect01.c index aa46852583ed..354b078b903f 100644 --- a/testcases/kernel/syscalls/mprotect/mprotect01.c +++ b/testcases/kernel/syscalls/mprotect/mprotect01.c @@ -145,7 +145,9 @@ static void setup3(struct test_case *self) /* * mmap the PAGESIZE bytes as read only. */ - self->addr = mmap(0, self->len, PROT_READ, MAP_SHARED, fd, 0); + self->addr = mmap(0, self->len, + PROT_READ | PROT_MAX(PROT_READ | PROT_WRITE), + MAP_SHARED, fd, 0); if (self->addr == MAP_FAILED) tst_brkm(TBROK, cleanup, "mmap failed");
diff --git a/testcases/kernel/syscalls/mprotect/mprotect02.c b/testcases/kernel/syscalls/mprotect/mprotect02.c index af282bba7b03..3643d67fbec0 100644 --- a/testcases/kernel/syscalls/mprotect/mprotect02.c +++ b/testcases/kernel/syscalls/mprotect/mprotect02.c @@ -86,7 +86,8 @@ int main(int ac, char **av) } while (0 < num_bytes);
/* mmap the PAGESIZE bytes as read only. */ - addr = SAFE_MMAP(cleanup, 0, sizeof(buf), PROT_READ, + addr = SAFE_MMAP(cleanup, 0, sizeof(buf), + PROT_READ | PROT_MAX(PROT_READ | PROT_WRITE), MAP_SHARED, fd, 0);
if ((pid = FORK_OR_VFORK()) == -1) diff --git a/testcases/kernel/syscalls/mprotect/mprotect04.c b/testcases/kernel/syscalls/mprotect/mprotect04.c index db99bc531f8e..e6e7063b0a3b 100644 --- a/testcases/kernel/syscalls/mprotect/mprotect04.c +++ b/testcases/kernel/syscalls/mprotect/mprotect04.c @@ -240,8 +240,9 @@ static void testfunc_protexec(void)
sig_caught = 0;
- p = SAFE_MMAP(cleanup, 0, page_sz, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + p = SAFE_MMAP(cleanup, 0, page_sz, + PROT_READ | PROT_WRITE | PROT_MAX(PROT_READ | PROT_WRITE | PROT_EXEC), + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#ifdef USE_FUNCTION_DESCRIPTORS func_descr_t opd; diff --git a/testcases/kernel/syscalls/mprotect/mprotect05.c b/testcases/kernel/syscalls/mprotect/mprotect05.c index 2b15f5bebbaa..5efcf32bf00f 100644 --- a/testcases/kernel/syscalls/mprotect/mprotect05.c +++ b/testcases/kernel/syscalls/mprotect/mprotect05.c @@ -31,7 +31,9 @@ static void setup(void) static void run(void) { fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, 0777); - addr = SAFE_MMAP(0, fullsize, PROT_READ, MAP_SHARED, fd, 0); + addr = SAFE_MMAP(0, fullsize, + PROT_READ | PROT_MAX(PROT_READ | PROT_WRITE | PROT_EXEC), + MAP_SHARED, fd, 0);
if (mprotect(addr + pagesize, pagesize, PROT_EXEC)) tst_res(TFAIL | TERRNO, "mprotect failed to exec");
A mapping that has just been created at a new location by mmap() cannot generally be expanded in PCuABI, because it cannot exceed the bounds of its underlying reservation. To allow this test to pass in PCuABI, pass MREMAP_MAYMOVE to mremap().
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mmap/mmap16.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/mmap/mmap16.c b/testcases/kernel/syscalls/mmap/mmap16.c index 64fb02fa4034..275f6461554b 100644 --- a/testcases/kernel/syscalls/mmap/mmap16.c +++ b/testcases/kernel/syscalls/mmap/mmap16.c @@ -43,6 +43,12 @@ static int parentfd = -1; static int childfd = -1;
+#ifdef __CHERI_PURE_CAPABILITY__ +#define MREMAP_FLAGS MREMAP_MAYMOVE +#else +#define MREMAP_FLAGS 0 +#endif + static void do_child(void) { int offset; @@ -74,7 +80,7 @@ static void do_child(void)
SAFE_FTRUNCATE(childfd, page_size * 2);
- addr = mremap(addr, FS_BLOCKSIZE, 2 * page_size, 0); + addr = mremap(addr, FS_BLOCKSIZE, 2 * page_size, MREMAP_FLAGS); if (addr == MAP_FAILED) tst_brk(TBROK | TERRNO, "mremap failed unexpectedly");
On Fri, Apr 19, 2024 at 03:24:28PM +0100, Kevin Brodsky wrote:
A mapping that has just been created at a new location by mmap() cannot generally be expanded in PCuABI, because it cannot exceed the bounds of its underlying reservation. To allow this test to pass in PCuABI, pass MREMAP_MAYMOVE to mremap().
Might be just me but the commit message reads like the MREMAP_MAYMOVE flag is used as a workaround here. Maybe expanding on what that flags means wrt reservations would make things more .... clear ?
--- BR Beata
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com
testcases/kernel/syscalls/mmap/mmap16.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/mmap/mmap16.c b/testcases/kernel/syscalls/mmap/mmap16.c index 64fb02fa4034..275f6461554b 100644 --- a/testcases/kernel/syscalls/mmap/mmap16.c +++ b/testcases/kernel/syscalls/mmap/mmap16.c @@ -43,6 +43,12 @@ static int parentfd = -1; static int childfd = -1; +#ifdef __CHERI_PURE_CAPABILITY__ +#define MREMAP_FLAGS MREMAP_MAYMOVE +#else +#define MREMAP_FLAGS 0 +#endif
static void do_child(void) { int offset; @@ -74,7 +80,7 @@ static void do_child(void) SAFE_FTRUNCATE(childfd, page_size * 2);
- addr = mremap(addr, FS_BLOCKSIZE, 2 * page_size, 0);
- addr = mremap(addr, FS_BLOCKSIZE, 2 * page_size, MREMAP_FLAGS); if (addr == MAP_FAILED) tst_brk(TBROK | TERRNO, "mremap failed unexpectedly");
2.43.0
linux-morello-ltp mailing list -- linux-morello-ltp@op-lists.linaro.org To unsubscribe send an email to linux-morello-ltp-leave@op-lists.linaro.org
On 22/04/2024 09:57, Beata Michalska wrote:
On Fri, Apr 19, 2024 at 03:24:28PM +0100, Kevin Brodsky wrote:
A mapping that has just been created at a new location by mmap() cannot generally be expanded in PCuABI, because it cannot exceed the bounds of its underlying reservation. To allow this test to pass in PCuABI, pass MREMAP_MAYMOVE to mremap().
Might be just me but the commit message reads like the MREMAP_MAYMOVE flag is used as a workaround here. Maybe expanding on what that flags means wrt reservations would make things more .... clear ?
It kind of is, as the original test didn't expect to use it, but for PCuABI it is necessary as per the first sentence: you cannot expand a mapping that's just been created, so you have to allow mremap() to create a new mapping/reservation using the flag. I don't think it gets in the way of checking what the test intends to, so probably not a concern.
Kevin
BR Beata
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com
testcases/kernel/syscalls/mmap/mmap16.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/mmap/mmap16.c b/testcases/kernel/syscalls/mmap/mmap16.c index 64fb02fa4034..275f6461554b 100644 --- a/testcases/kernel/syscalls/mmap/mmap16.c +++ b/testcases/kernel/syscalls/mmap/mmap16.c @@ -43,6 +43,12 @@ static int parentfd = -1; static int childfd = -1; +#ifdef __CHERI_PURE_CAPABILITY__ +#define MREMAP_FLAGS MREMAP_MAYMOVE +#else +#define MREMAP_FLAGS 0 +#endif
static void do_child(void) { int offset; @@ -74,7 +80,7 @@ static void do_child(void) SAFE_FTRUNCATE(childfd, page_size * 2);
- addr = mremap(addr, FS_BLOCKSIZE, 2 * page_size, 0);
- addr = mremap(addr, FS_BLOCKSIZE, 2 * page_size, MREMAP_FLAGS); if (addr == MAP_FAILED) tst_brk(TBROK | TERRNO, "mremap failed unexpectedly");
2.43.0
linux-morello-ltp mailing list -- linux-morello-ltp@op-lists.linaro.org To unsubscribe send an email to linux-morello-ltp-leave@op-lists.linaro.org
Syscalls such as mlock() first check the pointer (capability) they are passed in PCuABI. If the capability bounds are not contained in any reservation, -ERESERVATION is returned. This is what happens after a mapping is created and then fully unmapped.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mlock/mlock02.c | 12 +++++++++++- testcases/kernel/syscalls/mlock2/mlock202.c | 5 +++-- 2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/syscalls/mlock/mlock02.c b/testcases/kernel/syscalls/mlock/mlock02.c index 921ddeeae707..3e18cab016df 100644 --- a/testcases/kernel/syscalls/mlock/mlock02.c +++ b/testcases/kernel/syscalls/mlock/mlock02.c @@ -40,7 +40,17 @@ static void test_enomem1(void) addr = SAFE_MMAP(NULL, len, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); SAFE_MUNMAP(addr, len); - TST_EXP_FAIL(mlock(addr, len), ENOMEM, "mlock(%p, %lu)", addr, len); + + TEST(mlock(addr, len)); + if (TST_RET != -1) + tst_res(TFAIL | TTERRNO, "mlock(%p, %lu): wrong return code: %ld", + addr, len, TST_RET); + else if (TST_ERR != ENOMEM && TST_ERR != ERESERVATION) + tst_res(TFAIL | TTERRNO, "mlock(%p, %lu): expected errno: %d", + addr, len, TST_ERR); + else + tst_res(TPASS | TTERRNO, "mlock(%p, %lu) ", + addr, len); }
static void test_enomem2(void) diff --git a/testcases/kernel/syscalls/mlock2/mlock202.c b/testcases/kernel/syscalls/mlock2/mlock202.c index 3b49650657cd..5ef33ea95aed 100644 --- a/testcases/kernel/syscalls/mlock2/mlock202.c +++ b/testcases/kernel/syscalls/mlock2/mlock202.c @@ -40,11 +40,12 @@ static struct tcase { /* 1: nobody 0: root */ int user; int exp_err; + int alt_err; } tcases[] = { {&addr, -1, NULL, 0, EINVAL}, {&addr, 0, &max_sz1, 1, ENOMEM}, {&addr, 0, &max_sz2, 1, EPERM}, - {&unmapped_addr, 0, NULL, 0, ENOMEM}, + {&unmapped_addr, 0, NULL, 0, ENOMEM, ERESERVATION}, };
static void verify_mlock2(unsigned int n) @@ -67,7 +68,7 @@ static void verify_mlock2(unsigned int n) goto end; }
- if (TST_ERR != tc->exp_err) { + if (TST_ERR != tc->exp_err && TST_ERR != tc->alt_err) { tst_res(TFAIL | TTERRNO, "mlock2() failed unexpectedly, expected %s", tst_strerrno(tc->exp_err));
mmap(ptr, ..., MAP_FIXED_NOREPLACE) is invalid in PCuABI, as passing an owning capability requires replacing existing mapping(s) fully, which is the opposite of what MAP_FIXED_NOREPLACE requests.
Expect EINVAL in PCuABI only, as it is probably inappropriate on other ABIs.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mmap/mmap17.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/testcases/kernel/syscalls/mmap/mmap17.c b/testcases/kernel/syscalls/mmap/mmap17.c index 39703fbd397d..552b49f390b4 100644 --- a/testcases/kernel/syscalls/mmap/mmap17.c +++ b/testcases/kernel/syscalls/mmap/mmap17.c @@ -70,6 +70,10 @@ static void test_mmap(void) MAP_PRIVATE | MAP_FIXED_NOREPLACE, fd_file2, 0); if (address == MAP_FAILED && errno == EEXIST) tst_res(TPASS, "mmap set errno to EEXIST as expected"); +#ifdef __CHERI_PURE_CAPABILITY__ + else if (address == MAP_FAILED && errno == EINVAL) + tst_res(TPASS, "mmap set errno to EINVAL as expected"); +#endif else tst_res(TFAIL | TERRNO, "mmap failed, with unexpected error " "code, expected EEXIST");
A null pointer is not a valid capability in PCuABI, so the syscalls will fail early with -EINVAL.
Expect EINVAL in PCuABI only, as it is probably inappropriate on other ABIs.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mprotect/mprotect01.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/mprotect/mprotect01.c b/testcases/kernel/syscalls/mprotect/mprotect01.c index 354b078b903f..35941cc3702c 100644 --- a/testcases/kernel/syscalls/mprotect/mprotect01.c +++ b/testcases/kernel/syscalls/mprotect/mprotect01.c @@ -55,6 +55,7 @@ struct test_case { int prot; int error; void (*setupfunc) (struct test_case *self); + int alt_error; };
static void cleanup(void); @@ -105,7 +106,7 @@ int main(int ac, char **av) continue; }
- if (TEST_ERRNO == TC[i].error) { + if (TEST_ERRNO == TC[i].error || TEST_ERRNO == TC[i].alt_error) { tst_resm(TPASS, "expected failure - " "errno = %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); @@ -157,6 +158,10 @@ static void setup(void) { tst_sig(FORK, DEF_HANDLER, cleanup);
+#ifdef __CHERI_PURE_CAPABILITY__ + TC[0].alt_error = EINVAL; +#endif + TEST_PAUSE; }
In PCuABI, mremap() gets passed a capability with bounds that are narrower than memsize, which results in the syscall failing early with -EINVAL.
Expect EINVAL in PCuABI only, as it is probably inappropriate on other ABIs.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mremap/mremap03.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/testcases/kernel/syscalls/mremap/mremap03.c b/testcases/kernel/syscalls/mremap/mremap03.c index 02b79bc47bba..9ea7b64a47fc 100644 --- a/testcases/kernel/syscalls/mremap/mremap03.c +++ b/testcases/kernel/syscalls/mremap/mremap03.c @@ -131,6 +131,11 @@ int main(int ac, char **av) if (errno == EFAULT) { tst_resm(TPASS, "mremap() Fails, 'old region not " "mapped', errno %d", TEST_ERRNO); +#ifdef __CHERI_PURE_CAPABILITY__ + } else if (errno == EINVAL) { + tst_resm(TPASS, "mremap() Fails, 'invalid capability', " + "errno %d", TEST_ERRNO); +#endif } else { tst_resm(TFAIL, "mremap() Fails, " "'Unexpected errno %d", TEST_ERRNO);
MAP_GROWSDOWN is not supported in PCuABI, check that EOPNOTSUPP is returned by mmap() as specified and skip the tests.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- testcases/kernel/syscalls/mmap/mmap18.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/testcases/kernel/syscalls/mmap/mmap18.c b/testcases/kernel/syscalls/mmap/mmap18.c index b37b29890ca0..ed483942622c 100644 --- a/testcases/kernel/syscalls/mmap/mmap18.c +++ b/testcases/kernel/syscalls/mmap/mmap18.c @@ -77,6 +77,13 @@ static void setup(void) tst_brk(TCONF, "Test can't be performed with stack grows up architecture");
page_size = getpagesize(); + +#ifdef __CHERI_PURE_CAPABILITY__ + TST_EXP_FAIL(mmap(NULL, page_size, PROT_READ, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN, -1, 0), + EOPNOTSUPP, "MAP_GROWSDOWN is not supported in purecap"); + tst_brk(TCONF, "Cannot test MAP_GROWSDOWN in purecap: not supported"); +#endif }
/*
On Fri, Apr 19, 2024 at 03:24:33PM +0100, Kevin Brodsky wrote:
MAP_GROWSDOWN is not supported in PCuABI, check that EOPNOTSUPP is returned by mmap() as specified and skip the tests.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com
testcases/kernel/syscalls/mmap/mmap18.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/testcases/kernel/syscalls/mmap/mmap18.c b/testcases/kernel/syscalls/mmap/mmap18.c index b37b29890ca0..ed483942622c 100644 --- a/testcases/kernel/syscalls/mmap/mmap18.c +++ b/testcases/kernel/syscalls/mmap/mmap18.c @@ -77,6 +77,13 @@ static void setup(void) tst_brk(TCONF, "Test can't be performed with stack grows up architecture"); page_size = getpagesize();
+#ifdef __CHERI_PURE_CAPABILITY__
- TST_EXP_FAIL(mmap(NULL, page_size, PROT_READ,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN, -1, 0),
EOPNOTSUPP, "MAP_GROWSDOWN is not supported in purecap");
- tst_brk(TCONF, "Cannot test MAP_GROWSDOWN in purecap: not supported");
+#endif
One could arguee that this should be placed as an actual tests, not a setup phase. i.e placing it at run_test function ?
--- BR Beata
} /* -- 2.43.0
linux-morello-ltp mailing list -- linux-morello-ltp@op-lists.linaro.org To unsubscribe send an email to linux-morello-ltp-leave@op-lists.linaro.org
On 22/04/2024 09:56, Beata Michalska wrote:
On Fri, Apr 19, 2024 at 03:24:33PM +0100, Kevin Brodsky wrote:
MAP_GROWSDOWN is not supported in PCuABI, check that EOPNOTSUPP is returned by mmap() as specified and skip the tests.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com
testcases/kernel/syscalls/mmap/mmap18.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/testcases/kernel/syscalls/mmap/mmap18.c b/testcases/kernel/syscalls/mmap/mmap18.c index b37b29890ca0..ed483942622c 100644 --- a/testcases/kernel/syscalls/mmap/mmap18.c +++ b/testcases/kernel/syscalls/mmap/mmap18.c @@ -77,6 +77,13 @@ static void setup(void) tst_brk(TCONF, "Test can't be performed with stack grows up architecture"); page_size = getpagesize();
+#ifdef __CHERI_PURE_CAPABILITY__
- TST_EXP_FAIL(mmap(NULL, page_size, PROT_READ,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN, -1, 0),
EOPNOTSUPP, "MAP_GROWSDOWN is not supported in purecap");
- tst_brk(TCONF, "Cannot test MAP_GROWSDOWN in purecap: not supported");
+#endif
One could arguee that this should be placed as an actual tests, not a setup phase. i.e placing it at run_test function ?
Discussed offline, we can't actually test EOPNOTSUPP since that's not backwards-compatible, so having just the skip in setup() probably makes sense. FWIW we did the same thing in brk01.
Kevin
BR Beata
} /* -- 2.43.0
linux-morello-ltp mailing list -- linux-morello-ltp@op-lists.linaro.org To unsubscribe send an email to linux-morello-ltp-leave@op-lists.linaro.org
On Fri, Apr 19, 2024 at 03:24:23PM +0100, Kevin Brodsky wrote:
Hi,
This series fixes various issues in LTP that prevent tests from passing when reservations / PCuABI address space management are implemented.
Patch 1-3 are generic, and arguably general improvements. The remainder of the patches are PCuABI-specific, with appropriate #ifdef'ing where necessary. The changes are meant to be backwards-compatible (e.g. ERESERVATION is not assumed to be returned in PCuABI).
Review branch:
https://git.morello-project.org/kbrodsky-arm/morello-linux-ltp/-/commits/mor...
Landed on next with small modifications (whitespaces and indent) + dropping (expected-failure) test and amending commit message from: PATCH 10/10: syscalls/mmap: Skip MAP_GROWSDOWN tests in PCuABI
Thank you!
--- BR Beata
Thanks, Kevin
Kevin Brodsky (10): syscalls/munlock: Pass an appropriate length to munlock() syscalls/m{,un}lock: Use mmap() to obtain an owning pointer syscalls/m{,un}map: Pass a raw address when reusing an address range syscalls: Use PROT_MAX() where needed syscalls/mmap: Allow MREMAP_MAYMOVE in PCuABI syscalls/mlock{,2}: Expect ERESERVATION on unmapped area syscalls/mmap: Expect EINVAL on MAP_FIXED_NOREPLACE syscalls/mprotect: Expect EINVAL on null pointer syscalls/mremap: Expect EINVAL on narrow pointer syscalls/mmap: Skip MAP_GROWSDOWN tests in PCuABI
.../syscalls/memfd_create/memfd_create_common.c | 3 ++- testcases/kernel/syscalls/mlock/mlock01.c | 13 +++---------- testcases/kernel/syscalls/mlock/mlock02.c | 12 +++++++++++- testcases/kernel/syscalls/mlock2/mlock202.c | 5 +++-- testcases/kernel/syscalls/mmap/mmap16.c | 11 +++++++++-- testcases/kernel/syscalls/mmap/mmap17.c | 4 ++++ testcases/kernel/syscalls/mmap/mmap18.c | 7 +++++++ testcases/kernel/syscalls/mmap/mmap19.c | 4 ++-- testcases/kernel/syscalls/mprotect/mprotect01.c | 11 +++++++++-- testcases/kernel/syscalls/mprotect/mprotect02.c | 3 ++- testcases/kernel/syscalls/mprotect/mprotect04.c | 5 +++-- testcases/kernel/syscalls/mprotect/mprotect05.c | 4 +++- testcases/kernel/syscalls/mremap/mremap03.c | 5 +++++ testcases/kernel/syscalls/mremap/mremap05.c | 4 +++- testcases/kernel/syscalls/munlock/munlock01.c | 13 +++---------- testcases/kernel/syscalls/munlock/munlock02.c | 1 + 16 files changed, 70 insertions(+), 35 deletions(-)
-- 2.43.0
linux-morello-ltp mailing list -- linux-morello-ltp@op-lists.linaro.org To unsubscribe send an email to linux-morello-ltp-leave@op-lists.linaro.org
linux-morello-ltp@op-lists.linaro.org