[LTP] [PATCH 4/6] Convert cve-2016-7117 test to use long running threads
Richard Palethorpe
rpalethorpe@suse.com
Thu Aug 24 13:08:01 CEST 2017
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
testcases/cve/cve-2016-7117.c | 43 +++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)
diff --git a/testcases/cve/cve-2016-7117.c b/testcases/cve/cve-2016-7117.c
index deb667761..e08f8cd20 100644
--- a/testcases/cve/cve-2016-7117.c
+++ b/testcases/cve/cve-2016-7117.c
@@ -94,30 +94,44 @@ static struct mmsghdr msghdrs[2] = {
static char rbuf[sizeof(MSG)];
static struct timespec timeout = { .tv_sec = RECV_TIMEOUT };
static struct tst_fzsync_pair fzsync_pair = TST_FZSYNC_PAIR_INIT;
+static pthread_t pt_send;
+static void *send_and_close(void *);
+
+static void setup(void)
+{
+ SAFE_PTHREAD_CREATE(&pt_send, 0, send_and_close, 0);
+}
static void cleanup(void)
{
close(socket_fds[0]);
close(socket_fds[1]);
+
+ if (pt_send) {
+ tst_fzsync_pair_exit(&fzsync_pair);
+ SAFE_PTHREAD_JOIN(pt_send, 0);
+ }
}
static void *send_and_close(void *arg)
{
- send(socket_fds[0], MSG, sizeof(MSG), 0);
- send(socket_fds[0], MSG, sizeof(MSG), 0);
-
- tst_fzsync_delay_b(&fzsync_pair);
+ while(tst_fzsync_pair_wait_update(&fzsync_pair)) {
+ send(socket_fds[0], MSG, sizeof(MSG), 0);
+ send(socket_fds[0], MSG, sizeof(MSG), 0);
- close(socket_fds[0]);
- close(socket_fds[1]);
- tst_fzsync_time_b(&fzsync_pair);
+ tst_fzsync_delay_b(&fzsync_pair);
+ close(socket_fds[0]);
+ close(socket_fds[1]);
+ tst_fzsync_time_b(&fzsync_pair);
+ if (!tst_fzsync_pair_wait(&fzsync_pair))
+ break;
+ }
return arg;
}
static void run(void)
{
- pthread_t pt_send;
int i, stat, too_early_count = 0;
msghdrs[0].msg_hdr.msg_iov->iov_base = (void *)&rbuf;
@@ -126,8 +140,7 @@ static void run(void)
if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, socket_fds))
tst_brk(TBROK | TERRNO, "Socket creation failed");
- SAFE_PTHREAD_CREATE(&pt_send, 0, send_and_close, 0);
-
+ tst_fzsync_pair_wait_update(&fzsync_pair);
tst_fzsync_delay_a(&fzsync_pair);
stat = tst_syscall(__NR_recvmmsg,
@@ -140,20 +153,14 @@ static void run(void)
else if (stat < 0)
tst_res(TWARN | TERRNO, "recvmmsg failed unexpectedly");
- SAFE_PTHREAD_JOIN(pt_send, 0);
-
- tst_fzsync_pair_update(i, &fzsync_pair);
- if (!(i & 0x7FFFF)) {
- tst_res(TINFO, "Too early: %.1f%%",
- 100 * too_early_count / (float)i);
- tst_fzsync_pair_info(&fzsync_pair);
- }
+ tst_fzsync_pair_wait(&fzsync_pair);
}
tst_res(TPASS, "Nothing happened after %d attempts", ATTEMPTS);
}
static struct tst_test test = {
+ .setup = setup,
.test_all = run,
.cleanup = cleanup,
.min_kver = "2.6.33",
--
2.14.1
More information about the ltp
mailing list