Add a test to check if passing a pointer in epoll_data_t from epoll_ctl() to epoll_wait() succeeds.
For CHERI pointers the capability tag and metadata need to be checked as well.
Signed-off-by: Kristina Martsenko kristina.martsenko@arm.com --- runtest/syscalls | 1 + .../kernel/syscalls/epoll_wait/.gitignore | 1 + .../kernel/syscalls/epoll_wait/epoll_wait05.c | 87 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait05.c
diff --git a/runtest/syscalls b/runtest/syscalls index 24d0f955d..a280c3c1f 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -173,6 +173,7 @@ epoll_wait01 epoll_wait01 epoll_wait02 epoll_wait02 epoll_wait03 epoll_wait03 epoll_wait04 epoll_wait04 +epoll_wait05 epoll_wait05 epoll_pwait01 epoll_pwait01 epoll_pwait02 epoll_pwait02 epoll_pwait03 epoll_pwait03 diff --git a/testcases/kernel/syscalls/epoll_wait/.gitignore b/testcases/kernel/syscalls/epoll_wait/.gitignore index 222955dd2..ab5a9c010 100644 --- a/testcases/kernel/syscalls/epoll_wait/.gitignore +++ b/testcases/kernel/syscalls/epoll_wait/.gitignore @@ -2,3 +2,4 @@ epoll_wait01 epoll_wait02 epoll_wait03 epoll_wait04 +epoll_wait05 diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait05.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait05.c new file mode 100644 index 000000000..8828babe0 --- /dev/null +++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait05.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) Arm Ltd. 2022. All rights reserved. + * Author: Kristina Martsenko kristina.martsenko@arm.com + */ + +/*\ + * [Description] + * + * Check that passing a pointer as epoll_data_t succeeds. + */ + +#include <sys/epoll.h> +#ifdef __CHERI_PURE_CAPABILITY__ +#include <cheriintrin.h> +#endif + +#include "tst_test.h" + +static int epfd, fds[2]; +static struct epoll_event epevs[1] = { + {.events = EPOLLOUT} +}; +static int test_data; + +static void run(void) +{ + struct epoll_event ret_evs = {.events = 0, .data.ptr = NULL}; + + TEST(epoll_wait(epfd, &ret_evs, 1, -1)); + + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "epoll_wait() failed"); + return; + } + + if (TST_RET != 1) { + tst_res(TFAIL, "epoll_wait() returned %li, expected 1", TST_RET); + return; + } + +#ifdef __CHERI_PURE_CAPABILITY__ + if (!cheri_is_equal_exact(ret_evs.data.ptr, &test_data)) { + tst_res(TFAIL, "epoll_wait() received different pointer"); + return; + } +#else + if (ret_evs.data.ptr != &test_data) { + tst_res(TFAIL, "epoll_wait() received different pointer"); + return; + } +#endif + + tst_res(TPASS, "epoll_wait() with pointer as epoll_data_t"); +} + +static void setup(void) +{ + SAFE_PIPE(fds); + + epfd = epoll_create(1); + if (epfd == -1) + tst_brk(TBROK | TERRNO, "epoll_create()"); + + epevs[0].data.ptr = &test_data; + + if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[1], &epevs[0])) + tst_brk(TBROK | TERRNO, "epoll_ctl(..., EPOLL_CTL_ADD, ...)"); +} + +static void cleanup(void) +{ + if (epfd > 0) + SAFE_CLOSE(epfd); + + if (fds[0] > 0) + SAFE_CLOSE(fds[0]); + + if (fds[1] > 0) + SAFE_CLOSE(fds[1]); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, +};