[LTP] [PATCH V11 2/2] syscalls/semtimedop: Add failure test for invalid timeout pointer
Viresh Kumar
viresh.kumar@linaro.org
Wed Sep 2 17:00:45 CEST 2020
This adds test for invalid timeout pointer.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
V11:
- Fixed rebase conflicts.
testcases/kernel/syscalls/ipc/semop/semop02.c | 41 ++++++++++++-------
1 file changed, 27 insertions(+), 14 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/semop/semop02.c b/testcases/kernel/syscalls/ipc/semop/semop02.c
index 8d59e12bde92..9d799e6437cd 100644
--- a/testcases/kernel/syscalls/ipc/semop/semop02.c
+++ b/testcases/kernel/syscalls/ipc/semop/semop02.c
@@ -12,6 +12,7 @@
* EAGAIN - semop = -1 for zero semaphore and IPC_NOWAIT passed in flags
* EAGAIN - semop = 0 and timeout happens
* EAGAIN - semop = -1 and timeout happens
+ * EFAULT - invalid timeout pointer
*
* Copyright (c) International Business Machines Corp., 2001
* 03/2001 - Written by Wayne Boyer
@@ -33,6 +34,7 @@ static int bad_sem_id = -1;
static short sem_op_max, sem_op_1 = 1, sem_op_negative = -1, sem_op_zero = 0;
static struct sembuf *faulty_buf;
static struct tst_ts timeout;
+static struct tst_ts *valid_to = &timeout, *invalid_to;
#define NSOPS 1
#define BIGOPS 1024
@@ -47,20 +49,22 @@ static struct test_case_t {
short sem_flg;
unsigned t_ops;
int arr_val;
+ struct tst_ts **to;
int error;
} tc[] = {
- {0, &valid_sem_id, NULL, &sem_op_1, 0, 0, 0, BIGOPS, 1, E2BIG},
- {0, &noperm_sem_id, NULL, &sem_op_1, 0, 0, 0, NSOPS, 1, EACCES},
- {0, &valid_sem_id, &faulty_buf, &sem_op_1, 0, 0, 0, NSOPS, 1, EFAULT},
- {0, &valid_sem_id, NULL, &sem_op_1, 0, 0, 0, 0, 1, EINVAL},
- {0, &bad_sem_id, NULL, &sem_op_1, 0, 0, 0, NSOPS, 1, EINVAL},
- {0, &valid_sem_id, NULL, &sem_op_max, 0, 0, 0, 1, 1, ERANGE},
- {0, &valid_sem_id, NULL, &sem_op_1, 0, -1, SEM_UNDO, 1, 1, EFBIG},
- {0, &valid_sem_id, NULL, &sem_op_1, 0, PSEMS + 1, SEM_UNDO, 1, 1, EFBIG},
- {0, &valid_sem_id, NULL, &sem_op_zero, 2, 2, IPC_NOWAIT, 1, 1, EAGAIN},
- {0, &valid_sem_id, NULL, &sem_op_negative, 2, 2, IPC_NOWAIT, 1, 0, EAGAIN},
- {1, &valid_sem_id, NULL, &sem_op_zero, 0, 0, SEM_UNDO, 1, 1, EAGAIN},
- {1, &valid_sem_id, NULL, &sem_op_negative, 0, 0, SEM_UNDO, 1, 0, EAGAIN},
+ {0, &valid_sem_id, NULL, &sem_op_1, 0, 0, 0, BIGOPS, 1, &valid_to, E2BIG},
+ {0, &noperm_sem_id, NULL, &sem_op_1, 0, 0, 0, NSOPS, 1, &valid_to, EACCES},
+ {0, &valid_sem_id, &faulty_buf, &sem_op_1, 0, 0, 0, NSOPS, 1, &valid_to, EFAULT},
+ {0, &valid_sem_id, NULL, &sem_op_1, 0, 0, 0, 0, 1, &valid_to, EINVAL},
+ {0, &bad_sem_id, NULL, &sem_op_1, 0, 0, 0, NSOPS, 1, &valid_to, EINVAL},
+ {0, &valid_sem_id, NULL, &sem_op_max, 0, 0, 0, 1, 1, &valid_to, ERANGE},
+ {0, &valid_sem_id, NULL, &sem_op_1, 0, -1, SEM_UNDO, 1, 1, &valid_to, EFBIG},
+ {0, &valid_sem_id, NULL, &sem_op_1, 0, PSEMS + 1, SEM_UNDO, 1, 1, &valid_to, EFBIG},
+ {0, &valid_sem_id, NULL, &sem_op_zero, 2, 2, IPC_NOWAIT, 1, 1, &valid_to, EAGAIN},
+ {0, &valid_sem_id, NULL, &sem_op_negative, 2, 2, IPC_NOWAIT, 1, 0, &valid_to, EAGAIN},
+ {1, &valid_sem_id, NULL, &sem_op_zero, 0, 0, SEM_UNDO, 1, 1, &valid_to, EAGAIN},
+ {1, &valid_sem_id, NULL, &sem_op_negative, 0, 0, SEM_UNDO, 1, 0, &valid_to, EAGAIN},
+ {1, &valid_sem_id, NULL, &sem_op_zero, 0, 0, SEM_UNDO, 1, 1, &invalid_to, EFAULT},
};
static void setup(void)
@@ -70,6 +74,7 @@ static void setup(void)
key_t semkey;
union semun arr;
struct seminfo ipc_buf;
+ void *faulty_address;
tst_res(TINFO, "Testing variant: %s", tv->desc);
semop_supported_by_kernel(tv);
@@ -98,7 +103,9 @@ static void setup(void)
tst_brk(TBROK | TERRNO, "semctl() IPC_INFO failed");
sem_op_max = ipc_buf.semvmx;
- faulty_buf = tst_get_bad_addr(NULL);
+ faulty_address = tst_get_bad_addr(NULL);
+ invalid_to = faulty_address;
+ faulty_buf = faulty_address;
}
static void run(unsigned int i)
@@ -111,6 +118,7 @@ static void run(unsigned int i)
.sem_num = tc[i].sem_num,
};
struct sembuf *ptr = &buf;
+ void *to;
if (tc[i].semtimedop_only && tv->semop) {
tst_res(TCONF, "Test not supported for variant");
@@ -125,7 +133,12 @@ static void run(unsigned int i)
if (tc[i].buf)
ptr = *tc[i].buf;
- TEST(call_semop(tv, *(tc[i].semid), ptr, tc[i].t_ops, tst_ts_get(&timeout)));
+ if (*tc[i].to == invalid_to)
+ to = invalid_to;
+ else
+ to = tst_ts_get(*tc[i].to);
+
+ TEST(call_semop(tv, *(tc[i].semid), ptr, tc[i].t_ops, to));
if (TST_RET != -1) {
tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly");
--
2.25.0.rc1.19.g042ed3e048af
More information about the ltp
mailing list