[CRIU] [PATCH] [v2] zdtm: fix a race in socket_udp and socket_udplite

Andrei Vagin avagin at openvz.org
Fri Jan 20 11:40:52 PST 2017


From: Andrei Vagin <avagin at virtuozzo.com>

If we have two sockets and send an upd message from one to another,
we can't be sure that it will be delivered immediately,
there is a change to get from recv(..., MSG_DONTWAIT) EGAIN.

This message is handled asynchronously in a kernel space, so
there may be a small timeout before we get it from another socket.

v2: fix socket6_udp too

Reported-by: Mr Travis
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 test/zdtm/lib/lock.c              | 7 ++++++-
 test/zdtm/static/socket6_udp.c    | 4 ++--
 test/zdtm/static/socket_udp.c     | 4 ++--
 test/zdtm/static/socket_udplite.c | 4 ++--
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/test/zdtm/lib/lock.c b/test/zdtm/lib/lock.c
index 9c3ec87..5a24581 100644
--- a/test/zdtm/lib/lock.c
+++ b/test/zdtm/lib/lock.c
@@ -102,11 +102,16 @@ void task_waiter_wait4(task_waiter_t *t, unsigned int lockid)
 	if (recv(t->sk, &v, sizeof(v), 0) != sizeof(v))
 		goto err;
 
+	if (v != lockid) {
+		pr_err("Got %d instead of %d", v, lockid);
+		exit(1);
+	}
+
 	return;
 
 err:
 	pr_perror("task_waiter_wait4 failed");
-	exit(errno);
+	exit(1);
 }
 
 void task_waiter_complete(task_waiter_t *t, unsigned int lockid)
diff --git a/test/zdtm/static/socket6_udp.c b/test/zdtm/static/socket6_udp.c
index 30ddc9a..d1c39c7 100644
--- a/test/zdtm/static/socket6_udp.c
+++ b/test/zdtm/static/socket6_udp.c
@@ -85,7 +85,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk1, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk1, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv C");
@@ -102,7 +102,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk2, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk2, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv");
diff --git a/test/zdtm/static/socket_udp.c b/test/zdtm/static/socket_udp.c
index e84e8bf..5e24a8b 100644
--- a/test/zdtm/static/socket_udp.c
+++ b/test/zdtm/static/socket_udp.c
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk1, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk1, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv C");
@@ -107,7 +107,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk2, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk2, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv");
diff --git a/test/zdtm/static/socket_udplite.c b/test/zdtm/static/socket_udplite.c
index aaa40e1..8218ff5 100644
--- a/test/zdtm/static/socket_udplite.c
+++ b/test/zdtm/static/socket_udplite.c
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk1, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk1, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv C");
@@ -107,7 +107,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk2, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk2, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv");
-- 
2.7.4



More information about the CRIU mailing list